* [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
@ 2025-12-13 10:41 James Raphael Tiovalen
2025-12-27 9:09 ` Anup Patel
0 siblings, 1 reply; 2+ messages in thread
From: James Raphael Tiovalen @ 2025-12-13 10:41 UTC (permalink / raw)
To: opensbi; +Cc: andrew.jones, atishp, James Raphael Tiovalen
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@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
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
2025-12-13 10:41 [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters James Raphael Tiovalen
@ 2025-12-27 9:09 ` Anup Patel
0 siblings, 0 replies; 2+ messages in thread
From: Anup Patel @ 2025-12-27 9:09 UTC (permalink / raw)
To: James Raphael Tiovalen; +Cc: opensbi, andrew.jones, atishp
On Sat, Dec 13, 2025 at 4:12 PM James Raphael Tiovalen
<jamestiotio@gmail.com> wrote:
>
> 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@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;
> +
This check should also be done for platform firmware counters
hence it should be just before this if-else block.
> 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;
> +
As comment as above, this check should be before the previous
if block.
> phs->fw_counters_started &= ~BIT(cidx - num_hw_ctrs);
>
> return 0;
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
I have taken care of the above comments at the time of
merging this patch.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-27 9:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-13 10:41 [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters James Raphael Tiovalen
2025-12-27 9:09 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox