Skip to contentSkip to conversation

cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms

PATCH New Vishal Badole 1 participant 4 messages Nov 25

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms

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/[email protected]/

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
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 cpufreq: amd-pstate: Finalize prefcore before registration

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.

---
 drivers/cpufreq/amd-pstate.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -7
index 4bedfbfc18b66..3e0308f644778 100644
@@ -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);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms

In reply to 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.

---
 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
MAINTAINERS +1 -0
index 44540a1eb2b80..300dce181c1c4 100644
@@ -1322,6 +1322,7 @@ R:	K Prateek Nayak <[email protected]>
 L:	[email protected]
 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
 
arch/x86/include/asm/amd/amd-pstate.h new file +16 -0
new file mode 100644
index 0000000000000..1c0eb56c8f867
@@ -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_ */
arch/x86/kernel/acpi/cppc.c +2 -2
index 1c6bf56c3215b..15590e9da2dca 100644
@@ -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;
 
 	/*
drivers/cpufreq/amd-pstate.c +148 -2

228 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 platform/x86/amd: hfi: Stand down when amd-pstate CAS is active

In reply to Vishal Badole

From: Krishnamoorthi M <[email protected]>

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.

---
 drivers/platform/x86/amd/hfi/hfi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/hfi/hfi.c +8 -1
index 86a7f4332c35a..73e53203a838c 100644
@@ -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");
Signature · 1 line
2.34.1