From: Eric Lin <eric.lin@sifive.com>
To: opensbi@lists.infradead.org
Subject: [PATCH] lib: sbi: Bypass CY and IR bit setting in mcountinhibit
Date: Wed, 16 Nov 2022 18:18:26 +0800 [thread overview]
Message-ID: <20221116101826.10465-1-eric.lin@sifive.com> (raw)
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
next reply other threads:[~2022-11-16 10:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 10:18 Eric Lin [this message]
2022-11-16 14:56 ` [PATCH] lib: sbi: Bypass CY and IR bit setting in mcountinhibit 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
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=20221116101826.10465-1-eric.lin@sifive.com \
--to=eric.lin@sifive.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 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.