[PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()

Rafael J. Wysocki posted 1 patch 2 days, 21 hours ago
drivers/cpufreq/cpufreq.c      |    4 ++--
drivers/cpufreq/intel_pstate.c |   10 ++++++++++
include/linux/cpufreq.h        |    3 +++
3 files changed, 15 insertions(+), 2 deletions(-)
[PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()
Posted by Rafael J. Wysocki 2 days, 21 hours ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

After commit d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall
back to cpuinfo.max_freq"), cpufreq pressure appears in the CPU load
balancer unexpectedly in some cases in which it was not present before,
leading to confusion and uncertainty.

Clearly, the scheduler assumes that cpufreq pressure will not be set
unless the capacity reference frequency of the CPU is known, and the
commit mentioned above violates that assumption.

However, in some cases the capacity reference frequency of the CPU is
in fact known even though arch_scale_freq_ref() returns 0 and in those
cases it should be possible to set cpufreq pressure as appropriate.

For this purpose, introduce a new cpufreq driver callback returning
the CPU capacity reference frequency, .scale_freq_ref(), and make
cpufreq_update_pressure() invoke it, if present, instead of falling
back to cpuinfo.max_freq unconditionally.

Add that callback to the intel_pstate driver and make it return 0 unless
the scale-invariant capacity of the given CPU has been explicitly set,
in which cases its reference frequency is always cpuinfo.max_freq.

Fixes: d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall back to cpuinfo.max_freq")
Reported-by: Jianyong Wu <wujianyong@hygon.cn>
Closes: https://lore.kernel.org/linux-pm/20260915065747.1671965-1-wujianyong@hygon.cn/
Tested-by: Jianyong Wu <wujianyong@hygon.cn>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq.c      |    4 ++--
 drivers/cpufreq/intel_pstate.c |   10 ++++++++++
 include/linux/cpufreq.h        |    3 +++
 3 files changed, 15 insertions(+), 2 deletions(-)

--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2590,8 +2590,8 @@ static void cpufreq_update_pressure(stru
 
 	cpu = cpumask_first(policy->related_cpus);
 	max_freq = arch_scale_freq_ref(cpu);
-	if (!max_freq)
-		max_freq = policy->cpuinfo.max_freq;
+	if (!max_freq && cpufreq_driver->scale_freq_ref)
+		max_freq = cpufreq_driver->scale_freq_ref(policy);
 
 	capped_freq = policy->max;
 
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1135,6 +1135,14 @@ static bool hybrid_clear_max_perf_cpu(vo
 	return ret;
 }
 
+static unsigned int intel_pstate_scale_freq_ref(struct cpufreq_policy *policy)
+{
+	if (all_cpu_data[policy->cpu]->capacity_perf)
+		return policy->cpuinfo.max_freq;
+
+	return 0;
+}
+
 static void intel_pstate_update_freq_limits(struct cpudata *cpu)
 {
 	int scaling = cpu->pstate.scaling;
@@ -3088,6 +3096,7 @@ static struct cpufreq_driver intel_pstat
 	.offline	= intel_pstate_cpu_offline,
 	.online		= intel_pstate_cpu_online,
 	.update_limits	= intel_pstate_update_limits,
+	.scale_freq_ref = intel_pstate_scale_freq_ref,
 	.name		= "intel_pstate",
 };
 
@@ -3411,6 +3420,7 @@ static struct cpufreq_driver intel_cpufr
 	.suspend	= intel_cpufreq_suspend,
 	.resume		= intel_pstate_resume,
 	.update_limits	= intel_pstate_update_limits,
+	.scale_freq_ref = intel_pstate_scale_freq_ref,
 	.name		= "intel_cpufreq",
 };
 
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -420,6 +420,9 @@ struct cpufreq_driver {
 	/* Will be called after the driver is fully initialized */
 	void		(*ready)(struct cpufreq_policy *policy);
 
+	/* Return the capacity reference frequency for policy. */
+	unsigned int	(*scale_freq_ref)(struct cpufreq_policy *policy);
+
 	struct freq_attr **attr;
 
 	/* platform specific boost support code */
Re: [PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()
Posted by Chen Yu 1 day ago
On Mon, Sep 21, 2026 at 09:12:00PM +0200, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> After commit d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall
> back to cpuinfo.max_freq"), cpufreq pressure appears in the CPU load
> balancer unexpectedly in some cases in which it was not present before,
> leading to confusion and uncertainty.
> 
> Clearly, the scheduler assumes that cpufreq pressure will not be set
> unless the capacity reference frequency of the CPU is known, and the
> commit mentioned above violates that assumption.
> 
> However, in some cases the capacity reference frequency of the CPU is
> in fact known even though arch_scale_freq_ref() returns 0 and in those
> cases it should be possible to set cpufreq pressure as appropriate.
> 
> For this purpose, introduce a new cpufreq driver callback returning
> the CPU capacity reference frequency, .scale_freq_ref(), and make
> cpufreq_update_pressure() invoke it, if present, instead of falling
> back to cpuinfo.max_freq unconditionally.
> 
> Add that callback to the intel_pstate driver and make it return 0 unless
> the scale-invariant capacity of the given CPU has been explicitly set,
> in which cases its reference frequency is always cpuinfo.max_freq.
> 
> Fixes: d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall back to cpuinfo.max_freq")
> Reported-by: Jianyong Wu <wujianyong@hygon.cn>
> Closes: https://lore.kernel.org/linux-pm/20260915065747.1671965-1-wujianyong@hygon.cn/
> Tested-by: Jianyong Wu <wujianyong@hygon.cn>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

I did not observe any issue on a 4LLCs per node Xeon server when running
cache-aware-schedulings santity test,

Tested-by: Chen Yu <yu.c.chen@intel.com>

thanks,
Chenyu
Re: [PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()
Posted by Rafael J. Wysocki (Intel) 1 day ago
On Wed, Sep 23, 2026 at 6:32 PM Chen Yu <yu.c.chen@intel.com> wrote:
>
> On Mon, Sep 21, 2026 at 09:12:00PM +0200, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > After commit d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall
> > back to cpuinfo.max_freq"), cpufreq pressure appears in the CPU load
> > balancer unexpectedly in some cases in which it was not present before,
> > leading to confusion and uncertainty.
> >
> > Clearly, the scheduler assumes that cpufreq pressure will not be set
> > unless the capacity reference frequency of the CPU is known, and the
> > commit mentioned above violates that assumption.
> >
> > However, in some cases the capacity reference frequency of the CPU is
> > in fact known even though arch_scale_freq_ref() returns 0 and in those
> > cases it should be possible to set cpufreq pressure as appropriate.
> >
> > For this purpose, introduce a new cpufreq driver callback returning
> > the CPU capacity reference frequency, .scale_freq_ref(), and make
> > cpufreq_update_pressure() invoke it, if present, instead of falling
> > back to cpuinfo.max_freq unconditionally.
> >
> > Add that callback to the intel_pstate driver and make it return 0 unless
> > the scale-invariant capacity of the given CPU has been explicitly set,
> > in which cases its reference frequency is always cpuinfo.max_freq.
> >
> > Fixes: d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall back to cpuinfo.max_freq")
> > Reported-by: Jianyong Wu <wujianyong@hygon.cn>
> > Closes: https://lore.kernel.org/linux-pm/20260915065747.1671965-1-wujianyong@hygon.cn/
> > Tested-by: Jianyong Wu <wujianyong@hygon.cn>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> I did not observe any issue on a 4LLCs per node Xeon server when running
> cache-aware-schedulings santity test,
>
> Tested-by: Chen Yu <yu.c.chen@intel.com>

Thanks!
Re: [PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()
Posted by Ricardo Neri 1 day, 2 hours ago
On Mon, Sep 21, 2026 at 09:12:00PM +0200, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> After commit d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall
> back to cpuinfo.max_freq"), cpufreq pressure appears in the CPU load
> balancer unexpectedly in some cases in which it was not present before,
> leading to confusion and uncertainty.
> 
> Clearly, the scheduler assumes that cpufreq pressure will not be set
> unless the capacity reference frequency of the CPU is known, and the
> commit mentioned above violates that assumption.
> 
> However, in some cases the capacity reference frequency of the CPU is
> in fact known even though arch_scale_freq_ref() returns 0 and in those
> cases it should be possible to set cpufreq pressure as appropriate.
> 
> For this purpose, introduce a new cpufreq driver callback returning
> the CPU capacity reference frequency, .scale_freq_ref(), and make
> cpufreq_update_pressure() invoke it, if present, instead of falling
> back to cpuinfo.max_freq unconditionally.
> 
> Add that callback to the intel_pstate driver and make it return 0 unless
> the scale-invariant capacity of the given CPU has been explicitly set,
> in which cases its reference frequency is always cpuinfo.max_freq.
> 
> Fixes: d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall back to cpuinfo.max_freq")
> Reported-by: Jianyong Wu <wujianyong@hygon.cn>
> Closes: https://lore.kernel.org/linux-pm/20260915065747.1671965-1-wujianyong@hygon.cn/
> Tested-by: Jianyong Wu <wujianyong@hygon.cn>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

This patch did not break anything for me. I tested this in several Intel
processors with asymmetric capacity capacity enabled. Tasks spread as
expected when no cpufreq pressure is applied. Tasks duly migrate away when
this pressure is applied to a subset of CPUs. They come back when the
pressure is removed.

Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> # Intel hybrid parts
Re: [PATCH v1] cpufreq: intel_pstate: Fix max_freq fallback in cpufreq_update_pressure()
Posted by Rafael J. Wysocki (Intel) 1 day, 2 hours ago
On Wed, Sep 23, 2026 at 4:42 PM Ricardo Neri
<ricardo.neri-calderon@linux.intel.com> wrote:
>
> On Mon, Sep 21, 2026 at 09:12:00PM +0200, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > After commit d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall
> > back to cpuinfo.max_freq"), cpufreq pressure appears in the CPU load
> > balancer unexpectedly in some cases in which it was not present before,
> > leading to confusion and uncertainty.
> >
> > Clearly, the scheduler assumes that cpufreq pressure will not be set
> > unless the capacity reference frequency of the CPU is known, and the
> > commit mentioned above violates that assumption.
> >
> > However, in some cases the capacity reference frequency of the CPU is
> > in fact known even though arch_scale_freq_ref() returns 0 and in those
> > cases it should be possible to set cpufreq pressure as appropriate.
> >
> > For this purpose, introduce a new cpufreq driver callback returning
> > the CPU capacity reference frequency, .scale_freq_ref(), and make
> > cpufreq_update_pressure() invoke it, if present, instead of falling
> > back to cpuinfo.max_freq unconditionally.
> >
> > Add that callback to the intel_pstate driver and make it return 0 unless
> > the scale-invariant capacity of the given CPU has been explicitly set,
> > in which cases its reference frequency is always cpuinfo.max_freq.
> >
> > Fixes: d2d5c129d07e ("cpufreq: Make cpufreq_update_pressure() fall back to cpuinfo.max_freq")
> > Reported-by: Jianyong Wu <wujianyong@hygon.cn>
> > Closes: https://lore.kernel.org/linux-pm/20260915065747.1671965-1-wujianyong@hygon.cn/
> > Tested-by: Jianyong Wu <wujianyong@hygon.cn>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> This patch did not break anything for me. I tested this in several Intel
> processors with asymmetric capacity capacity enabled. Tasks spread as
> expected when no cpufreq pressure is applied. Tasks duly migrate away when
> this pressure is applied to a subset of CPUs. They come back when the
> pressure is removed.
>
> Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> # Intel hybrid parts

Thank you!

In the absence of objections or concerns, I'll queue up this patch as
a fix for 7.3.