Re: [PATCH 1/2] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
From: Badole, Vishal
Date: Mon Nov 23 2026 - 06:46:22 EST
Hello Prateek,
Thanks for reviewing this patch.
On 11/17/2026 11:49 AM, K Prateek Nayak wrote:
Hello Vishal,Thanks for the suggestion. Given our future plans for the HFI driver, I would prefer to keep this CAS series independent of a broader HFI ownership rework.
On 11/14/2026 8:33 PM, Vishal Badole wrote:
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 4bedfbfc18b6..59eb2c4c7867 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -29,6 +29,7 @@
#include <linux/smp.h>
#include <linux/sched.h>
#include <linux/cpufreq.h>
+#include <linux/sched/smt.h>
#include <linux/compiler.h>
#include <linux/dmi.h>
#include <linux/slab.h>
@@ -39,6 +40,8 @@
#include <linux/power_supply.h>
#include <linux/static_call.h>
#include <linux/topology.h>
+#include <linux/cpuset.h>
+#include <linux/amd-pstate.h>
#include <acpi/processor.h>
#include <acpi/cppc_acpi.h>
@@ -86,6 +89,10 @@ static struct cpufreq_driver amd_pstate_driver;
static struct cpufreq_driver amd_pstate_epp_driver;
static int cppc_state = AMD_PSTATE_UNDEFINED;
static bool amd_pstate_prefcore = true;
+static bool amd_pstate_cas = true;
+static bool amd_pstate_cas_initialized;
+static u32 amd_pstate_ref_freq_khz;
+static u32 amd_pstate_ref_highest_perf;
static struct quirk_entry *quirks;
/*
@@ -957,8 +964,8 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
return;
/* should use amd-hfi instead */
- if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
- IS_ENABLED(CONFIG_AMD_HFI)) {
+ if ((cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
+ IS_ENABLED(CONFIG_AMD_HFI)) || amd_pstate_cas) {
This keeps getting uglier. I think you should have a preperatory patch to
negotiate this and maybe a late initcall like Mario suggested to actually
toggle the itmt support.
I was thinking something like folows to negotiate the who / what gets
the owenership:
diff --git a/arch/x86/include/asm/amd/hfi.h b/arch/x86/include/asm/amd/hfi.h
new file mode 100644
index 000000000000..2a86d0049b8f
--- /dev/null
+++ b/arch/x86/include/asm/amd/hfi.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __ASM_X86_AMD_HFI_H__
+#define __ASM_X86_AMD_HFI_H__
+
+enum amd_hfi_mode {
+ AMD_HFI_UNDEFINED,
+ AMD_HFI_PREFCORE, /* amd-pstate defined preferred core. */
+ AMD_HFI_ACPI, /* amd_hfi defined from ACPI PCCT. */
+ AMD_HFI_ASYM_CAPACITY, /* Amd-pstate defined asymmetric capacity. */
+};
+
+static enum amd_hfi_mode amd_hfi_current_mode = AMD_HFI_UNDEFINED;
+
+static void amd_hfi_set_mode(enum amd_hfi_mode mode)
+{
+ if (mode <= amd_hfi_current_mode)
+ return;
+
+ amd_hfi_current_mode = mode;
+}
+
+static enum amd_hfi_mode amd_hfi_get_mode(enum amd_hfi_mode mode)
+{
+ return amd_hfi_current_mode;
+}
+
+#endif /* __ASM_X86_AMD_HFI_H__ */
---
For this series, I would like to follow your earlier suggestion and move the global amd_pstate_prefcore decision into amd_pstate_init(), rather than the per-CPU initialization paths, as a preparatory patch.
Prateek, my point was that CPU 0 is not always the highest-performance CPU on newer hardware. I used CPU 0 considering highest perf CPU with Mario’s patches in mind, where Fmax is hardcoded per core type and shared by cores of that type. That handling does not apply to older hardware.amd_pstate_prefcore = false;
return;
}
@@ -969,6 +976,64 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu);
}
+bool amd_pstate_cas_active(void)
+{
+ return READ_ONCE(amd_pstate_cas_initialized);
+}
+EXPORT_SYMBOL_GPL(amd_pstate_cas_active);
You can then just use amd_hfi_get_mode() instead of this.
+
+static bool __init amd_pstate_init_cas(void)
+{
+ int highest_perf, max_freq;
+
+ highest_perf = amd_get_effective_highest_perf(0);
Didn't you mention an efficiency core / LP core could also be
the boot CPU? How are you considering it as your highest
reference then?
I think we can tak a page from how intel_pstate does a
hybrid_set_cpu_capacity() which iterates all online CPUs after driver
registration / if onlining changes the hybrid_max_perf_cpu.
However, sharing Fmax within a core type does not guarantee that CPU 0 belongs to the highest-performance type. I will update the series to select the highest-performance online CPU and recalculate capacities if a stronger CPU first comes online later.
The x86 hybrid-capacity implementation requires CONFIG_SMP && CONFIG_X86_64. Otherwise, arch_enable_hybrid_capacity_scale() is a stub returning false: topology.h:299 and x86_topology_update is defined in smpboot.c:127, which is built only with SMP.+ if (highest_perf <= 0) {
+ pr_warn("Invalid reference highest performance (%d)\n", highest_perf);
+ return false;
+ }
+
+ max_freq = amd_get_max_frequency(0);
+ if (max_freq < 0 || (u32)max_freq > U32_MAX / 1000) {
+ pr_warn("Invalid reference maximum frequency (%d)\n", max_freq);
+ return false;
+ }
+
+ amd_pstate_ref_highest_perf = highest_perf;
+ amd_pstate_ref_freq_khz = max_freq * 1000U;
+
+ return arch_enable_hybrid_capacity_scale();
+}
+
+static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata,
+ bool highest_freq_available)
+{
+ unsigned long capacity, max_capacity, capacity_freq, base_freq;
+
+ if (!IS_ENABLED(CONFIG_SMP))
+ return;
What is the CONFIG_SMP dependnecy for?
Without this check when CONFIG_SMP is set to 'n', build will fail with following error:
amd-pstate.c:(.text+0xf23c09): undefined reference to `x86_topology_update'
On newer-generation hardware, the performance-value ranges have changed across all core types, and the differences between core types are smaller than on older hardware.+
+ if (highest_freq_available && amd_pstate_ref_freq_khz) {
+ capacity = cpudata->max_freq;
+ max_capacity = amd_pstate_ref_freq_khz;
+ capacity_freq = capacity;
+ base_freq = max_capacity;
+ } else {
+ union perf_cached perf = READ_ONCE(cpudata->perf);
+
+ capacity = perf.highest_perf;
+ max_capacity = amd_pstate_ref_highest_perf;
You can just cache the freq corresponding to
amd_pstate_ref_highest_perf and not need two seperate global
variables.
Inferring and caching a reference frequency solely from amd_pstate_ref_highest_perf can therefore misrepresent the actual frequency differences and produce incorrect capacity scaling. We should use the actual maximum frequency when available and keep performance-based scaling as a separate fallback.
The mutex was intended to serialize capacity publication and the x86_topology_update write with the scheduler’s read-and-clear of that flag during domain rebuilding.+ capacity_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf);
+ base_freq = perf_to_freq(perf, cpudata->nominal_freq, max_capacity);
+ }
+
+ guard(mutex)(&sched_domains_mutex);
Why "sched_domains_mutex"? Probably means you are setting
x86_topology_update at the wrong time.
Normal CPU hotplug provides serialization, but .init() also runs during driver re-registration under cpus_read_lock(), which does not exclude concurrent cpuset-triggered rebuilds. That was the reason for using the same mutex.
I’ll revisit the notification timing to see whether we can avoid taking a scheduler-global mutex in this path.
Ack. Mario also suggested this, along with a few additional changes. I’ll incorporate them in the next revision of the patch.+ arch_set_cpu_capacity(cpudata->cpu, capacity, max_capacity,
+ capacity_freq, base_freq);
+ topology_set_cpu_scale(cpudata->cpu, arch_scale_cpu_capacity(cpudata->cpu));
+ x86_topology_update = true;
+ WRITE_ONCE(amd_pstate_cas_initialized, true);
+}
+
static void amd_pstate_update_limits(struct cpufreq_policy *policy)
{
struct amd_cpudata *cpudata;
@@ -1043,6 +1108,7 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
u32 min_freq, max_freq, nominal_freq, lowest_nonlinear_freq;
struct cppc_perf_caps cppc_perf;
union perf_cached perf;
+ bool highest_freq_available;
int ret;
ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
@@ -1069,6 +1135,7 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
/* try to look up from BIOS/quirk first, fall back to (nominal_freq * highest_perf)/nominal_perf */
max_freq = amd_get_max_frequency(cpudata->cpu) * 1000;
+ highest_freq_available = !!max_freq;
if (!max_freq)
max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf);
WRITE_ONCE(cpudata->max_freq, max_freq);
@@ -1100,6 +1167,9 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
bios_min_freq, cpudata->cpu);
}
+ if (amd_pstate_cas)
+ amd_pstate_set_cpu_capacity(cpudata, highest_freq_available);
+
return 0;
}
@@ -1923,12 +1993,20 @@ static ssize_t prefcore_show(struct device *dev,
return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore));
}
+static ssize_t cas_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_cas_active()));
+}
+
static DEVICE_ATTR_RW(status);
static DEVICE_ATTR_RO(prefcore);
+static DEVICE_ATTR_RO(cas);
static struct attribute *pstate_global_attributes[] = {
&dev_attr_status.attr,
&dev_attr_prefcore.attr,
+ &dev_attr_cas.attr,
NULL
};
@@ -2438,12 +2516,23 @@ static int __init amd_pstate_init(void)
return ret;
}
+ amd_pstate_cas = amd_pstate_cas && IS_ENABLED(CONFIG_SMP) &&
+ cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES);
+
+ /* Enable CAS for processors with heterogeneous cores. */
+ if (amd_pstate_cas)
+ amd_pstate_cas = amd_pstate_init_cas();
That two step disable is pretty ugly. Why couldn't you push the
feature checks into amd_pstate_init_cas()?
I used intel_pstate as a reference here, following your earlier suggestion. The intention is to rebuild domains once after publishing the asymmetric capacities. Since amd-pstate initializes via device_initcall(), the initial scheduler domains have already been built by that point.+
ret = amd_pstate_register_driver(cppc_state);
if (ret) {
pr_err("failed to register with return %d\n", ret);
return ret;
}
+ /* Per-CPU capacities are set during registration; rebuild domains once. */
+ if (amd_pstate_cas)
+ rebuild_sched_domains();
+
Isn't this super early into the boot? You don't need to rebuild sched
domains here since they will be done later (I'm having a deja vu moment
from a previous review)
Ack!dev_root = bus_get_dev_root(&cpu_subsys);
if (dev_root) {
ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group);
@@ -2484,8 +2573,17 @@ static int __init amd_prefcore_param(char *str)
return 0;
}
+static int __init amd_cas_param(char *str)
+{
+ if (!strcmp(str, "disable"))
+ amd_pstate_cas = false;
+
+ return 0;
+}
+
early_param("amd_pstate", amd_pstate_param);
early_param("amd_prefcore", amd_prefcore_param);
+early_param("amd_cas", amd_cas_param);
MODULE_AUTHOR("Huang Rui <ray.huang@xxxxxxx>");
MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver");
diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
Why not arch/x86/include/asm/amd/amd-pstate.h since all of this is
AMd related?
new file mode 100644
index 000000000000..eb750abd20f7
--- /dev/null
+++ b/include/linux/amd-pstate.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Public interface for the AMD P-state driver.
+ */
+#ifndef __LINUX_AMD_PSTATE_H__
+#define __LINUX_AMD_PSTATE_H__
+
+#if IS_ENABLED(CONFIG_X86_AMD_PSTATE)
+bool amd_pstate_cas_active(void);
+#else
+static inline bool amd_pstate_cas_active(void) { return false; }
+#endif
+
+#endif /* __LINUX_AMD_PSTATE_H__ */