From: Jie Zhan <zhanjie9@hisilicon.com>
To: Prashant Malani <pmalani@google.com>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: Bowen Yu <yubowen8@huawei.com>, <rafael@kernel.org>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linuxarm@huawei.com>, <jonathan.cameron@huawei.com>,
<lihuisong@huawei.com>, <zhenglifeng1@huawei.com>,
Beata Michalska <beata.michalska@arm.com>,
Ionela Voinescu <ionela.voinescu@arm.com>
Subject: Re: [PATCH 2/2] cpufreq: CPPC: Fix error handling in cppc_scale_freq_workfn()
Date: Thu, 31 Jul 2025 16:32:15 +0800 [thread overview]
Message-ID: <9041c44e-b81a-879d-90cd-3ad0e8992c6c@hisilicon.com> (raw)
In-Reply-To: <CAFivqmLkLn-92rMow+c7iEADCdh3-DEapVmtB_Qwk1a2JrwwWw@mail.gmail.com>
On 31/07/2025 06:34, Prashant Malani wrote:
> Thanks for adding me, Viresh.
>
> On Tue, 29 Jul 2025 at 23:39, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>>
>> + Prashant/Beata/Ionela
>>
>> On 30-07-25, 11:23, Bowen Yu wrote:
>>> From: Jie Zhan <zhanjie9@hisilicon.com>
>>>
>>> Perf counters could be 0 if the cpu is in a low-power idle state. Just try
>>> it again next time and update the frequency scale when the cpu is active
>>> and perf counters successfully return.
>>>
>>> Also, remove the FIE source on an actual failure.
>>>
>>> Signed-off-by: Jie Zhan <zhanjie9@hisilicon.com>
>>> ---
>>> drivers/cpufreq/cppc_cpufreq.c | 13 ++++++++++++-
>>> 1 file changed, 12 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>>> index 904006027df2..e95844d3d366 100644
>>> --- a/drivers/cpufreq/cppc_cpufreq.c
>>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>>> @@ -78,12 +78,23 @@ static void cppc_scale_freq_workfn(struct kthread_work *work)
>>> struct cppc_cpudata *cpu_data;
>>> unsigned long local_freq_scale;
>>> u64 perf;
>>> + int ret;
>>>
>>> cppc_fi = container_of(work, struct cppc_freq_invariance, work);
>>> cpu_data = cppc_fi->cpu_data;
>>>
>>> - if (cppc_get_perf_ctrs(cppc_fi->cpu, &fb_ctrs)) {
>>> + ret = cppc_get_perf_ctrs(cppc_fi->cpu, &fb_ctrs);
>>> + /*
>>> + * Perf counters could be 0 if the cpu is in a low-power idle state.
>>> + * Just try it again next time.
>>> + */
>
> FWIU the performance counters shouldn't be returning 0 in an idle state.
> Per the UEFI spec [1], they increment any time the CPU is active,
> so they should just return their last counter value before they went into idle
> (of course in the FFH case an IPI is performed on the target CPU, so even
> if the CPU was idle, it will get woken up).
Hi Prashant,
The perf counters could return 0 when a CPU is enters a low-power idle
state, e.g. reset or powered down, and the perf counters are in the system
memory space (the target CPU is not woken up unfortunately).
On our platform, and I suppose so on most ARM64 platforms, perf counters
are mapped to AMU counters. Per ARM spec, AMEVCNTR0 is 0 on reset. BTW,
that's also why ARM Trusted Firmware needs to save and restore AMU counters
before and after powering down.
https://github.com/ARM-software/arm-trusted-firmware/blob/master/lib/extensions/amu/aarch64/amu.c
I hope this explains your confusion. Then we can carry on discussion if we
reach on this consensus.
Thanks for taking a look!
Jie
>
> As such it is better to either :
> - Check for idle_cpu() directly and return (see [2] for the function)
> or
> - Always clear the source on encountering an error return value.
>
> [1] https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html?highlight=cppc#performance-counters
> [2] https://lore.kernel.org/linux-pm/20250619000925.415528-2-pmalani@google.com/
>
> HTH,
>
> -Prashant
next prev parent reply other threads:[~2025-07-31 8:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 3:23 [PATCH 0/2] cpufreq: CPPC: Changing error message in CPPC FIE Bowen Yu
2025-07-30 3:23 ` [PATCH 1/2] cpufreq: CPPC: Don't warn on failing to read perf counters on offline cpus Bowen Yu
2025-07-30 3:23 ` [PATCH 2/2] cpufreq: CPPC: Fix error handling in cppc_scale_freq_workfn() Bowen Yu
2025-07-30 6:39 ` Viresh Kumar
2025-07-30 22:34 ` Prashant Malani
2025-07-31 8:32 ` Jie Zhan [this message]
2025-08-01 8:58 ` Prashant Malani
2025-08-04 6:21 ` Jie Zhan
2025-08-05 1:12 ` Prashant Malani
2025-08-05 4:58 ` Prashant Malani
2025-08-13 7:15 ` Jie Zhan
2025-08-13 9:30 ` Beata Michalska
2025-08-15 3:48 ` Jie Zhan
2025-07-30 18:38 ` Markus Elfring
2025-07-31 4:21 ` Jie Zhan
2025-07-31 10:34 ` [2/2] " Markus Elfring
2025-07-31 8:19 ` [PATCH 2/2] " Beata Michalska
2025-07-31 8:52 ` Jie Zhan
2025-07-31 9:42 ` Beata Michalska
2025-08-04 6:31 ` Jie Zhan
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=9041c44e-b81a-879d-90cd-3ad0e8992c6c@hisilicon.com \
--to=zhanjie9@hisilicon.com \
--cc=beata.michalska@arm.com \
--cc=ionela.voinescu@arm.com \
--cc=jonathan.cameron@huawei.com \
--cc=lihuisong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=pmalani@google.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=yubowen8@huawei.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
all inboxes | Powered by JetHome®