Linux ACPI
 help / color / mirror / Atom feed
From: Sunil V L <sunilvl@ventanamicro.com>
To: 鞠文龙 <juwenlong@bytedance.com>
Cc: yunhui cui <cuiyunhui@bytedance.com>,
	rafael@kernel.org, lenb@kernel.org, paul.walmsley@sifive.com,
	palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
	linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Anup Patel <apatel@ventanamicro.com>,
	Rahul Pathak <rpathak@ventanamicro.com>
Subject: Re: [External] Re: [PATCH] ACPI: RISC-V: CPPC: Add CSR_CYCLE for CPPC FFH
Date: Wed, 13 Aug 2025 17:39:58 +0530	[thread overview]
Message-ID: <aJyAlqd3U5Jq9ipy@sunil-laptop> (raw)
In-Reply-To: <CAHEos+Msmta3o-HvXoigmJGbD48333Kh8tU3j2D=w_G8gL+OQw@mail.gmail.com>

On Wed, Aug 13, 2025 at 12:06:11AM -0700, 鞠文龙 wrote:
> Hi Sunil,
> 
> > From: "Sunil V L"<sunilvl@ventanamicro.com>
> > Date:  Wed, Aug 13, 2025, 13:28
> > Subject:  Re: [External] Re: [PATCH] ACPI: RISC-V: CPPC: Add CSR_CYCLE for CPPC FFH
> > To: "yunhui cui"<cuiyunhui@bytedance.com>
> > Cc: <rafael@kernel.org>, <lenb@kernel.org>, <paul.walmsley@sifive.com>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu>, <alex@ghiti.fr>, <linux-acpi@vger.kernel.org>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>, "Anup Patel"<apatel@ventanamicro.com>, "Rahul Pathak"<rpathak@ventanamicro.com>, <juwenlong@bytedance.com>
> > Hi Yunhui,
> >
> >
> > On Wed, Aug 13, 2025 at 11:23:39AM +0800, yunhui cui wrote:
> > > Hi Sunil,
> > >
> > > On Tue, Aug 12, 2025 at 10:06 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
> > > >
> > [...]
> > > > > > >
> > > > > > > The purpose of cppc_ffh_csr_read() is to calculate the actual
> > > > > > > frequency of the CPU, which is delta_CSR_CYCLE/delta_CSR_XXX.
> > > > > > >
> > > > > > > CSR_XXX should be a reference clock and does not count during WFI
> > > > > > > (Wait For Interrupt).
> > > > > > >
> > > > > > > Similar solutions include: x86's aperf/mperf, and ARM64's AMU with
> > > > > > > registers SYS_AMEVCNTR0_CORE_EL0/SYS_AMEVCNTR0_CONST_EL0.
> > > > > > >
> > > > > > > However, we know that CSR_TIME in the current code does count during
> > > > > > > WFI. So, is this design unreasonable?
> > > > > > >
> > > > > > > Should we consider proposing an extension to support such a dedicated
> > > > > > > counter (a reference clock that does not count during WFI)? This way,
> > > > > > > the value can be obtained directly in S-mode without trapping to
> > > > > > > M-mode, especially since reading this counter is very frequent.
> > > > > > >
> > > > > > Hi Yunhui,
> > > > > >
> > > > > > Yes, but we anticipated that vendors might define their own custom CSRs.
> > > > > > So, we introduced FFH encoding to accommodate such cases.
> > > > > >
> > > > > > Thanks,
> > > > > > Sunil
> > > > >
> > > > > As mentioned earlier, it is best to directly read CSR_XXX (a reference
> > > > > clock that does not count during WFI) and CSR_CYCLE in S-mode, rather
> > > > > than trapping to SBI.
> > > > >
> > > > No. I meant direct CSR access itself not SBI. Please take a look at
> > > > Table 6 of RISC-V FFH spec.
> > > >
> > > > > drivers/acpi/riscv/cppc.c is a generic driver that is not specific to
> > > > > any vendor. Currently, the upstream code already uses CSR_TIME, and
> > > > > the logic of CSR_TIME is incorrect.
> > > > >
> > ACPI spec for "Reference Performance Register" says,
> >
> >
> > "The Reference Performance Counter Register counts at a fixed rate any
> > time the processor is active. It is not affected by changes to Desired
> > Performance, processor throttling, etc."
> >
> >
> > > > CSR_TIME is just an example. It is upto the vendor how _CPC objects are
> > > > encoded using FFH. The linux code doesn't mean one should use CSR_TIME
> > > > always.
> > >
> > > First, the example of CSR_TIME is incorrect. What is needed is a
> > > CSR_XXX (a reference clock that does not count during WFI).
> > >
> > > Second, you mentioned that each vendor can customize their own
> > > implementations. But should all vendors' CSR_XXX/YYY/... be added to
> > > drivers/acpi/riscv/cppc.c? Shouldn’t drivers/acpi/riscv/cppc.c fall
> > > under the scope defined by the RISC-V architecture?
> > >
> > No. One can implement similar to csr_read_num() in opensbi. We didn't
> > add it since there was no HW implementing such thing. What I am
> > saying is we have FFH encoding to support such case.
> >
> >
> > > >
> > > > > It would be best to promote a specification to support CSR_XXX, just
> > > > > like what has been done for x86 and arm64. What do you think?
> > > > >
> > > > Wouldn't above work? For a standard extension, you may have to provide
> > > > more data with actual HW.
> > >
> > > This won’t work. May I ask how the current upstream code can calculate
> > > the actual CPU frequency using CSR_TIME without trapping to SBI?
> > > This is a theoretical logical issue. Why is data needed here?
> > >
> > As I mentioned above, one can implement a generic CSR read without
> > trapping to SBI.
> >
> >
> > > Could you take a look at the "AMU events and event numbers" chapter in
> > > the ARM64 manual?
> > >
> > As-per ACPI spec reference performance counter is not affected by CPU
> > state. The RISC-V FFH encoding is sufficiently generic to support this
> > requirement, even if the standard CSR_TIME cannot be used. In such
> > cases, an alternative CSR can be encodeded, accessed via an OS-level
> > abstraction such as csr_read_num().
>        As-per ACPI Spec,Both Reference performance counter register
> and Delivered Performance Counter are affected by CPU
> state。From ACPI Spec,“The Reference Performance Counter Register
> counts at a fixed rate any time the processor is active.”
>
> “The Delivered Performance Counter Register increments any time the
> processor is active, at a rate proportional to the current performance
> level, taking into account changes to Desired Performance”
> “ Processor power states include are designated C0, C1, C2, C3, . . .
> Cn. The C0 power state is an active power state where the CPU executes
> instructions. The C1 through Cn power states are processor sleeping
> states where the processor consumes less power and dissipates less
> heat than leaving the processor in the C0 state”. So the time csr can
> not meet this requirements.we need another csr, but not availiable for
> now.Either implement it as vendor-specific or create a community
> extension for all?
>
It is upto the interpretation. I am not sure what is "active" or
"etc" in the below statement.

