lib: sbi: Do not clear active_events for cycle/instret when stopping
authorAlexandre Ghiti <alexghiti@rivosinc.com>
Thu, 13 Apr 2023 14:02:18 +0000 (16:02 +0200)
committerAnup Patel <anup@brainfault.org>
Mon, 17 Apr 2023 03:56:26 +0000 (09:26 +0530)
Those events are enabled by default and should not be reset afterwards
since when using SBI_PMU_CFG_FLAG_SKIP_MATCH, it leads to unaccessible
counters after the first use.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
lib/sbi/sbi_pmu.c

index 04259aeb24ebae94caba1c03c851bc70c427b77d..f28c9f5e80a0d076dfdd8c59739ac65104ea2479 100644 (file)
@@ -532,7 +532,7 @@ int sbi_pmu_ctr_stop(unsigned long cbase, unsigned long cmask,
                else
                        ret = pmu_ctr_stop_hw(cidx);
 
-               if (flag & SBI_PMU_STOP_FLAG_RESET) {
+               if (cidx > (CSR_INSTRET - CSR_CYCLE) && flag & SBI_PMU_STOP_FLAG_RESET) {
                        active_events[hartid][cidx] = SBI_PMU_EVENT_IDX_INVALID;
                        pmu_reset_hw_mhpmevent(cidx);
                }