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: Fri, 15 Aug 2025 05:12:58 +0000 [thread overview]
Message-ID: <aJ7B2labaxza9duY@google.com> (raw)
In-Reply-To: <CAJZ5v0hXUoqmxwjH0CN8gGDj=qnC3ZWrJc5VarkqRfh=0SCUWw@mail.gmail.com>
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.
Perhaps some of the ARM experts here can think of ways to do this that
I haven't considered.
Best regards,
-Prashant
next prev parent reply other threads:[~2025-08-15 5:13 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 [this message]
2025-08-16 8:25 ` Prashant Malani
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=aJ7B2labaxza9duY@google.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).