[PATCH] lib: sbi: pmu: Improve loop in pmu_ctr_find_hw

Anup Patel anup at brainfault.org
Tue Aug 26 04:15:00 PDT 2025


On Mon, Jul 21, 2025 at 10:31 PM Manuel Hernández Méndez
<maherme.dev at gmail.com> wrote:
>
> 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.
>
> Signed-off-by: Manuel Hernández Méndez <maherme.dev at gmail.com>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup


> ---
>  lib/sbi/sbi_pmu.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
> index 07a5c544..635cb0c7 100644
> --- a/lib/sbi/sbi_pmu.c
> +++ b/lib/sbi/sbi_pmu.c
> @@ -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
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list