From: Prashant Malani <pmalani@google.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Beata Michalska <beata.michalska@arm.com>,
Jie Zhan <zhanjie9@hisilicon.com>,
Ionela Voinescu <ionela.voinescu@arm.com>,
Ben Segall <bsegall@google.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
open list <linux-kernel@vger.kernel.org>,
"open list:CPU FREQUENCY SCALING FRAMEWORK"
<linux-pm@vger.kernel.org>, Mel Gorman <mgorman@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Valentin Schneider <vschneid@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
z00813676 <zhenglifeng1@huawei.com>,
sudeep.holla@arm.com
Subject: Re: [PATCH v2 2/2] cpufreq: CPPC: Dont read counters for idle CPUs
Date: Sat, 16 Aug 2025 01:25:12 -0700 [thread overview]
Message-ID: <CAFivqmKyRnz-uE8TO+0H26os8uPjL_vcMHiPME3Q5yDu3Ph=4Q@mail.gmail.com> (raw)
In-Reply-To: <aJ7B2labaxza9duY@google.com>
On Thu, 14 Aug 2025 at 22:13, Prashant Malani <pmalani@google.com> wrote:
>
> Thanks a lot for taking a look at this, Rafael.
>
> On Aug 14 13:48, Rafael J. Wysocki wrote:
> >
> > First off, AFAICS, using idle_cpu() for reliable detection of CPU
> > idleness in a sysfs attribute code path would be at least
> > questionable, if not outright invalid. By the time you have got a
> > result from it, there's nothing to prevent the CPU in question from
> > going idle or waking up from idle.
>
> This is a heuristic-based optimization. The observation is that when
> the CPU is idle (or near-idle/lightly loaded, since FFH actually wakes
> up an idle CPU), the AMU counters as read from the kernel are unreliable.
> It is fine if the CPU wakes up from idle immediately after the check.
> In that case, we'd return the desired frequency (via PCC reg read), which
> is what the frequency would be anyway (if the AMU measurement was
> actually taken).
>
> In a sense, the assumption here is no worse than what is there at
> present; currently the samples are taken across 2us, and (theoretically)
> if the difference between them is 0, we take the fallback path. There is
> nothing to prevent the CPU from waking up immediately after that 2us
> sample period.
>
> > Moreover, the fact that the given
> > CPU is idle from the scheduler perspective doesn't actually mean that
> > it is in an idle state and so it has no bearing on whether or not its
> > performance counters can be accessed etc.
>
> The idle check isn't meant to guard against accessing the counters.
> AFAICT it is perfectly valid to access the counters even when the CPU is
> actually idle.
>
> >
> > The way x86 deals with this problem is to snapshot the counters in
> > question periodically (actually, in scheduler ticks) and fall back to
> > cpu_khz if the interval between the two consecutive updates is too
> > large (see https://elixir.bootlin.com/linux/v6.16/source/arch/x86/kernel/cpu/aperfmperf.c#L502).
> > I think that this is the only reliable way to handle it, but I may be
> > mistaken.
>
> This is interesting. I think it may not work for the CPPC case, since
> the registers in question are in some cases accessed through PCC reads
> which require semaphores. I think it would be untenable to do that in
> the tick handler (but I may be mistaken here). It's easier on x86
> since those are always just MSRs.
> We could probably do it for the FFH case, but then we're bifurcating
> the computation method and IMO that's not worth the hassle.
I looked around a bit more and it turns out arm64 is already doing something
similar to what you propose.
It takes a snapshot of the counters every tick, and falls back to
arch_scale_freq_capacity() for another non-idle CPU (checked using idle_cpu())
in the same frequency domain if the interval between snapshots is too long [1].
However, this function only works some of the time; if the CPU hasn't had
a tick in a while *and* there is no other non-idle CPU in the frequency domain,
it returns an error [2].
Moreover, cpuinfo_cur_freq doesn't use this (it reads the frequency directly
from the CPPC driver).
(I'll abandon this series if you still believe this is an invalid
approach; just thought
I'd get this bit of clarification in, for my own understanding).
BR,
-Prashant
[1] https://elixir.bootlin.com/linux/v6.16-rc7/source/arch/arm64/kernel/topology.c#L285
[2] https://elixir.bootlin.com/linux/v6.16-rc7/source/arch/arm64/kernel/topology.c#L336
next prev parent reply other threads:[~2025-08-16 8:25 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-19 0:09 [PATCH v2 0/2] cpufreq: CPPC: idle cpu perf handling Prashant Malani
2025-06-19 0:09 ` [PATCH v2 1/2] sched: Expose idle_cpu() to modules Prashant Malani
2025-06-19 0:09 ` [PATCH v2 2/2] cpufreq: CPPC: Dont read counters for idle CPUs Prashant Malani
2025-06-20 3:53 ` Jie Zhan
2025-06-20 5:07 ` Prashant Malani
2025-06-26 18:42 ` Prashant Malani
2025-06-27 7:54 ` Jie Zhan
2025-06-27 17:07 ` Prashant Malani
2025-07-02 18:38 ` Prashant Malani
2025-07-03 9:29 ` Beata Michalska
2025-07-07 8:32 ` Beata Michalska
2025-07-09 17:25 ` Prashant Malani
2025-07-09 22:49 ` Prashant Malani
2025-07-14 9:30 ` Beata Michalska
2025-07-15 6:28 ` Prashant Malani
2025-07-21 17:00 ` Rafael J. Wysocki
2025-07-21 19:40 ` Prashant Malani
2025-07-22 3:27 ` Viresh Kumar
2025-07-22 6:02 ` Prashant Malani
2025-07-30 7:31 ` Prashant Malani
2025-07-31 8:27 ` Beata Michalska
2025-07-31 11:13 ` Viresh Kumar
2025-07-31 20:23 ` Beata Michalska
2025-08-01 4:43 ` Viresh Kumar
2025-08-07 0:19 ` Prashant Malani
2025-08-11 6:05 ` Viresh Kumar
2025-08-11 18:43 ` Prashant Malani
2025-08-11 19:19 ` Rafael J. Wysocki
2025-08-11 20:01 ` Prashant Malani
2025-08-14 11:48 ` Rafael J. Wysocki
2025-08-15 5:12 ` Prashant Malani
2025-08-16 8:25 ` Prashant Malani [this message]
2025-08-13 10:12 ` Beata Michalska
2025-07-31 16:51 ` Prashant Malani
2025-07-31 20:30 ` Beata Michalska
2025-08-01 9:16 ` Prashant Malani
2025-08-04 20:55 ` Prashant Malani
2025-08-06 7:21 ` Beata Michalska
2025-08-07 0:01 ` Prashant Malani
2025-08-07 10:24 ` Beata Michalska
2025-08-08 2:14 ` Prashant Malani
2025-08-13 10:15 ` Beata Michalska
2025-08-13 22:25 ` Prashant Malani
2025-07-07 8:35 ` Beata Michalska
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='CAFivqmKyRnz-uE8TO+0H26os8uPjL_vcMHiPME3Q5yDu3Ph=4Q@mail.gmail.com' \
--to=pmalani@google.com \
--cc=beata.michalska@arm.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=ionela.voinescu@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sudeep.holla@arm.com \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=vschneid@redhat.com \
--cc=zhanjie9@hisilicon.com \
--cc=zhenglifeng1@huawei.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;
as well as URLs for NNTP newsgroup(s).