mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: lirongqing <lirongqing@baidu.com>,
	"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 <zhongqiu.han@oss.qualcomm.com>
Subject: Re: [PATCH v6 2/2] cpufreq: acpi-cpufreq: report filtered-out P-states in extract_msr()
Date: Tue, 17 Nov 2026 19:15:52 +0800	[thread overview]
Message-ID: <d77a8540-b1ef-476c-b03c-97e4483f71c9@oss.qualcomm.com> (raw)
In-Reply-To: <20261114140724.2336-3-lirongqing@baidu.com>

On 11/14/2026 10:07 PM, lirongqing wrote:
> From: 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;
>   }
>   

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

      reply	other threads:[~2026-11-17 11:15 UTC|newest]

Thread overview: 4+ 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 ` [PATCH v6 2/2] cpufreq: acpi-cpufreq: report filtered-out P-states in extract_msr() lirongqing
2026-11-17 11:15   ` Zhongqiu Han [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=d77a8540-b1ef-476c-b03c-97e4483f71c9@oss.qualcomm.com \
    --to=zhongqiu.han@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /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®