From: "Yicong Yang" <yang.yicong@picoheart.com>
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>,
"Anup Patel" <anup.patel@oss.qualcomm.com>,
"Sunil V L" <sunilvl@oss.qualcomm.com>,
"Rafael J . Wysocki" <rafael@kernel.org>
Cc: <yang.yicong@picoheart.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Alexandre Ghiti" <alex@ghiti.fr>, "Len Brown" <lenb@kernel.org>,
"Atish Patra" <atish.patra@linux.dev>,
"Anup Patel" <anup@brainfault.org>,
"Will Deacon" <will@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
<linux-acpi@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
"Anup Patel" <apatel@ventanamicro.com>,
"Sunil V L" <sunilvl@ventanamicro.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Atish Patra" <atishp@rivosinc.com>,
"Nutty Liu" <nutty.liu@hotmail.com>,
"Yunhui Cui" <cuiyunhui@bytedance.com>,
"Yuanzhu" <yuanzhu@bytedance.com>
Subject: Re: [PATCH v7 1/1] RISC-V: Add common csr_read_num() and csr_write_num() functions
Date: Wed, 11 Nov 2026 19:40:55 +0800 [thread overview]
Message-ID: <a767f8c1-a568-42bf-8dd2-0b05d32686ec@picoheart.com> (raw)
In-Reply-To: <CACnXVnfFWF8h+o0=nSb9JESOxYsdVMO+BJKMT7t=K=XVgVwx2g@mail.gmail.com>
On 11/11/26 5:15 PM, Zhanpeng Zhang wrote:
> Hi Anup,
>
> On 11/5/26 12:15 AM, Anup Patel wrote:
>> From: Anup Patel <apatel@ventanamicro.com>
>>
>> In RISC-V, there is no CSR read/write instruction which takes CSR
>> number via register so add common csr_read_num() and csr_write_num()
>> functions which allow accessing certain CSRs by passing CSR number
>> as parameter. These common functions will be first used by the
>> ACPI CPPC driver and RISC-V PMU driver.
>>
>> Also, the RISC-V ACPI FFH specification allows arbitrary CSR number
>> as CPPC register and the RISC-V SBI specification allows arbitrary
>> CSR number as PMU hardware counter. This means ACPI CPPC driver and
>> RISC-V PMU driver no longer need to do sanity checks on CSR number
>> which are now done by the common csr_read_num() and csr_write_num()
>> functions.
>>
>> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
>> Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
>> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
>> Reviewed-by: Atish Patra <atishp@rivosinc.com>
>> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
>> ---
>> arch/riscv/include/asm/csr.h | 3 +
>> arch/riscv/kernel/Makefile | 1 +
>> arch/riscv/kernel/csr.c | 165 +++++++++++++++++++++++++++++++++++
>> drivers/acpi/riscv/cppc.c | 17 ++--
>> drivers/perf/riscv_pmu.c | 54 ++----------
>> 5 files changed, 184 insertions(+), 56 deletions(-)
>> create mode 100644 arch/riscv/kernel/csr.c
>>
>> diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
>> index 621f84d1898f..ebd82043430b 100644
>> --- a/arch/riscv/include/asm/csr.h
>> +++ b/arch/riscv/include/asm/csr.h
>>
>> [...]
>> /*
>> * Read the CSR of a corresponding counter.
>> */
>> unsigned long riscv_pmu_ctr_read_csr(unsigned long csr)
>> {
>> - if (csr < CSR_CYCLE || csr > CSR_HPMCOUNTER31H ||
>> - (csr > CSR_HPMCOUNTER31 && csr < CSR_CYCLEH)) {
>
>
> Could we keep the existing CSR range check in riscv_pmu_ctr_read_csr()
> when switching it to csr_read_num()?
>
> The SBI PMU driver still assumes the architectural counter layout. For
> example, if SBI assigns an event to a custom counter at CSR 0x800,
> pmu_sbi_csr_index() truncates 0x800 - CSR_CYCLE to zero. The perf mmap
> page then advertises index 1, so userspace reads cycle while the kernel
> reads 0x800. The same index is used to set and clear scounteren.
I think it's an existing problem that current SBI PMU doesn't support
custom counters, but only rejects the custom counters in riscv_pmu_ctr_read_csr().
the index truncation and scounteren issue should still exist even if we
add back the check in riscv_pmu_ctr_read_csr().
but you're right that remove the check here changes the existing
behaviour and should be retained.
thanks.
>
> Non-snapshot overflow handling and RV32 high-half reads also assume the
> architectural layout. Could we keep the PMU conversion
> behavior-preserving and handle custom counters separately?
>
>> [...]
> Thanks,
> Zhanpeng
next prev parent reply other threads:[~2026-11-11 11:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 16:15 [PATCH v7 0/1] Common csr_read_num() and csr_write_num() for RISC-V Anup Patel
2026-11-04 16:15 ` [PATCH v7 1/1] RISC-V: Add common csr_read_num() and csr_write_num() functions Anup Patel
2026-11-05 12:52 ` Yicong Yang
2026-11-11 9:15 ` Zhanpeng Zhang
2026-11-11 11:40 ` Yicong Yang [this message]
2026-11-15 8:24 ` Anup Patel
2026-11-11 11:46 ` Zhanpeng Zhang
2026-11-15 8:27 ` 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=a767f8c1-a568-42bf-8dd2-0b05d32686ec@picoheart.com \
--to=yang.yicong@picoheart.com \
--cc=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=anup.patel@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=apatel@ventanamicro.com \
--cc=atish.patra@linux.dev \
--cc=atishp@rivosinc.com \
--cc=cuiyunhui@bytedance.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=nutty.liu@hotmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael@kernel.org \
--cc=sunilvl@oss.qualcomm.com \
--cc=sunilvl@ventanamicro.com \
--cc=will@kernel.org \
--cc=yuanzhu@bytedance.com \
--cc=zhangzhanpeng.jasper@bytedance.com \
/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
all inboxes | Powered by JetHome®