* [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms
@ 2026-11-25 17:20 Vishal Badole
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Vishal Badole @ 2026-11-25 17:20 UTC (permalink / raw)
To: ray.huang, mario.limonciello, rafael, viresh.kumar, perry.yuan,
kprateek.nayak, hansg, ilpo.jarvinen, platform-driver-x86,
linux-pm, linux-kernel
Cc: Vishal Badole
This series enables Capacity Aware Scheduling (CAS) for AMD heterogeneous
processors.
amd-pstate does not export per-CPU capacity today, so the scheduler treats
all cores as equal and places tasks without regard to core strength.
Patch 1 moves the HFI check before amd-pstate driver registration, making
the preferred-core scheduling decision before per-CPU initialization.
Patch 2 makes amd-pstate publish asymmetric per-CPU capacities via the arch
hybrid capacity scaling interface. CAS is enabled by default on supported
hardware and can be turned off with the "amd_cas=disable" boot parameter.
Patch 3 makes amd-hfi stand down when CAS is active, since both manage the
same scheduler state. HFI initialization is deferred until amd-pstate has
established the CAS state.
Changes since v1:
- Add a preparation patch to finalize prefcore before driver registration.
- Select the reference CPU from all online CPUs instead of assuming CPU 0.
Scale by maximum frequency when available for both CPUs, or by effective
highest performance otherwise.
- Update the reference when a stronger CPU is initialized and rescale
existing CPUs, including offline CPUs with retained policy data.
- Move the public AMD P-state header to arch/x86/include/asm/amd/.
- Defer HFI initialization to a late initcall for the CAS state check.
- Link to v1:
https://lore.kernel.org/all/20261114150310.1377654-1-Vishal.Badole@amd.com/
Krishnamoorthi M (1):
platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
Vishal Badole (2):
cpufreq: amd-pstate: Finalize prefcore before registration
cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
MAINTAINERS | 1 +
arch/x86/include/asm/amd/amd-pstate.h | 16 +++
arch/x86/kernel/acpi/cppc.c | 4 +-
drivers/cpufreq/amd-pstate.c | 157 ++++++++++++++++++++++++--
drivers/platform/x86/amd/hfi/hfi.c | 9 +-
5 files changed, 177 insertions(+), 10 deletions(-)
create mode 100644 arch/x86/include/asm/amd/amd-pstate.h
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration
2026-11-25 17:20 [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms Vishal Badole
@ 2026-11-25 17:20 ` Vishal Badole
2026-11-30 15:38 ` Mario Limonciello
2026-11-25 17:20 ` [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
2026-11-25 17:20 ` [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole
2 siblings, 1 reply; 8+ messages in thread
From: Vishal Badole @ 2026-11-25 17:20 UTC (permalink / raw)
To: ray.huang, mario.limonciello, rafael, viresh.kumar, perry.yuan,
kprateek.nayak, hansg, ilpo.jarvinen, platform-driver-x86,
linux-pm, linux-kernel
Cc: Vishal Badole
The choice between amd-hfi and preferred-core scheduling applies to the
whole system. However, the HFI check currently runs during per-CPU
initialization and clears the global amd_pstate_prefcore flag.
Move the check to amd_pstate_init(), after preferred-core detection and
before driver registration.
Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>
---
drivers/cpufreq/amd-pstate.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 4bedfbfc18b66..3e0308f644778 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -956,13 +956,6 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
if (!amd_pstate_prefcore)
return;
- /* should use amd-hfi instead */
- if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
- IS_ENABLED(CONFIG_AMD_HFI)) {
- amd_pstate_prefcore = false;
- return;
- }
-
cpudata->hw_prefcore = true;
/* Priorities must be initialized before ITMT support can be toggled on. */
@@ -2438,6 +2431,10 @@ static int __init amd_pstate_init(void)
return ret;
}
+ if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
+ IS_ENABLED(CONFIG_AMD_HFI))
+ amd_pstate_prefcore = false;
+
ret = amd_pstate_register_driver(cppc_state);
if (ret) {
pr_err("failed to register with return %d\n", ret);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
2026-11-25 17:20 [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms Vishal Badole
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
@ 2026-11-25 17:20 ` Vishal Badole
2026-11-30 8:24 ` K Prateek Nayak
2026-11-25 17:20 ` [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole
2 siblings, 1 reply; 8+ messages in thread
From: Vishal Badole @ 2026-11-25 17:20 UTC (permalink / raw)
To: ray.huang, mario.limonciello, rafael, viresh.kumar, perry.yuan,
kprateek.nayak, hansg, ilpo.jarvinen, platform-driver-x86,
linux-pm, linux-kernel
Cc: Vishal Badole
AMD heterogeneous processors combine multiple core types (e.g.
performance and efficiency cores) whose maximum sustained performance
and frequency differ. On such platforms the Linux scheduler relies on
per-CPU capacity values to place and balance tasks across cores.
Today amd-pstate does not export any per-CPU capacity information. As a
result the scheduler sees every CPU as having identical capacity and
treats performance and efficiency cores as interchangeable. Tasks are
therefore placed and balanced without regard to core strength, which
hurts both throughput and energy efficiency on hybrid systems.
This happens because the scheduler defaults to a uniform
SCHED_CAPACITY_SCALE when no arch- or driver-supplied capacity exists,
and amd-pstate never feeds the asymmetry it knows (via CPPC highest
frequency or the effective highest performance register) into the arch
hybrid capacity scaling interface.
Enable capacity aware scheduling by scaling each CPU's capacity relative
to a reference CPU. Use the maximum attainable frequencies when available
for both CPUs, or their effective highest performance values otherwise.
If reference setup fails, keep CAS disabled and continue normal CPUFreq
registration.
Capacity aware scheduling is enabled by default on supported hardware and
can be turned off with the "amd_cas=disable" boot parameter. Its effective
state is exposed through the "cas" sysfs attribute, and also exported via
amd_pstate_cas_active() so amd-hfi can stand down when capacity aware
scheduling owns the heterogeneous cores.
Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>
---
MAINTAINERS | 1 +
arch/x86/include/asm/amd/amd-pstate.h | 16 +++
arch/x86/kernel/acpi/cppc.c | 4 +-
drivers/cpufreq/amd-pstate.c | 150 +++++++++++++++++++++++++-
4 files changed, 167 insertions(+), 4 deletions(-)
create mode 100644 arch/x86/include/asm/amd/amd-pstate.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb2b80..300dce181c1c4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1322,6 +1322,7 @@ R: K Prateek Nayak <kprateek.nayak@amd.com>
L: linux-pm@vger.kernel.org
S: Supported
F: Documentation/admin-guide/pm/amd-pstate.rst
+F: arch/x86/include/asm/amd/amd-pstate.h
F: drivers/cpufreq/amd-pstate*
F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
diff --git a/arch/x86/include/asm/amd/amd-pstate.h b/arch/x86/include/asm/amd/amd-pstate.h
new file mode 100644
index 0000000000000..1c0eb56c8f867
--- /dev/null
+++ b/arch/x86/include/asm/amd/amd-pstate.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Public interface for the AMD P-state driver.
+ */
+#ifndef _ASM_X86_AMD_PSTATE_H_
+#define _ASM_X86_AMD_PSTATE_H_
+
+#include <linux/types.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 /* _ASM_X86_AMD_PSTATE_H_ */
diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c
index 1c6bf56c3215b..15590e9da2dca 100644
--- a/arch/x86/kernel/acpi/cppc.c
+++ b/arch/x86/kernel/acpi/cppc.c
@@ -248,8 +248,8 @@ int amd_get_effective_highest_perf(unsigned int cpu)
if (ret < 0)
return ret;
- /* without preferred cores, return the highest perf register value */
- if (!prefcore)
+ /* Reuse the cached value for homogeneous CPUs without preferred cores. */
+ if (!prefcore && !cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
return boost_numerator;
/*
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 3e0308f644778..415553109fc26 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -39,10 +39,12 @@
#include <linux/power_supply.h>
#include <linux/static_call.h>
#include <linux/topology.h>
+#include <linux/cpuset.h>
#include <acpi/processor.h>
#include <acpi/cppc_acpi.h>
+#include <asm/amd/amd-pstate.h>
#include <asm/msr.h>
#include <asm/cpufeature.h>
#include <asm/cpu_device_id.h>
@@ -86,6 +88,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 = IS_ENABLED(CONFIG_SMP);
+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;
/*
@@ -962,6 +968,117 @@ 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);
+
+static void __init amd_pstate_init_cas(void)
+{
+ int ref_highest_perf = 0, ref_max_freq = 0;
+ int cpu, highest_perf, max_freq;
+
+ if (!amd_pstate_cas)
+ return;
+
+ amd_pstate_cas = false;
+ if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
+ return;
+
+ for_each_online_cpu(cpu) {
+ highest_perf = amd_get_effective_highest_perf(cpu);
+ if (highest_perf <= 0) {
+ pr_warn("Invalid highest performance (%d) on CPU%d\n",
+ highest_perf, cpu);
+ return;
+ }
+
+ max_freq = amd_get_max_frequency(cpu);
+ if (max_freq < 0 || (u32)max_freq > U32_MAX / 1000) {
+ pr_warn("Invalid maximum frequency (%d) on CPU%d\n",
+ max_freq, cpu);
+ return;
+ }
+
+ if (highest_perf < ref_highest_perf ||
+ (highest_perf == ref_highest_perf && max_freq <= ref_max_freq))
+ continue;
+
+ ref_highest_perf = highest_perf;
+ ref_max_freq = max_freq;
+ }
+
+ if (!ref_highest_perf) {
+ pr_warn("No reference CPU available for capacity scaling\n");
+ return;
+ }
+
+ amd_pstate_ref_highest_perf = ref_highest_perf;
+ amd_pstate_ref_freq_khz = ref_max_freq * 1000U;
+
+ amd_pstate_cas = arch_enable_hybrid_capacity_scale();
+}
+
+static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data,
+ bool highest_freq_available)
+{
+ unsigned long capacity, max_capacity, capacity_freq, base_freq;
+ int cpu = data->cpu;
+
+ lockdep_assert_held(&sched_domains_mutex);
+
+ if (highest_freq_available && amd_pstate_ref_freq_khz) {
+ capacity = data->max_freq;
+ max_capacity = amd_pstate_ref_freq_khz;
+ capacity_freq = capacity;
+ base_freq = max_capacity;
+ } else {
+ union perf_cached perf = READ_ONCE(data->perf);
+
+ capacity = perf.highest_perf;
+ max_capacity = amd_pstate_ref_highest_perf;
+ capacity_freq = perf_to_freq(perf, data->nominal_freq, perf.highest_perf);
+ base_freq = perf_to_freq(perf, data->nominal_freq, max_capacity);
+ }
+
+ arch_set_cpu_capacity(cpu, capacity, max_capacity, capacity_freq, base_freq);
+ topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu));
+}
+
+static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata,
+ bool highest_freq_available)
+{
+ union perf_cached perf = READ_ONCE(cpudata->perf);
+ int cpu;
+
+ lockdep_assert_cpus_held();
+
+ guard(mutex)(&sched_domains_mutex);
+
+ if (perf.highest_perf > amd_pstate_ref_highest_perf) {
+ amd_pstate_ref_highest_perf = perf.highest_perf;
+ amd_pstate_ref_freq_khz = highest_freq_available ? cpudata->max_freq : 0;
+
+ for_each_possible_cpu(cpu) {
+ struct cpufreq_policy *policy;
+
+ if (cpu == cpudata->cpu)
+ continue;
+
+ policy = cpufreq_cpu_policy(cpu);
+ if (policy && policy->driver_data)
+ amd_pstate_update_cpu_capacity(policy->driver_data,
+ amd_pstate_ref_freq_khz &&
+ amd_get_max_frequency(cpu) > 0);
+ }
+ }
+
+ amd_pstate_update_cpu_capacity(cpudata, highest_freq_available);
+ 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;
@@ -1036,6 +1153,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);
@@ -1062,6 +1180,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);
@@ -1093,6 +1212,9 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
bios_min_freq, cpudata->cpu);
}
+ if (IS_ENABLED(CONFIG_SMP) && amd_pstate_cas)
+ amd_pstate_set_cpu_capacity(cpudata, highest_freq_available);
+
return 0;
}
@@ -1203,6 +1325,7 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
freq_qos_remove_request(&cpudata->req[0]);
policy->fast_switch_possible = false;
kfree(cpudata);
+ policy->driver_data = NULL;
}
static int amd_pstate_get_balanced_epp(struct cpufreq_policy *policy)
@@ -1916,12 +2039,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
};
@@ -2431,8 +2562,10 @@ static int __init amd_pstate_init(void)
return ret;
}
- if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
- IS_ENABLED(CONFIG_AMD_HFI))
+ amd_pstate_init_cas();
+
+ if ((cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
+ IS_ENABLED(CONFIG_AMD_HFI)) || amd_pstate_cas)
amd_pstate_prefcore = false;
ret = amd_pstate_register_driver(cppc_state);
@@ -2441,6 +2574,10 @@ static int __init amd_pstate_init(void)
return ret;
}
+ /* Per-CPU capacities are set during registration; rebuild domains once. */
+ if (amd_pstate_cas)
+ rebuild_sched_domains();
+
dev_root = bus_get_dev_root(&cpu_subsys);
if (dev_root) {
ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group);
@@ -2481,8 +2618,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@amd.com>");
MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver");
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
2026-11-25 17:20 [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms Vishal Badole
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
2026-11-25 17:20 ` [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
@ 2026-11-25 17:20 ` Vishal Badole
2026-11-30 15:39 ` Mario Limonciello
2 siblings, 1 reply; 8+ messages in thread
From: Vishal Badole @ 2026-11-25 17:20 UTC (permalink / raw)
To: ray.huang, mario.limonciello, rafael, viresh.kumar, perry.yuan,
kprateek.nayak, hansg, ilpo.jarvinen, platform-driver-x86,
linux-pm, linux-kernel
Cc: Krishnamoorthi M, Vishal Badole
From: Krishnamoorthi M <krishnamoorthi.m@amd.com>
When amd-pstate CAS is active, it takes ownership of per-CPU capacity
values that the scheduler uses to distinguish performance and efficiency
cores. amd-hfi manages the same scheduler state through its ranking
mechanism. Running both simultaneously would cause them to overwrite
each other's settings, leading to unpredictable task placement on hybrid
platforms.
Avoid loading amd-hfi if CAS is enabled. Defer HFI driver initialization
to a late initcall so amd-pstate completes initialization before HFI
checks whether CAS is active.
Signed-off-by: Krishnamoorthi M <krishnamoorthi.m@amd.com>
Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>
---
drivers/platform/x86/amd/hfi/hfi.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 86a7f4332c35a..73e53203a838c 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -27,6 +27,7 @@
#include <linux/topology.h>
#include <linux/workqueue.h>
+#include <asm/amd/amd-pstate.h>
#include <asm/cpu_device_id.h>
#include <acpi/pcc.h>
@@ -536,6 +537,12 @@ static int __init amd_hfi_init(void)
!cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
return -ENODEV;
+ /* amd-pstate CAS owns heterogeneous core scheduling when enabled. */
+ if (amd_pstate_cas_active()) {
+ pr_debug("amd-pstate CAS is active, not loading amd-hfi\n");
+ return -ENODEV;
+ }
+
ret = platform_driver_register(&amd_hfi_driver);
if (ret)
pr_err("failed to register HFI driver\n");
@@ -547,7 +554,7 @@ static __exit void amd_hfi_exit(void)
{
platform_driver_unregister(&amd_hfi_driver);
}
-module_init(amd_hfi_init);
+late_initcall(amd_hfi_init);
module_exit(amd_hfi_exit);
MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
2026-11-25 17:20 ` [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
@ 2026-11-30 8:24 ` K Prateek Nayak
2026-11-30 15:40 ` Mario Limonciello
0 siblings, 1 reply; 8+ messages in thread
From: K Prateek Nayak @ 2026-11-30 8:24 UTC (permalink / raw)
To: Vishal Badole, ray.huang, mario.limonciello, rafael, viresh.kumar,
perry.yuan, hansg, ilpo.jarvinen, platform-driver-x86, linux-pm,
linux-kernel
Hello Vishal,
On 11/25/2026 10:50 PM, Vishal Badole wrote:
> +bool amd_pstate_cas_active(void)
> +{
> + return READ_ONCE(amd_pstate_cas_initialized);
> +}
> +EXPORT_SYMBOL_GPL(amd_pstate_cas_active);
> +
> +static void __init amd_pstate_init_cas(void)
> +{
> + int ref_highest_perf = 0, ref_max_freq = 0;
> + int cpu, highest_perf, max_freq;
> +
> + if (!amd_pstate_cas)
> + return;
> +
> + amd_pstate_cas = false;
> + if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
> + return;
> +
> + for_each_online_cpu(cpu) {
> + highest_perf = amd_get_effective_highest_perf(cpu);
> + if (highest_perf <= 0) {
> + pr_warn("Invalid highest performance (%d) on CPU%d\n",
> + highest_perf, cpu);
> + return;
> + }
> +
> + max_freq = amd_get_max_frequency(cpu);
> + if (max_freq < 0 || (u32)max_freq > U32_MAX / 1000) {
> + pr_warn("Invalid maximum frequency (%d) on CPU%d\n",
> + max_freq, cpu);
> + return;
> + }
> +
> + if (highest_perf < ref_highest_perf ||
> + (highest_perf == ref_highest_perf && max_freq <= ref_max_freq))
So I don't get the second part of this condition. There can be CPUs with
same highest_perf bit different max_freq?
Say you have:
Performance Core : max_perf = 196; max_freq = 3000000KHz
Efficiency Core : max_perf = 196; max_freq = 2000000KHz
(Hypothetical numbers)
In this case, you'll have:
amd_pstate_ref_highest_perf = 196
amd_pstate_ref_freq_khz = 30000000KHz
Continued below ...
> + continue;
> +
> + ref_highest_perf = highest_perf;
> + ref_max_freq = max_freq;
> + }
> +
> + if (!ref_highest_perf) {
> + pr_warn("No reference CPU available for capacity scaling\n");
> + return;
> + }
> +
> + amd_pstate_ref_highest_perf = ref_highest_perf;
> + amd_pstate_ref_freq_khz = ref_max_freq * 1000U;
> +
> + amd_pstate_cas = arch_enable_hybrid_capacity_scale();
> +}
> +
> +static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data,
> + bool highest_freq_available)
> +{
> + unsigned long capacity, max_capacity, capacity_freq, base_freq;
> + int cpu = data->cpu;
> +
> + lockdep_assert_held(&sched_domains_mutex);
> +
> + if (highest_freq_available && amd_pstate_ref_freq_khz) {
> + capacity = data->max_freq;
> + max_capacity = amd_pstate_ref_freq_khz;
> + capacity_freq = capacity;
> + base_freq = max_capacity;
> + } else {
> + union perf_cached perf = READ_ONCE(data->perf);
> +
> + capacity = perf.highest_perf;
> + max_capacity = amd_pstate_ref_highest_perf;
> + capacity_freq = perf_to_freq(perf, data->nominal_freq, perf.highest_perf);
So this is literally "data->max_freq"
> + base_freq = perf_to_freq(perf, data->nominal_freq, max_capacity);
And this would likely be equal to "amd_pstate_ref_freq_khz"
> + }
Making both those branch pretty much the same. Why isn't just the
frequency reference enough?
> +
> + arch_set_cpu_capacity(cpu, capacity, max_capacity, capacity_freq, base_freq);
...
And that means they'll have same capacity, but different frequency scale.
That reads a bit wrong to me. Different frequency scale will help cap the
PELT tracking but the CPUs themself will appear as same capacity which
would do the wrong thing.
What do these highest_perf numbers look like on real hardware btw?
> + topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu));
> +}
> +
> +static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata,
> + bool highest_freq_available)
> +{
> + union perf_cached perf = READ_ONCE(cpudata->perf);
> + int cpu;
> +
> + lockdep_assert_cpus_held();
> +
> + guard(mutex)(&sched_domains_mutex);
> +
> + if (perf.highest_perf > amd_pstate_ref_highest_perf) {
Btw there is other side to this where all CPUs of the highest
capacity are offlined and you'll need to recaliberate the
reference again if you have efficiency and low-power cores.
> + amd_pstate_ref_highest_perf = perf.highest_perf;
> + amd_pstate_ref_freq_khz = highest_freq_available ? cpudata->max_freq : 0;
> +
> + for_each_possible_cpu(cpu) {
> + struct cpufreq_policy *policy;
> +
> + if (cpu == cpudata->cpu)
> + continue;
> +
> + policy = cpufreq_cpu_policy(cpu);
> + if (policy && policy->driver_data)
> + amd_pstate_update_cpu_capacity(policy->driver_data,
> + amd_pstate_ref_freq_khz &&
> + amd_get_max_frequency(cpu) > 0);
This is the most convoluted condition ^^^^
If this CPU has "highest_freq_available", doesn't that mean all the CPUs
in this system have "highest_freq_available"?
> + }
> + }
> +
> + amd_pstate_update_cpu_capacity(cpudata, highest_freq_available);
> + x86_topology_update = true;
I think this really calls for an arch side helper rather seting it
openly here. That should get rid of that CONFIG_SMP checks everywhere.
> + WRITE_ONCE(amd_pstate_cas_initialized, true);
> +}
> +
> static void amd_pstate_update_limits(struct cpufreq_policy *policy)
> {
> struct amd_cpudata *cpudata;
--
Thanks and Regards,
Prateek
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
@ 2026-11-30 15:38 ` Mario Limonciello
0 siblings, 0 replies; 8+ messages in thread
From: Mario Limonciello @ 2026-11-30 15:38 UTC (permalink / raw)
To: Vishal Badole
Cc: ray.huang, rafael, viresh.kumar, perry.yuan, kprateek.nayak,
hansg, ilpo.jarvinen, platform-driver-x86, linux-pm, linux-kernel
On 11/25/26 11:20, Vishal Badole wrote:
> The choice between amd-hfi and preferred-core scheduling applies to the
> whole system. However, the HFI check currently runs during per-CPU
> initialization and clears the global amd_pstate_prefcore flag.
>
> Move the check to amd_pstate_init(), after preferred-core detection and
> before driver registration.
>
> Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/cpufreq/amd-pstate.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 4bedfbfc18b66..3e0308f644778 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -956,13 +956,6 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
> if (!amd_pstate_prefcore)
> return;
>
> - /* should use amd-hfi instead */
> - if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
> - IS_ENABLED(CONFIG_AMD_HFI)) {
> - amd_pstate_prefcore = false;
> - return;
> - }
> -
> cpudata->hw_prefcore = true;
>
> /* Priorities must be initialized before ITMT support can be toggled on. */
> @@ -2438,6 +2431,10 @@ static int __init amd_pstate_init(void)
> return ret;
> }
>
> + if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
> + IS_ENABLED(CONFIG_AMD_HFI))
> + amd_pstate_prefcore = false;
> +
> ret = amd_pstate_register_driver(cppc_state);
> if (ret) {
> pr_err("failed to register with return %d\n", ret);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
2026-11-25 17:20 ` [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole
@ 2026-11-30 15:39 ` Mario Limonciello
0 siblings, 0 replies; 8+ messages in thread
From: Mario Limonciello @ 2026-11-30 15:39 UTC (permalink / raw)
To: Vishal Badole, Krishnamoorthi M
Cc: ray.huang, rafael, viresh.kumar, perry.yuan, kprateek.nayak,
hansg, ilpo.jarvinen, platform-driver-x86, linux-pm, linux-kernel
On 11/25/26 11:20, Vishal Badole wrote:
> From: Krishnamoorthi M <krishnamoorthi.m@amd.com>
>
> When amd-pstate CAS is active, it takes ownership of per-CPU capacity
> values that the scheduler uses to distinguish performance and efficiency
> cores. amd-hfi manages the same scheduler state through its ranking
> mechanism. Running both simultaneously would cause them to overwrite
> each other's settings, leading to unpredictable task placement on hybrid
> platforms.
>
> Avoid loading amd-hfi if CAS is enabled. Defer HFI driver initialization
> to a late initcall so amd-pstate completes initialization before HFI
> checks whether CAS is active.
>
> Signed-off-by: Krishnamoorthi M <krishnamoorthi.m@amd.com>
> Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index 86a7f4332c35a..73e53203a838c 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -27,6 +27,7 @@
> #include <linux/topology.h>
> #include <linux/workqueue.h>
>
> +#include <asm/amd/amd-pstate.h>
> #include <asm/cpu_device_id.h>
>
> #include <acpi/pcc.h>
> @@ -536,6 +537,12 @@ static int __init amd_hfi_init(void)
> !cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
> return -ENODEV;
>
> + /* amd-pstate CAS owns heterogeneous core scheduling when enabled. */
> + if (amd_pstate_cas_active()) {
> + pr_debug("amd-pstate CAS is active, not loading amd-hfi\n");
> + return -ENODEV;
> + }
> +
> ret = platform_driver_register(&amd_hfi_driver);
> if (ret)
> pr_err("failed to register HFI driver\n");
> @@ -547,7 +554,7 @@ static __exit void amd_hfi_exit(void)
> {
> platform_driver_unregister(&amd_hfi_driver);
> }
> -module_init(amd_hfi_init);
> +late_initcall(amd_hfi_init);
> module_exit(amd_hfi_exit);
>
> MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
2026-11-30 8:24 ` K Prateek Nayak
@ 2026-11-30 15:40 ` Mario Limonciello
0 siblings, 0 replies; 8+ messages in thread
From: Mario Limonciello @ 2026-11-30 15:40 UTC (permalink / raw)
To: K Prateek Nayak, Vishal Badole, ray.huang, rafael, viresh.kumar,
perry.yuan, hansg, ilpo.jarvinen, platform-driver-x86, linux-pm,
linux-kernel
On 11/30/26 02:24, K Prateek Nayak wrote:
> Hello Vishal,
>
> On 11/25/2026 10:50 PM, Vishal Badole wrote:
>> +bool amd_pstate_cas_active(void)
>> +{
>> + return READ_ONCE(amd_pstate_cas_initialized);
>> +}
>> +EXPORT_SYMBOL_GPL(amd_pstate_cas_active);
>> +
>> +static void __init amd_pstate_init_cas(void)
>> +{
>> + int ref_highest_perf = 0, ref_max_freq = 0;
>> + int cpu, highest_perf, max_freq;
>> +
>> + if (!amd_pstate_cas)
>> + return;
>> +
>> + amd_pstate_cas = false;
>> + if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
>> + return;
>> +
>> + for_each_online_cpu(cpu) {
>> + highest_perf = amd_get_effective_highest_perf(cpu);
>> + if (highest_perf <= 0) {
>> + pr_warn("Invalid highest performance (%d) on CPU%d\n",
>> + highest_perf, cpu);
>> + return;
>> + }
>> +
>> + max_freq = amd_get_max_frequency(cpu);
>> + if (max_freq < 0 || (u32)max_freq > U32_MAX / 1000) {
>> + pr_warn("Invalid maximum frequency (%d) on CPU%d\n",
>> + max_freq, cpu);
>> + return;
>> + }
>> +
>> + if (highest_perf < ref_highest_perf ||
>> + (highest_perf == ref_highest_perf && max_freq <= ref_max_freq))
>
> So I don't get the second part of this condition. There can be CPUs with
> same highest_perf bit different max_freq?
>
> Say you have:
>
> Performance Core : max_perf = 196; max_freq = 3000000KHz
> Efficiency Core : max_perf = 196; max_freq = 2000000KHz
>
> (Hypothetical numbers)
>
> In this case, you'll have:
>
> amd_pstate_ref_highest_perf = 196
> amd_pstate_ref_freq_khz = 30000000KHz
>
> Continued below ...
I don't think this combination is real.
>
>> + continue;
>> +
>> + ref_highest_perf = highest_perf;
>> + ref_max_freq = max_freq;
>> + }
>> +
>> + if (!ref_highest_perf) {
>> + pr_warn("No reference CPU available for capacity scaling\n");
>> + return;
>> + }
>> +
>> + amd_pstate_ref_highest_perf = ref_highest_perf;
>> + amd_pstate_ref_freq_khz = ref_max_freq * 1000U;
>> +
>> + amd_pstate_cas = arch_enable_hybrid_capacity_scale();
>> +}
>> +
>> +static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data,
>> + bool highest_freq_available)
>> +{
>> + unsigned long capacity, max_capacity, capacity_freq, base_freq;
>> + int cpu = data->cpu;
>> +
>> + lockdep_assert_held(&sched_domains_mutex);
>> +
>> + if (highest_freq_available && amd_pstate_ref_freq_khz) {
>> + capacity = data->max_freq;
>> + max_capacity = amd_pstate_ref_freq_khz;
>> + capacity_freq = capacity;
>> + base_freq = max_capacity;
>> + } else {
>> + union perf_cached perf = READ_ONCE(data->perf);
>> +
>> + capacity = perf.highest_perf;
>> + max_capacity = amd_pstate_ref_highest_perf;
>> + capacity_freq = perf_to_freq(perf, data->nominal_freq, perf.highest_perf);
>
> So this is literally "data->max_freq"
>
>> + base_freq = perf_to_freq(perf, data->nominal_freq, max_capacity);
>
> And this would likely be equal to "amd_pstate_ref_freq_khz"
>
>> + }
>
> Making both those branch pretty much the same. Why isn't just the
> frequency reference enough?
>
>> +
>> + arch_set_cpu_capacity(cpu, capacity, max_capacity, capacity_freq, base_freq);
>
> ...
>
> And that means they'll have same capacity, but different frequency scale.
> That reads a bit wrong to me. Different frequency scale will help cap the
> PELT tracking but the CPUs themself will appear as same capacity which
> would do the wrong thing.
>
> What do these highest_perf numbers look like on real hardware btw?
>
>> + topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu));
>> +}
>> +
>> +static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata,
>> + bool highest_freq_available)
>> +{
>> + union perf_cached perf = READ_ONCE(cpudata->perf);
>> + int cpu;
>> +
>> + lockdep_assert_cpus_held();
>> +
>> + guard(mutex)(&sched_domains_mutex);
>> +
>> + if (perf.highest_perf > amd_pstate_ref_highest_perf) {
>
> Btw there is other side to this where all CPUs of the highest
> capacity are offlined and you'll need to recaliberate the
> reference again if you have efficiency and low-power cores.
>
>> + amd_pstate_ref_highest_perf = perf.highest_perf;
>> + amd_pstate_ref_freq_khz = highest_freq_available ? cpudata->max_freq : 0;
>> +
>> + for_each_possible_cpu(cpu) {
>> + struct cpufreq_policy *policy;
>> +
>> + if (cpu == cpudata->cpu)
>> + continue;
>> +
>> + policy = cpufreq_cpu_policy(cpu);
>> + if (policy && policy->driver_data)
>> + amd_pstate_update_cpu_capacity(policy->driver_data,
>> + amd_pstate_ref_freq_khz &&
>> + amd_get_max_frequency(cpu) > 0);
>
> This is the most convoluted condition ^^^^
>
> If this CPU has "highest_freq_available", doesn't that mean all the CPUs
> in this system have "highest_freq_available"?
>
>> + }
>> + }
>> +
>> + amd_pstate_update_cpu_capacity(cpudata, highest_freq_available);
>> + x86_topology_update = true;
>
> I think this really calls for an arch side helper rather seting it
> openly here. That should get rid of that CONFIG_SMP checks everywhere.
>
>> + WRITE_ONCE(amd_pstate_cas_initialized, true);
>> +}
>> +
>> static void amd_pstate_update_limits(struct cpufreq_policy *policy)
>> {
>> struct amd_cpudata *cpudata;
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-30 15:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 17:20 [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms Vishal Badole
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
2026-11-30 15:38 ` Mario Limonciello
2026-11-25 17:20 ` [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
2026-11-30 8:24 ` K Prateek Nayak
2026-11-30 15:40 ` Mario Limonciello
2026-11-25 17:20 ` [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole
2026-11-30 15:39 ` Mario Limonciello
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox