lib: sbi_pmu: Add PMU snapshot definitions
authorAtish Patra <atishp@rivosinc.com>
Thu, 7 Dec 2023 22:23:49 +0000 (14:23 -0800)
committerAnup Patel <anup@brainfault.org>
Fri, 8 Dec 2023 17:20:21 +0000 (22:50 +0530)
OpenSBI doesn't support SBI PMU snapshot yet as there is not much benefit
unless the multiple counters overflow at the same time.

Just add the definition and return not supported error at this moment. The
default returned error is also not supported. Thus, no functional change
intended.

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
include/sbi/sbi_ecall_interface.h
include/sbi/sbi_error.h
lib/sbi/sbi_ecall_pmu.c
lib/sbi/sbi_pmu.c

index 1fe469e370787b8644b1bbbbcf84e020e3258595..d8c646d7b073424658b3b4fada3f7a538a414fbe 100644 (file)
 #define SBI_EXT_PMU_COUNTER_STOP       0x4
 #define SBI_EXT_PMU_COUNTER_FW_READ    0x5
 #define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6
+#define SBI_EXT_PMU_SNAPSHOT_SET_SHMEM 0x7
 
 /** General pmu event codes specified in SBI PMU extension */
 enum sbi_pmu_hw_generic_events_t {
@@ -241,9 +242,11 @@ enum sbi_pmu_ctr_type {
 
 /* Flags defined for counter start function */
 #define SBI_PMU_START_FLAG_SET_INIT_VALUE (1 << 0)
+#define SBI_PMU_START_FLAG_INIT_FROM_SNAPSHOT (1 << 1)
 
 /* Flags defined for counter stop function */
 #define SBI_PMU_STOP_FLAG_RESET (1 << 0)
+#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT (1 << 1)
 
 /* SBI function IDs for DBCN extension */
 #define SBI_EXT_DBCN_CONSOLE_WRITE             0x0
@@ -309,8 +312,9 @@ enum sbi_cppc_reg_id {
 #define SBI_ERR_ALREADY_AVAILABLE              -6
 #define SBI_ERR_ALREADY_STARTED                        -7
 #define SBI_ERR_ALREADY_STOPPED                        -8
+#define SBI_ERR_NO_SHMEM                       -9
 
-#define SBI_LAST_ERR                           SBI_ERR_ALREADY_STOPPED
+#define SBI_LAST_ERR                           SBI_ERR_NO_SHMEM
 
 /* clang-format on */
 
index dd65e14b6fcd233b065688f514ab59c4cd5e127a..7f97506d8bd5f5f4407779ca2c6d4162dedfbc70 100644 (file)
@@ -23,6 +23,7 @@
 #define SBI_EALREADY           SBI_ERR_ALREADY_AVAILABLE
 #define SBI_EALREADY_STARTED   SBI_ERR_ALREADY_STARTED
 #define SBI_EALREADY_STOPPED   SBI_ERR_ALREADY_STOPPED
+#define SBI_ENO_SHMEM          SBI_ERR_NO_SHMEM
 
 #define SBI_ENODEV             -1000
 #define SBI_ENOSYS             -1001
index 1d5d512eeed787c937aed349700181b3a2fc4fc9..c58591106d09a1940bcca8ceae60e436cf962995 100644 (file)
@@ -74,6 +74,8 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
        case SBI_EXT_PMU_COUNTER_STOP:
                ret = sbi_pmu_ctr_stop(regs->a0, regs->a1, regs->a2);
                break;
+       case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM:
+               /* fallthrough as OpenSBI doesn't support snapshot yet */
        default:
                ret = SBI_ENOTSUPP;
        }
index 4b0f5be4bf71a2b3ea3358d0294cb2c307d8e5e7..5f70730e4022e8fab7b5a0dc00c7b2c388df26ea 100644 (file)
@@ -442,6 +442,9 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,
        if ((cbase + sbi_fls(cmask)) >= total_ctrs)
                return ret;
 
+       if (flags & SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT)
+               return SBI_ENO_SHMEM;
+
        if (flags & SBI_PMU_START_FLAG_SET_INIT_VALUE)
                bUpdate = true;
 
@@ -540,6 +543,9 @@ int sbi_pmu_ctr_stop(unsigned long cbase, unsigned long cmask,
        if ((cbase + sbi_fls(cmask)) >= total_ctrs)
                return SBI_EINVAL;
 
+       if (flag & SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT)
+               return SBI_ENO_SHMEM;
+
        for_each_set_bit(i, &cmask, BITS_PER_LONG) {
                cidx = i + cbase;
                event_idx_type = pmu_ctr_validate(phs, cidx, &event_code);