[PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
James Raphael Tiovalen
jamestiotio at gmail.com
Sat Dec 13 02:41:46 PST 2025
Currently, OpenSBI returns SBI_ERR_ALREADY_STARTED when attempting to
start a HW counter that is already started and SBI_ERR_ALREADY_STOPPED
when attempting to stop a HW counter that is already stopped. However,
this is not yet implemented for FW counters.
Add the necessary checks to return the same error codes when attempting
the same actions on FW counters.
Signed-off-by: James Raphael Tiovalen <jamestiotio at gmail.com>
---
lib/sbi/sbi_pmu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index e24e485d..0218c921 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -468,6 +468,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
cidx - num_hw_ctrs,
event_data);
} else {
+ if (phs->fw_counters_started & BIT(cidx - num_hw_ctrs))
+ return SBI_EALREADY_STARTED;
+
if (ival_update)
phs->fw_counters_data[cidx - num_hw_ctrs] = ival;
}
@@ -629,6 +632,9 @@ static int pmu_ctr_stop_fw(struct sbi_pmu_hart_state *phs,
return ret;
}
+ if (!(phs->fw_counters_started & BIT(cidx - num_hw_ctrs)))
+ return SBI_EALREADY_STOPPED;
+
phs->fw_counters_started &= ~BIT(cidx - num_hw_ctrs);
return 0;
--
2.43.0
More information about the opensbi
mailing list