diff options
| author | Alexandre Ghiti <alexghiti@rivosinc.com> | 2023-04-13 16:02:19 +0200 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2023-04-17 09:26:28 +0530 |
| commit | 674e0199b23effebfc5311d09b636ca9b46cde7e (patch) | |
| tree | dc5bc8021cd3031446fb3fd29a3bf33ff7ed3b26 | |
| parent | bdb3c42bca1c7fddd0c43f0be24c3a1590f02e50 (diff) | |
| download | opensbi-674e0199b23effebfc5311d09b636ca9b46cde7e.tar.gz opensbi-674e0199b23effebfc5311d09b636ca9b46cde7e.zip | |
lib: sbi: Fix counter index calculation for SBI_PMU_CFG_FLAG_SKIP_MATCH
As per the SBI specification, we should "unconditionally select the first
counter from the set of counters specified by the counter_idx_base and
counter_idx_mask", so implement this behaviour.
Suggested-by: Atish Patra <atishp@atishpatra.org>
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
| -rw-r--r-- | lib/sbi/sbi_pmu.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index f28c9f5e..939f29d8 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -736,10 +736,15 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, /* The caller wants to skip the match because it already knows the * counter idx for the given event. Verify that the counter idx * is still valid. + * As per the specification, we should "unconditionally select + * the first counter from the set of counters specified by the + * counter_idx_base and counter_idx_mask". */ - if (active_events[hartid][cidx_base] == SBI_PMU_EVENT_IDX_INVALID) + unsigned long cidx_first = cidx_base + sbi_ffs(cidx_mask); + + if (active_events[hartid][cidx_first] == SBI_PMU_EVENT_IDX_INVALID) return SBI_EINVAL; - ctr_idx = cidx_base; + ctr_idx = cidx_first; goto skip_match; } |
