All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: sbi: Bypass CY and IR bit setting in mcountinhibit
@ 2022-11-16 10:18 Eric Lin
  2022-11-16 14:56 ` Jessica Clarke
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Lin @ 2022-11-16 10:18 UTC (permalink / raw)
  To: opensbi

CYCLE and INSTRET counters are part of uABI and they were
re-enable for userspace in Linux riscv pmu driver.

To make these counters increase normally in userspace, we bypass
CY and IR bit checking when setting mcountinhibit register.

LINK:https://lore.kernel.org/all/20220928131807.30386-1-palmer at rivosinc.com/
Signed-off-by: Eric Lin <eric.lin@sifive.com>
---
 lib/sbi/sbi_pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index 91d9ccc..28107e5 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -318,7 +318,7 @@ static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update)
 	if (cidx >= num_hw_ctrs || cidx == 1)
 		return SBI_EINVAL;
 
-	if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11)
+	if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11 || cidx == 0 || cidx == 2)
 		goto skip_inhibit_update;
 
 	/*
@@ -413,7 +413,7 @@ static int pmu_ctr_stop_hw(uint32_t cidx)
 	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 	unsigned long mctr_inhbt;
 
-	if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11)
+	if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11 || cidx == 0 || cidx == 2)
 		return 0;
 
 	mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
-- 
2.36.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-07  9:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16 10:18 [PATCH] lib: sbi: Bypass CY and IR bit setting in mcountinhibit Eric Lin
2022-11-16 14:56 ` Jessica Clarke
2022-11-17 23:00   ` Atish Patra
2022-12-05  2:31     ` Eric Lin
     [not found]     ` <CAPqJEFq-Pm5FUdckyqgqb==Pi88zcdNRcRpKjK89SD6b2+ziFg@mail.gmail.com>
2022-12-07  9:35       ` Atish Patra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.