From: lirongqing <lirongqing@baidu.com>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <zhongqiu.han@oss.qualcomm.com>, Li RongQing <lirongqing@baidu.com>
Subject: [PATCH v6 2/2] cpufreq: acpi-cpufreq: report filtered-out P-states in extract_msr()
Date: Sat, 14 Nov 2026 22:07:24 +0800 [thread overview]
Message-ID: <20261114140724.2336-3-lirongqing@baidu.com> (raw)
In-Reply-To: <20261114140724.2336-1-lirongqing@baidu.com>
From: Li RongQing <lirongqing@baidu.com>
extract_msr() maps the status value read from the hardware to a
frequency by walking policy->freq_table. freq_table[] is built by
filtering out _PSS entries that are not lower in frequency than the
previous one, so firmware may autonomously switch the CPU to a P-state
that has no freq_table entry. The status of such a P-state cannot be
matched and extract_msr() falls back to freq_table[0].frequency.
get_cur_freq_on_cpu() is the ->get() callback for the
ACPI_ADR_SPACE_FIXED_HARDWARE case. When firmware has changed the
P-state behind the OS's back, it sets data->resume so that the next
->target() call rewrites the control register even if the requested
P-state equals perf->state. However, acpi_cpufreq_target() is reached
only if the cpufreq core sees a difference between the requested
frequency and policy->cur, because __cpufreq_driver_target() and
__target_index() return early when target_freq == policy->cur.
policy->cur is resynchronized from the ->get() value by
cpufreq_verify_current_freq(), so the frequency returned by ->get()
has to differ from policy->cur for data->resume to be acted upon in
the ->target_index() path.
If the OS is at the P-state corresponding to freq_table[0] and firmware
switches the CPU to a filtered-out P-state, the fallback makes ->get()
return the same frequency as policy->cur and cached_freq. data->resume
is left clear, policy->cur is not updated, and the CPU stays at the
firmware-selected P-state while the cpufreq core believes it is at
freq_table[0].
Look the status up in all of perf->states[] instead and return the
frequency of the matching ACPI P-state. For P-states retained in
freq_table[] this returns the same value as before, because the
frequency of each freq_table entry is perf->states[driver_data]
.core_frequency converted to kHz. For a filtered-out P-state whose
frequency differs from policy->cur, get_cur_freq_on_cpu() now sets
data->resume and the cpufreq core updates policy->cur through
cpufreq_out_of_sync(), so the next request for the expected P-state
reaches acpi_cpufreq_target() and rewrites the control register.
The fallback to freq_table[0].frequency is kept for a status that
matches no _PSS entry at all, since returning 0 from ->get() makes
cpufreq_online() fail and triggers a warning in cpufreq_update_policy().
A filtered-out P-state with the same frequency as policy->cur is still
not detected through the ->target_index() path, but in that case the
CPU runs at the frequency the cpufreq core expects.
extract_io() is not changed: for ACPI_ADR_SPACE_SYSTEM_IO no ->get()
callback is registered and extract_io() is only used by check_freqs().
Fixes: e56a727b023d ("[CPUFREQ] Make acpi-cpufreq more robust against BIOS freq changes behind our back.")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260910111329.2220-1-lirongqing%40baidu.com
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
drivers/cpufreq/acpi-cpufreq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 2d7d147..3dc7ee4 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -210,8 +210,8 @@ static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
{
struct acpi_cpufreq_data *data = policy->driver_data;
- struct cpufreq_frequency_table *pos;
struct acpi_processor_performance *perf;
+ unsigned int i;
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
msr &= AMD_MSR_RANGE;
@@ -222,9 +222,9 @@ static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
perf = to_perf_data(data);
- cpufreq_for_each_entry(pos, policy->freq_table)
- if (msr == perf->states[pos->driver_data].status)
- return pos->frequency;
+ for (i = 0; i < perf->state_count; i++)
+ if (msr == perf->states[i].status)
+ return perf->states[i].core_frequency * 1000;
return policy->freq_table[0].frequency;
}
--
2.9.4
prev parent reply other threads:[~2026-11-14 14:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 14:07 [PATCH v6 0/2] cpufreq: acpi-cpufreq: fix P-state index mismatch between perf->states[] and freq_table[] lirongqing
2026-11-14 14:07 ` [PATCH v6 1/2] cpufreq: acpi-cpufreq: fix P-state index mismatch in get_cur_freq_on_cpu() lirongqing
2026-11-14 14:07 ` lirongqing [this message]
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=20261114140724.2336-3-lirongqing@baidu.com \
--to=lirongqing@baidu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhongqiu.han@oss.qualcomm.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®