From: James Raphael Tiovalen <jamestiotio@gmail.com>
To: opensbi@lists.infradead.org
Cc: andrew.jones@linux.dev, atishp@rivosinc.com,
James Raphael Tiovalen <jamestiotio@gmail.com>
Subject: [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
Date: Sat, 13 Dec 2025 18:41:46 +0800 [thread overview]
Message-ID: <20251213104146.422972-1-jamestiotio@gmail.com> (raw)
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
next reply other threads:[~2025-12-13 10:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-13 10:41 James Raphael Tiovalen [this message]
2025-12-27 9:09 ` [PATCH] lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251213104146.422972-1-jamestiotio@gmail.com \
--to=jamestiotio@gmail.com \
--cc=andrew.jones@linux.dev \
--cc=atishp@rivosinc.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox