Skip to contentSkip to conversation

lib: sbi: pmu: Improve loop in pmu_ctr_find_hw

PATCH Applied Manuel Hernández Méndez 2 participants 2 messages Jul 21, 2025 – Aug 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: pmu: Improve loop in pmu_ctr_find_hw

We do not need to iterate over all values in the loop, we can break the loop when we found a valid counter that is not started yet.

---
 lib/sbi/sbi_pmu.c | 1 +
 1 file changed, 1 insertion(+)
lib/sbi/sbi_pmu.c +1 -0
index 07a5c544..635cb0c7 100644
@@ -780,6 +780,7 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,
 				continue;
 			/* We found a valid counter that is not started yet */
 			ctr_idx = cbase;
+			break;
 		}
 	}
 
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#1 lore raw
Quoted 6 lines · Manuel Hernández Méndez

We do not need to iterate over all values in the loop, we can break the loop when we found a valid counter that is not started yet.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 24 lines
---
 lib/sbi/sbi_pmu.c | 1 +
 1 file changed, 1 insertion(+)
lib/sbi/sbi_pmu.c +1 -1
index 07a5c544..635cb0c7 100644
@@ -780,6 +780,7 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,
                                continue;
                        /* We found a valid counter that is not started yet */
                        ctr_idx = cbase;
+                       break;
                }
        }
 
--

2.34.1

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi