diff mbox series

lib: sbi_pmu: Allow resetting an already stopped counter

Message ID 20261029124309.3689651-1-mayuresh.chitale@oss.qualcomm.com
State New
Headers show
Series lib: sbi_pmu: Allow resetting an already stopped counter | expand

Commit Message

Mayuresh Chitale Oct. 29, 2026, 12:43 p.m. UTC
Kernel sbi_pmu driver issues a counter stop with SBI_PMU_STOP_FLAG_RESET
while removing a perf event. This is done after the counter is stopped
which causes pmu_ctr_stop_hw() to fail with SBI_EALREADY_STOPPED.

Allow pmu_ctr_stop_hw to complete the requested reset and return
success, while still reporting error in other cases.

Fixes: c5077d497d0f ("lib: sbi_pmu: Fix counter and event info error codes as per SBI v3.0 spec")
Signed-off-by: Mayuresh Chitale <mayuresh.chitale@oss.qualcomm.com>
---
 lib/sbi/sbi_pmu.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index a043dc7c..01c45f7a 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -721,16 +721,21 @@  int sbi_pmu_ctr_stop(unsigned long cbase, unsigned long cmask,
 
 		else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW)
 			ret = pmu_ctr_stop_fw(phs, cidx, event_code);
-		else
+		else {
 			ret = pmu_ctr_stop_hw(cidx);
+			if (ret && ret != SBI_EALREADY_STOPPED)
+				return ret;
 
-		if(ret)
-			return ret;
-
-		if (cidx > (CSR_INSTRET - CSR_CYCLE) && flag & SBI_PMU_STOP_FLAG_RESET) {
-			phs->active_events[cidx] = SBI_PMU_EVENT_IDX_INVALID;
-			pmu_reset_hw_mhpmevent(cidx);
+			if (flag & SBI_PMU_STOP_FLAG_RESET &&
+			    cidx > (CSR_INSTRET - CSR_CYCLE)) {
+				phs->active_events[cidx] = SBI_PMU_EVENT_IDX_INVALID;
+				pmu_reset_hw_mhpmevent(cidx);
+				ret = 0;
+			}
 		}
+
+		if (ret)
+			return ret;
 	}
 
 	/* Clear PMU overflow interrupt to avoid spurious ones */