[PATCH] lib: sbi_pmu: Fix fixed-counter events reported as unsupported

Anup Patel anup at brainfault.org
Wed Oct 28 22:38:03 PDT 2026


On Sun, Sep 27, 2026 at 11:25 AM Fengwei Tan <tfx2001 at outlook.com> wrote:
>
> 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: e4345842168b ("lib: sbi_pmu: Implement SBI PMU event info function")
> Signed-off-by: Fengwei Tan <tfx2001 at outlook.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/sbi_pmu.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
> index e79f6b60..b4abfa1e 100644
> --- a/lib/sbi/sbi_pmu.c
> +++ b/lib/sbi/sbi_pmu.c
> @@ -1119,6 +1119,9 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys
>                         einfo[i].output = 0;
>                 } else if (event_type == SBI_PMU_EVENT_TYPE_FW) {
>                         einfo[i].output = 1;
> +               } else if (event_type == SBI_PMU_EVENT_TYPE_HW &&
> +                          pmu_ctr_find_fixed_hw(event_idx) >= 0) {
> +                       einfo[i].output = 1;
>                 } else {
>                         for (j = 0; j < num_hw_events; j++) {
>                                 temp = &hw_event_map[j];
>
> ---
> base-commit: 5a175017261af97e9122fcb9d9012481cdb5aa41
> change-id: 20260927-fix-pmu-event-get-info-c4a6e2c5717b
>
> Best regards,
> --
> Fengwei Tan <tfx2001 at outlook.com>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list