cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms
Subsystems (5)
cover cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms
This series enables Capacity Aware Scheduling (CAS) for AMD heterogeneous processors that combine performance and efficiency cores.
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 makes amd-pstate publish asymmetric per-CPU capacities via the arch hybrid capacity scaling interface. It is enabled by default on supported hardware and can be turned off with the "amd_cas=disable" boot parameter.
Patch 2 makes amd-hfi stand down when CAS is active, since both manage the same scheduler state.
Krishnamoorthi M (1):
platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
Vishal Badole (1):
cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
MAINTAINERS | 1 + drivers/cpufreq/amd-pstate.c | 102 ++++++++++++++++++++++++++++- drivers/platform/x86/amd/hfi/hfi.c | 8 +++ include/linux/amd-pstate.h | 14 ++++ 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 include/linux/amd-pstate.h
Signature · 1 line
2.34.1
PATCH 1/2 cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
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 on AMD heterogeneous-core processors. Use CPU 0 as the capacity reference, assuming it is a highest-performance CPU on the supported platforms. Cache its maximum frequency in kHz and effective highest performance once before driver registration, treating these reference capabilities as fixed for the lifetime of the system. During per-CPU initialization, compute each CPU's capacity relative to the cached reference and publish it:
- When maximum-frequency data is available for both CPUs, scale by frequency via arch_set_cpu_capacity().
- Otherwise, fall back to performance-register based scaling using the effective highest_perf values.
Record frequency availability before applying the per-CPU fallback. Keep frequency and performance references separate instead of interpreting a boost-ratio numerator in performance units as MHz. The fallback base frequency still depends on each CPU's nominal frequency and performance, so calculate that conversion per CPU. Disable CAS if reference setup fails without preventing 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 + drivers/cpufreq/amd-pstate.c | 102 ++++++++++++++++++++++++++++++++++- include/linux/amd-pstate.h | 14 +++++ 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 include/linux/amd-pstate.h
MAINTAINERS +1 -0
@@ -1324,6 +1324,7 @@ L: [email protected] S: Supported F: Documentation/admin-guide/pm/amd-pstate.rst F: drivers/cpufreq/amd-pstate* +F: include/linux/amd-pstate.h F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py AMD PTDMA DRIVER
drivers/cpufreq/amd-pstate.c +100 -2
182 lines not on this page · raw message
include/linux/amd-pstate.h new file +14 -0
@@ -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__ */
Signature · 1 line
2.34.1
Mario Limonciello
maintainerRe: [PATCH 1/2] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
Quoted 85 lines · 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_SCALEwhen 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 on AMD heterogeneous-core processors. Use CPU 0 as the capacity reference, assuming it is a highest-performance CPU on the supported platforms. Cache its maximum frequency in kHz and effective highest performance once before driver registration, treating these reference capabilities as fixed for the lifetime of the system. During per-CPU initialization, compute each CPU's capacity relative to the cached reference and publish it:
- When maximum-frequency data is available for both CPUs, scale by frequency via
arch_set_cpu_capacity().
- Otherwise, fall back to performance-register based scaling using the effectivehighest_perfvalues.Record frequency availability before applying the per-CPU fallback. Keep frequency and performance references separate instead of interpreting a boost-ratio numerator in performance units as MHz. The fallback base frequency still depends on each CPU's nominal frequency and performance, so calculate that conversion per CPU. Disable CAS if reference setup fails without preventing 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 <[email protected]>--- MAINTAINERS | 1 + drivers/cpufreq/amd-pstate.c | 102 ++++++++++++++++++++++++++++++++++- include/linux/amd-pstate.h | 14 +++++ 3 files changed, 115 insertions(+), 2 deletions(-)create mode 100644
include/linux/amd-pstate.hMAINTAINERS +1
-0@@ -1324,6 +1324,7 @@ L: [email protected] S: Supported F: Documentation/admin-guide/pm/amd-pstate.rst F: drivers/cpufreq/amd-pstate* +F: include/linux/amd-pstate.h F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py AMD PTDMA DRIVERdrivers/cpufreq/amd-pstate.c +3
-0@@ -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>
drivers/cpufreq/amd-pstate.c static struct cpufreq_driver amd_pstate_driver; · line 92
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +1
-0@@ -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;
As this strictly requires SMP support, what do you think about this instead to pick the default.
static bool amd_pstate_cas = IS_ENABLED(CONFIG_SMP);
Quoted 46 lines
drivers/cpufreq/amd-pstate.c +30
-2+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) { 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); + +static bool __init amd_pstate_init_cas (void ) +{ +int highest_perf, max_freq; + + highest_perf =amd_get_effective_highest_perf (0 ); +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 ; +
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1013
Quoted 10 lines
drivers/cpufreq/amd-pstate.c +10
-0+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 ;
From what I can tell; I don't think this is realistically something that can get called since you already check to enable CAS based on this same check (IS_ENABLED(CONFIG_SMP)).
So please drop this check here. More later about IS_ENABLED(CONFIG_SMP).
Quoted 74 lines
drivers/cpufreq/amd-pstate.c +36
-0+ +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; + 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); +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 };
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2525
Quoted 10 lines
drivers/cpufreq/amd-pstate.c +7
-0@@ -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 (); +
This seem to be a pointless variable initialization, especially as it's a global variable and this runs on non-hetero systems too. Maybe something like this:
0) See my previous comment about where to use IS_ENABLED(CONFIG_SMP).
1) Change amd_pstate_init_cas return type to void.
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2526
Quoted 1 line
drivers/cpufreq/amd-pstate.c +1
-0+static void __init amd_pstate_init_cas (void )
2) Add checks into the function like this:
static void __init amd_pstate_init_cas(void) {
if (!amd_pstate_cas)
return;
if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
return;
.
.
.
amd_pstate_cas = arch_enable_hybrid_capacity_scale();}
3) Change the call in this function to just:amd_pstate_init_cas();
That should help avoid some extra variable writes.
Quoted 51 lines
drivers/cpufreq/amd-pstate.c +13
-0ret =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 (); + 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 <[email protected]>" );MODULE_DESCRIPTION ("AMD Processor P-state Frequency Driver" );include/linux/amd-pstate.h new file +14
-0@@ -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__ */
Re: [PATCH 1/2] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
Hello Mari,
Thanks for reiviewing this patch.
Quoted 93 lines · Mario Limonciello
Quoted 83 lines · 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_SCALEwhen 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 on AMD heterogeneous-core processors. Use CPU 0 as the capacity reference, assuming it is a highest-performance CPU on the supported platforms. Cache its maximum frequency in kHz and effective highest performance once before driver registration, treating these reference capabilities as fixed for the lifetime of the system. During per-CPU initialization, compute each CPU's capacity relative to the cached reference and publish it:
- When maximum-frequency data is available for both CPUs, scale by frequency via
arch_set_cpu_capacity().
- Otherwise, fall back to performance-register based scaling using the effectivehighest_perfvalues.Record frequency availability before applying the per-CPU fallback. Keep frequency and performance references separate instead of interpreting a boost-ratio numerator in performance units as MHz. The fallback base frequency still depends on each CPU's nominal frequency and performance, so calculate that conversion per CPU. Disable CAS if reference setup fails without preventing 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 <[email protected]>---
MAINTAINERS | 1 +drivers/cpufreq/amd-pstate.c| 102 ++++++++++++++++++++++++++++++++++- include/linux/amd-pstate.h | 14 +++++3 files changed, 115 insertions(+), 2 deletions(-)create mode 100644
include/linux/amd-pstate.hMAINTAINERS +0
-0@@ -1324,6 +1324,7 @@ L: [email protected]S: Supported
F:Documentation/admin-guide/pm/amd-pstate.rstF:drivers/cpufreq/amd-pstate*
+F:include/linux/amd-pstate.h
F:tools/power/x86/amd_pstate_tracer/amd_pstate_trace.pyAMD PTDMA DRIVERdrivers/cpufreq/amd-pstate.c +3
-0@@ -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>drivers/cpufreq/amd-pstate.c static struct cpufreq_driver amd_pstate_driver; · line 92
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +1
-0@@ -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;As this strictly requires SMP support, what do you think about this instead to pick the default.
Quoted 2 lines
static bool
amd_pstate_cas=IS_ENABLED(CONFIG_SMP);
Ack!
Quoted 61 lines
Quoted 47 lines
drivers/cpufreq/amd-pstate.c +5
-2+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) { 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-
Quoted 1 line
prefcore_ranking),cpudata->cpu);}
drivers/cpufreq/amd-pstate.c +13
-0+bool amd_pstate_cas_active (void ) +{ + return READ_ONCE(amd_pstate_cas_initialized); +} +EXPORT_SYMBOL_GPL (amd_pstate_cas_active); + +static bool __init amd_pstate_init_cas (void ) +{ + int highest_perf, max_freq; + + highest_perf = amd_get_effective_highest_perf(0); + if (highest_perf <= 0) { + pr_warn("Invalid reference highest performance (%d)\n",
highest_perf);
+ return false;
+ }drivers/cpufreq/amd-pstate.c +10
-0+ + 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; +drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1013
Quoted 10 lines
drivers/cpufreq/amd-pstate.c +10
-0+ 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;From what I can tell; I don't think this is realistically something
that can get called since you already check to enable CAS based on this same check (IS_ENABLED(CONFIG_SMP)).
Quoted 2 lines
So please drop this check here. More later about
IS_ENABLED(CONFIG_SMP).
Sure, I will update it in the next patch revision.
Quoted 104 lines
Quoted 74 lines
drivers/cpufreq/amd-pstate.c +12
-0+ + 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; + 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);
+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);drivers/cpufreq/amd-pstate.c +2
-0+} +static void
amd_pstate_update_limits(struct cpufreq_policy *policy){
structamd_cpudata*cpudata;drivers/cpufreq/amd-pstate.c +13
-0@@ -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
};drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2524
Quoted 9 lines
drivers/cpufreq/amd-pstate.c +7
-0@@ -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(); +This seem to be a pointless variable initialization, especially as it's a global variable and this runs on non-hetero systems too. Maybe something like this:
0) See my previous comment about where to use
IS_ENABLED(CONFIG_SMP).1) Change
amd_pstate_init_casreturn type to void.drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2525
Quoted 1 line
drivers/cpufreq/amd-pstate.c +1
-0+static void __init amd_pstate_init_cas (void )2) Add checks into the function like this:
static void
__initamd_pstate_init_cas(void){
if (!amd_pstate_cas)
return;
if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES)) return;
.
.
.
amd_pstate_cas =arch_enable_hybrid_capacity_scale();
Quoted 5 lines
}
3) Change the call in this function to just:
amd_pstate_init_cas();
Sure, I will include these changes in patch revision.
Quoted 52 lines
That should help avoid some extra variable writes.
Quoted 49 lines
drivers/cpufreq/amd-pstate.c +1
-0ret = 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; rebuilddomains 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);drivers/cpufreq/amd-pstate.c +9
-0@@ -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 <[email protected]>"); MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver");include/linux/amd-pstate.h new file +14
-0@@ -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__ */
K Prateek Nayak
reviewerRe: [PATCH 1/2] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
In reply to Vishal BadoleHello Vishal,
Quoted 33 lines · Vishal Badole
drivers/cpufreq/amd-pstate.c +7
-0@@ -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;/*
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 968
Quoted 7 lines
drivers/cpufreq/amd-pstate.c +2
-2@@ -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:
arch/x86/include/asm/amd/hfi.h new file +27 -0
@@ -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__ */
---
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 983
Quoted 12 lines
drivers/cpufreq/amd-pstate.c +5
-0amd_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.
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 989
Quoted 6 lines
drivers/cpufreq/amd-pstate.c +6
-0+ +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.
Quoted 14 lines
drivers/cpufreq/amd-pstate.c +14
-0+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 ; +
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1013
Quoted 10 lines
drivers/cpufreq/amd-pstate.c +10
-0+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?
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1024
Quoted 11 lines
drivers/cpufreq/amd-pstate.c +11
-0+ +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.
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1029
Quoted 5 lines
drivers/cpufreq/amd-pstate.c +5
-0+ 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.
Quoted 58 lines
drivers/cpufreq/amd-pstate.c +20
-0+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 };
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2524
Quoted 9 lines
drivers/cpufreq/amd-pstate.c +6
-0@@ -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()?
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2535
Quoted 11 lines
drivers/cpufreq/amd-pstate.c +5
-0+ 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)
include/linux/amd-pstate.h
Quoted 22 lines
drivers/cpufreq/amd-pstate.c +9
-0dev_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 <[email protected]>" );MODULE_DESCRIPTION ("AMD Processor P-state Frequency Driver" );include/linux/amd-pstate.h +0
-0
Why not arch/x86/include/asm/amd/amd-pstate.h since all of this is AMd related?
Quoted 19 lines
new file mode 100644
index 000000000000..eb750abd20f7include/linux/amd-pstate.h new file +14
-0@@ -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__ */
Signature · 2 lines
Thanks and Regards, Prateek
Re: [PATCH 1/2] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
Hello Prateek,
Thanks for reviewing this patch.
Quoted 76 lines · K Prateek Nayak
Hello Vishal,
Quoted 33 lines · Vishal Badole
drivers/cpufreq/amd-pstate.c +7
-0@@ -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;/* drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 968
Quoted 7 lines
drivers/cpufreq/amd-pstate.c +2
-2@@ -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:
arch/x86/include/asm/amd/hfi.h new file +18
-0@@ -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 ; +
arch/x86/include/asm/amd/hfi.h
Quoted 10 lines
arch/x86/include/asm/amd/hfi.h new file +9
-1+ 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__ */ ---
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.
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.
Quoted 26 lines
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 983
Quoted 12 lines
drivers/cpufreq/amd-pstate.c +5
-0amd_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.drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 989
Quoted 6 lines
drivers/cpufreq/amd-pstate.c +6
-0+ +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?
Quoted 4 lines
I think we can tak a page from how
intel_pstatedoes ahybrid_set_cpu_capacity()which iterates all online CPUs after driver registration / if onlining changes thehybrid_max_perf_cpu.
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.
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.
Quoted 18 lines
Quoted 18 lines
drivers/cpufreq/amd-pstate.c +18
-0+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,
Quoted 9 lines
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1013
Quoted 6 lines
drivers/cpufreq/amd-pstate.c +6
-0+ bool highest_freq_available) +{ +unsigned long capacity, max_capacity, capacity_freq, base_freq; + +if (!IS_ENABLED (CONFIG_SMP )) +return ;What is the
CONFIG_SMPdependnecy for?
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.
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'
Quoted 7 lines
Quoted 7 lines
drivers/cpufreq/amd-pstate.c +7
-0+ +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 {
Quoted 9 lines
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1024
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +4
-0+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_perfand not need two seperate global variables.
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.
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.
Quoted 9 lines
drivers/cpufreq/amd-pstate.c static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) · line 1029
Quoted 5 lines
drivers/cpufreq/amd-pstate.c +5
-0+ 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 settingx86_topology_updateat the wrong time.
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.
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.
Quoted 61 lines
Quoted 61 lines
drivers/cpufreq/amd-pstate.c +20
-0+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; }
Quoted 10 lines
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2524
Quoted 6 lines
drivers/cpufreq/amd-pstate.c +6
-0+ 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()?
Ack. Mario also suggested this, along with a few additional changes. I’ll incorporate them in the next revision of the patch.
Quoted 7 lines
Quoted 7 lines
drivers/cpufreq/amd-pstate.c +1
-0+ ret =amd_pstate_register_driver (cppc_state);if (ret) {pr_err ("failed to register with return %d\n" , ret);return ret; }
Quoted 9 lines
drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 2535
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +4
-0+/* 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)
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.
Quoted 19 lines
Quoted 19 lines
drivers/cpufreq/amd-pstate.c +9
-0dev_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);
Quoted 7 lines
include/linux/amd-pstate.h
Quoted 3 lines
drivers/cpufreq/amd-pstate.c +0
-0MODULE_AUTHOR ("Huang Rui <[email protected]>" );MODULE_DESCRIPTION ("AMD Processor P-state Frequency Driver" );include/linux/amd-pstate.h +0
-0Why not
arch/x86/include/asm/amd/amd-pstate.hsince all of this is AMd related?
Ack!
Quoted 20 lines
Quoted 19 lines
new file mode 100644
index 000000000000..eb750abd20f7include/linux/amd-pstate.h new file +14
-0@@ -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__ */
PATCH 2/2 platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
In reply to Vishal BadoleFrom: 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.
--- drivers/platform/x86/amd/hfi/hfi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/platform/x86/amd/hfi/hfi.c +8 -0
@@ -29,6 +29,8 @@#include <asm/cpu_device_id.h> +#include <linux/amd-pstate.h> +#include <acpi/pcc.h> #include <acpi/cppc_acpi.h>
@@ -536,6 +538,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" );
Signature · 1 line
2.34.1
Mario Limonciello
maintainerRe: [PATCH 2/2] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
Quoted 9 lines · 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.
Quoted 3 lines
Avoid loading amd-hfi if CAS is enabled.
Signed-off-by Krishnamoorthi M <[email protected]>
When a patch is authored by another person and you send it on their behalf you need to add your own S-o-b as well.
Think of it like a chain of custody.
Quoted 30 lines
--- drivers/platform/x86/amd/hfi/hfi.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/platform/x86/amd/hfi/hfi.c +8
-0@@ -29,6 +29,8 @@#include <asm/cpu_device_id.h> +#include <linux/amd-pstate.h> +#include <acpi/pcc.h> #include <acpi/cppc_acpi.h> @@ -536,6 +538,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" );
Mario Limonciello
maintainerRe: [PATCH 2/2] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
Quoted 36 lines · Mario Limonciello
Quoted 9 lines · 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.
Quoted 3 lines
Avoid loading amd-hfi if CAS is enabled.
Signed-off-by Krishnamoorthi M <[email protected]>When a patch is authored by another person and you send it on their behalf you need to add your own S-o-b as well.
Think of it like a chain of custody.
Quoted 16 lines
---
drivers/platform/x86/amd/hfi/hfi.c| 8 ++++++++1 file changed, 8 insertions(+)drivers/platform/x86/amd/hfi/hfi.c +2
-0@@ -29,6 +29,8 @@ #include <asm/cpu_device_id.h> +#include <linux/amd-pstate.h> + #include <acpi/pcc.h> #include <acpi/cppc_acpi.h>@@ -536,6 +538,12 @@ static int __init amd_hfi_init(void) !cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
Quoted 8 lines
Quoted 8 lines
drivers/platform/x86/amd/hfi/hfi.c +1
-0return -ENODEV; + /* amd-pstate CAS owns heterogeneous core scheduling whenenabled. */
+ if (amd_pstate_cas_active()) {
+pr_debug("amd-pstate CAS is active, not loading amd-hfi\n"); + return-ENODEV;
+ }
+
The load order happens to work; but AFAICT this is just by coincidence (link order).
If the link order was changed in the future this could break completely non-obviously.
I think it would be most ideal to add deferred probing support or forcing HFI into a later init call phase.
Quoted 4 lines
Quoted 3 lines
ret =
platform_driver_register(&amd_hfi_driver); if (ret)
pr_err("failed to register HFI driver\n");
Re: [PATCH 2/2] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
Quoted 50 lines · Mario Limonciello
Quoted 36 lines · Mario Limonciello
Quoted 9 lines · 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.
Quoted 3 lines
Avoid loading amd-hfi if CAS is enabled.
Signed-off-by Krishnamoorthi M <[email protected]>When a patch is authored by another person and you send it on their behalf you need to add your own S-o-b as well.
Think of it like a chain of custody.
Quoted 16 lines
---
drivers/platform/x86/amd/hfi/hfi.c| 8 ++++++++1 file changed, 8 insertions(+)drivers/platform/x86/amd/hfi/hfi.c +2
-0@@ -29,6 +29,8 @@ #include <asm/cpu_device_id.h> +#include <linux/amd-pstate.h> + #include <acpi/pcc.h> #include <acpi/cppc_acpi.h>@@ -536,6 +538,12 @@ static int __init amd_hfi_init(void) !cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))Quoted 8 lines
Quoted 8 lines
drivers/platform/x86/amd/hfi/hfi.c +1
-0return -ENODEV; + /* amd-pstate CAS owns heterogeneous core scheduling whenenabled. */
+ if (amd_pstate_cas_active()) {
+pr_debug("amd-pstate CAS is active, not loading amd-hfi\n"); + return-ENODEV;
+ }
+The load order happens to work; but AFAICT this is just by coincidence (link order).
Quoted 4 lines
If the link order was changed in the future this could break completely non-obviously.
I think it would be most ideal to add deferred probing support or forcing HFI into a later init call phase.
Ack! I will add required changes to deffer the HFI driver probing.
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
ret =
platform_driver_register(&amd_hfi_driver); if (ret)
pr_err("failed to register HFI driver\n");
Re: [PATCH 2/2] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active
In reply to Mario LimoncielloQuoted 12 lines · Mario Limonciello
Quoted 9 lines · 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.
Quoted 8 lines
Quoted 3 lines
Avoid loading amd-hfi if CAS is enabled.
Signed-off-by Krishnamoorthi M <[email protected]>When a patch is authored by another person and you send it on their behalf you need to add your own S-o-b as well.
Think of it like a chain of custody.
Ack! Thanks for Pointing this.
Quoted 28 lines
Quoted 27 lines
---
drivers/platform/x86/amd/hfi/hfi.c| 8 ++++++++1 file changed, 8 insertions(+)drivers/platform/x86/amd/hfi/hfi.c +3
-0@@ -29,6 +29,8 @@ #include <asm/cpu_device_id.h> +#include <linux/amd-pstate.h> + #include <acpi/pcc.h> #include <acpi/cppc_acpi.h>@@ -536,6 +538,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 whenenabled. */
+ 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");