"The Reference Performance Counter Register counts at a fixed rate any
time the processor is active. It is not affected by changes to Desired
Performance, processor throttling, etc."

Second, I don't see an issue if both reference and delivered counters
increment irrespective of idle state because ultimately the ratio
delta(delivered)/delta(reference) matters which will be same in either
case.

Thanks,
Sunil


  reply	other threads:[~2025-08-13 12:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15  9:43 [PATCH] ACPI: RISC-V: CPPC: Add CSR_CYCLE for CPPC FFH Yunhui Cui
2025-08-12 11:25 ` yunhui cui
2025-08-12 13:15   ` Sunil V L
2025-08-12 13:32     ` [External] " yunhui cui
2025-08-12 14:06       ` Sunil V L
2025-08-13  3:23         ` yunhui cui
2025-08-13  5:27           ` Sunil V L
2025-08-13  6:43             ` yunhui cui
2025-08-13 11:11               ` Anup Patel
2025-08-14  3:37                 ` yunhui cui
2025-08-14  5:48                   ` Anup Patel
2025-08-14  6:19                     ` yunhui cui
2025-08-14 13:37                       ` Anup Patel
2025-08-14 16:56                         ` [External] " Jessica Clarke
2025-08-15  2:46                           ` yunhui cui
2025-08-15  4:07                           ` Anup Patel
2025-08-13  7:06             ` [External] " 鞠文龙
2025-08-13 12:09               ` Sunil V L [this message]
2025-08-14  6:08                 ` 鞠文龙

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=aJyAlqd3U5Jq9ipy@sunil-laptop \
    --to=sunilvl@ventanamicro.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=apatel@ventanamicro.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=juwenlong@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=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=rafael@kernel.org \
    --cc=rpathak@ventanamicro.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