2 Commits
Author SHA1 Message Date
Fengwei Tan 827f8bf26b lib: sbi_pmu: fix mapping reset for already stopped counters
Linux stops a counter before issuing another stop with RESET flag when
deleting an event [1]. Returning early on SBI_EALREADY_STOPPED skips
counter-to-event mapping reset, eventually exhausting the hardware
counters.

Continue the stop and reset process for the remaining counters when a
counter in the set is already stopped. Preserve SBI_EALREADY_STOPPED in
the final result, while still returning immediately on other errors.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/perf/riscv_pmu.c?id=72d3fcf802c45d00b300f25b848a93c3a2bd7c7e#n318

Fixes: c5077d497d ("lib: sbi_pmu: Fix counter and event info error codes as per SBI v3.0 spec")
Signed-off-by: Fengwei Tan <tfx2001@outlook.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/SY8P300MB00410B44E7D55CB5CF7B276AB5882@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM
Signed-off-by: Anup Patel <anup@brainfault.org>
2026-11-02 12:02:17 +05:30
Fengwei Tan 2bbee7d82a lib: sbi_pmu: Fix fixed-counter events reported as unsupported
OpenSBI assigns SBI_PMU_HW_CPU_CYCLES and SBI_PMU_HW_INSTRUCTIONS to
fixed counters during PMU initialization. sbi_pmu_ctr_cfg_match()
recognizes these events without searching hw_event_map[].

However, sbi_pmu_event_get_info() only checks hw_event_map[] when
determining whether a hardware event is supported. As a result, these
fixed-counter events are reported as unsupported when no riscv,pmu
device tree node is provided.

Check fixed-counter events separately using pmu_ctr_find_fixed_hw() and
report them as supported.

Fixes: e434584216 ("lib: sbi_pmu: Implement SBI PMU event info function")
Signed-off-by: Fengwei Tan <tfx2001@outlook.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/SY8P300MB0041D04649621E79FE950B43B58E2@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM
Signed-off-by: Anup Patel <anup@brainfault.org>
2026-10-29 11:06:47 +05:30