Re: [PATCH v6 2/2] cpufreq: acpi-cpufreq: report filtered-out P-states in extract_msr()

From: Zhongqiu Han

Date: Tue Nov 17 2026 - 06:16:01 EST


On 11/14/2026 10:07 PM, lirongqing wrote:
From: Li RongQing <lirongqing@xxxxxxxxx>

---
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;
}

Walking all of perf->states[] may make ->get() report _PSS entries that
acpi_cpufreq_cpu_init() deliberately dropped from freq_table[]. Such
entries do exist in real tables, e.g. Lenovo Legion Y9000X IAH7 in
linuxhw/ACPI [1][3]:


2600 MHz ctl 0x1a00 kept
2300 MHz ctl 0x1700 kept
2400 MHz ctl 0x1800 dropped
2200 MHz ... kept

If the CPU can end up in such an entry, there are two problems:

1) ->get() can return an unlisted frequency (2400 MHz on the Legion).
At policy creation this leaves cpufreq_stats permanently stuck.

2) A dropped entry sharing its status with a later retained one is
matched first, so the retained state is misreported (theoretical).

I wonder if we can keep the existing loop and only fall back to the
dropped entries, restricted to listed frequencies:

```diff
@@ 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, freq;
...
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)
+ continue;
+
+ freq = perf->states[i].core_frequency * 1000;
+ if (cpufreq_frequency_table_get_index(policy, freq) >= 0)
+ return freq;
+ }
+
return policy->freq_table[0].frequency;
```

The first loop is unchanged, so retained entries behave exactly as
before (2). The second loop only runs where the current code falls back
to freq_table[0], and never returns an unlisted frequency (1).

Note that what the second loop can find is then a same-frequency twin,
like P1 on the X370[2]:

3775 MHz 4590 mW ctl 0x0 kept
3775 MHz 4050 mW ctl 0x1 dropped
2200 MHz 1980 mW ctl 0x2 kept

There the reported frequency is right (as is today's freq_table[0]
fallback), but the twin may run at a different voltage, and since the
frequency matches policy->cur the control register is not rewritten.


Hi Rafael,
May I ask what you think about this? And please feel free to correct me.


[1] https://github.com/linuxhw/ACPI
[2] https://github.com/linuxhw/ACPI/blob/master/Desktop/ASUSTek%20Computer/PRIME/PRIME%20X370-PRO/22F59A67504C#L11328
[3] https://github.com/linuxhw/ACPI/blob/master/Notebook/Lenovo/Legion/Legion%20Y9000X%20IAH7%2082TF/CB118A4005F6#L135790


--
Thx and BRs,
Zhongqiu Han