From: Atish Patra <atish.patra@linux.dev>
To: cp0613@linux.alibaba.com, anup@brainfault.org, alex@ghiti.fr,
pjw@kernel.org, guoren@kernel.org
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers/perf: riscv: Keep the fixed counter counting
Date: Wed, 4 Feb 2026 01:17:25 -0800 [thread overview]
Message-ID: <aab19ab9-0946-4477-8ca2-bc93621a54a0@linux.dev> (raw)
In-Reply-To: <20260131112440.2915-1-cp0613@linux.alibaba.com>
On 1/31/26 3:24 AM, cp0613@linux.alibaba.com wrote:
> From: Chen Pei <cp0613@linux.alibaba.com>
>
> The RISC-V SBI PMU driver disables all PMU counters during initialization
> via pmu_sbi_stop_all. For fixed counters CYCLE, TIME and INSTRET, this is
> unnecessary for the following two reasons:
>
> 1. Some kernel driver code may directly read CYCLE and INSTRET to perform
> simple performance analysis.
Is this for some debugging purpose to read the instret/cycle count at
boot time or real use case for driver performance analysis ?
If it is the latter, that will be problematic for various reasons such
as context switching will lead to inaccurate numbers.
> 2. In legacy mode, user space directly reads CYCLE and INSTRET. (echo 2 >
> /proc/sys/kernel/perf_user_access)
>
> Therefore, We keep counting CYCLE, TIME and INSTRET.
>
> Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
> ---
> drivers/perf/riscv_pmu_sbi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 7dd282da67ce..93aaab324443 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -899,6 +899,9 @@ static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask)
>
> static inline void pmu_sbi_stop_all(struct riscv_pmu *pmu)
> {
> + /* We keep counting CYCLE, TIME and INSTRET. */
> + pmu->cmask &= ~0x7;
> +
This is incorrect. The cmask should be set based on the perf_user_access
value. We should not continue counting the CYCLE/INSTRET when legacy
mode is not set. if (sysctl_perf_user_access == SYSCTL_LEGACY)
csr_write(CSR_SCOUNTEREN, 0x7); else csr_write(CSR_SCOUNTEREN, 0x2);
> /*
> * No need to check the error because we are disabling all the counters
> * which may include counters that are not enabled yet.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-02-04 9:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 11:24 [PATCH] drivers/perf: riscv: Keep the fixed counter counting cp0613
2026-02-04 9:17 ` Atish Patra [this message]
2026-02-04 13:13 ` qingwei hu
2026-02-08 9:32 ` Atish Patra
2026-02-09 11:16 ` [External] " Qingwei Hu
2026-02-09 12:36 ` cp0613
2026-03-28 3:57 ` 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=aab19ab9-0946-4477-8ca2-bc93621a54a0@linux.dev \
--to=atish.patra@linux.dev \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=cp0613@linux.alibaba.com \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=pjw@kernel.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