Zen6 client CPPC
Subsystems (6)
v3 cover Zen6 client CPPC
From: Mario Limonciello <[email protected]>
Zen6 client platforms use CPPC differently than previous platforms and knowing maximum frequency for a core type is needed for capacity calculations.
Newer versions of the ACPI will introduce a proper interface for getting this information, but for now hardcode values so that these systems perform as intended and to unblock future scheduler work while we continue to wait.
v3:
* rebase on linux-pm/bleeding-edge to pick up "ACPI: CPPC: Fix register access and lifetime bugs"
v2:
Mario Limonciello (3):
ACPI: CPPC: Refactor boost ratio handling
cpufreq/acpi-cpufreq: Use amd_get_boost_ratio()
cpufreq/amd-pstate: Get Highest Freq for a CPU
arch/x86/kernel/acpi/cppc.c | 166 ++++++++++++++++++++++----------- drivers/cpufreq/acpi-cpufreq.c | 17 ++-- drivers/cpufreq/amd-pstate.c | 20 ++-- include/acpi/cppc_acpi.h | 14 ++- 4 files changed, 143 insertions(+), 74 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/3 ACPI: CPPC: Refactor boost ratio handling
From: Mario Limonciello <[email protected]>
Rename amd_get_boost_ratio_numerator() to amd_get_effective_highest_perf() to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.
Add a new helper amd_get_boost_ratio() for doing both for boost ratio calculations and update callers to use it.
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
The frequency values will eventually come from the BIOS, but for now use some hardcoded values for Zen6 platforms.
--- arch/x86/kernel/acpi/cppc.c | 166 ++++++++++++++++++++++----------- drivers/cpufreq/acpi-cpufreq.c | 5 +- drivers/cpufreq/amd-pstate.c | 14 ++- include/acpi/cppc_acpi.h | 14 ++- 4 files changed, 134 insertions(+), 65 deletions(-)
arch/x86/kernel/acpi/cppc.c +110 -56
@@ -11,6 +11,7 @@#include <asm/msr.h> #include <asm/processor.h> #include <asm/topology.h> +#include <asm/cpu_device_id.h> #define CPPC_HIGHEST_PERF_PERFORMANCE 196#define CPPC_HIGHEST_PERF_PREFCORE 166
@@ -95,31 +96,18 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)static void amd_set_max_freq_ratio (void ) { -struct cppc_perf_caps perf_caps; -u64 numerator, nominal_perf; +u64 numerator, denominator;u64 perf_ratio;int rc; - rc =cppc_get_perf_caps (0 , &perf_caps); -if (rc) { -pr_debug ("Could not retrieve perf counters (%d)\n" , rc); -return ; - } - - rc =amd_get_boost_ratio_numerator (0 , &numerator); + rc =amd_get_boost_ratio (0 , &numerator, &denominator);if (rc) { -pr_debug ("Could not retrieve highest performance (%d)\n" , rc); -return ; - } - nominal_perf = perf_caps.nominal_perf; - -if (!nominal_perf) { -pr_debug ("Could not retrieve nominal performance\n" ); +pr_debug ("Could not retrieve boost ratio (%d)\n" , rc);return ; }/* midpoint between max_boost and max_P */ - perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , nominal_perf) +SCHED_CAPACITY_SCALE ) >>1 ; + perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , denominator) +SCHED_CAPACITY_SCALE ) >>1 ;freq_invariance_set_perf_ratio (perf_ratio, false); }
@@ -239,35 +227,30 @@ int amd_detect_prefcore(bool *detected)EXPORT_SYMBOL_GPL (amd_detect_prefcore);/** -* amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation -* @cpu: CPU to get numerator for. -* @numerator: Output variable for numerator. -* -* Determine the numerator to use for calculating the boost ratio on -* a CPU. On systems that support preferred cores, this will be a hardcoded -* value. On other systems this will the highest performance register value. +* amd_get_effective_highest_perf: Get the effective highest performance value +* @cpu: CPU to get highest performance for. * -* If booting the system with amd-pstate enabled but preferred cores disabled then -* the correct boost numerator will be returned to match hardware capabilities -* even if the preferred cores scheduling hints are not enabled. +* Get the effective highest performance value for a CPU, accounting for +* preferred cores and heterogeneous topologies. On systems with preferred +* cores, this may be a hardcoded value. On heterogeneous systems, this +* may be a per-CPU value. On other systems, this is the shared highest +* performance value. * -* Return: 0 for success, negative error code otherwise. +* Return: Effective highest performance value, or negative error code. */ -int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +int amd_get_effective_highest_perf (unsigned int cpu) {bool prefcore;int ret;u32 tmp; ret =amd_detect_prefcore (&prefcore); -if (ret) +if (ret <0 )return ret;/* without preferred cores, return the highest perf register value */ -if (!prefcore) { - *numerator = boost_numerator; -return 0 ; - } +if (!prefcore) +return boost_numerator;/* * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f,
@@ -277,8 +260,7 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)if (cpu_feature_enabled (X86_FEATURE_ZEN4 )) {switch (boot_cpu_data.x86_model) { case 0x70 ... 0x7f: - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; +return CPPC_HIGHEST_PERF_PERFORMANCE ;default :break ; }
@@ -286,28 +268,100 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (cpu_data (cpu).topo.cpu_type) { -case TOPO_CPU_TYPE_UNKNOWN : -case TOPO_CPU_TYPE_ANY : -pr_warn ("Undefined core type found for cpu %d\n" , cpu); -break ; -case TOPO_CPU_TYPE_PERFORMANCE : -/* use the max scale for performance cores */ - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; -case TOPO_CPU_TYPE_LOW_POWER : -case TOPO_CPU_TYPE_EFFICIENCY : -/* use the highest perf value for efficiency and low-power cores */ - ret =amd_get_highest_perf (cpu, &tmp); -if (ret) -return ret; - *numerator = tmp; -return 0 ; - } +if (cpu_feature_enabled (X86_FEATURE_ZEN5 ) && +cpu_data (cpu).topo.cpu_type ==TOPO_CPU_TYPE_PERFORMANCE ) +return CPPC_HIGHEST_PERF_PERFORMANCE ; + +/* Zen 5 efficiency, and Zen 6+ */ + ret =amd_get_highest_perf (cpu, &tmp); +if (ret <0 ) +return ret; + +return tmp; + } + +return CPPC_HIGHEST_PERF_PREFCORE ; +} +EXPORT_SYMBOL_GPL (amd_get_effective_highest_perf); + +struct amd_max_freq { +u32 performance; +u32 efficiency; +u32 low_power; +}; + +static const struct amd_max_freq max_freq_zen6_client = { + .performance =5025 , + .efficiency =3524 , + .low_power =2399 , +}; + +int amd_get_max_frequency (unsigned int cpu) +{ +enum x86_topology_cpu_type type =cpu_data (cpu).topo.cpu_type; +const struct amd_max_freq *max_freq =NULL ; + +if (cpu_feature_enabled (X86_FEATURE_ZEN6 ) && +cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) + max_freq = &max_freq_zen6_client; + +if (!max_freq) +return 0 ; + +switch (type) { +case TOPO_CPU_TYPE_PERFORMANCE : +return max_freq->performance; +case TOPO_CPU_TYPE_EFFICIENCY : +return max_freq->efficiency; +case TOPO_CPU_TYPE_LOW_POWER : +return max_freq->low_power; +default : +break ; } - *numerator =CPPC_HIGHEST_PERF_PREFCORE ; +return 0 ; +} +EXPORT_SYMBOL_GPL (amd_get_max_frequency); + +/** +* amd_get_boost_ratio: Get numerator and denominator for boost ratio +* @cpu: CPU to get the boost ratio for. +* @numerator: Output variable for numerator. +* @denominator: Output variable for denominator. +* +* Get the numerator and denominator for calculating the boost ratio. +* +* Return: 0 for success, negative error code otherwise. +*/ +int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) +{ +struct cppc_perf_caps perf_caps; +int max_frequency; +int ret; + + ret =cppc_get_perf_caps (cpu, &perf_caps); +if (ret) +return ret; + + max_frequency =amd_get_max_frequency (cpu); +/* Use frequency values if available */ +if (max_frequency && perf_caps.nominal_freq) { + *numerator = max_frequency; + *denominator = perf_caps.nominal_freq; +return 0 ; + } + +/* Fall back to performance values */ + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) +return ret; + + *numerator = ret; + + *denominator = perf_caps.nominal_perf; +if (!*denominator) +return -EINVAL ;return 0 ; } -EXPORT_SYMBOL_GPL (amd_get_boost_ratio_numerator); +EXPORT_SYMBOL_GPL (amd_get_boost_ratio);
drivers/cpufreq/acpi-cpufreq.c +3 -2
@@ -640,12 +640,13 @@ static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq) }if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { - ret =amd_get_boost_ratio_numerator (cpu, &highest_perf); -if (ret) { + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) {pr_debug ("CPU%d: Unable to get boost ratio numerator (%d)\n" , cpu, ret);return 0 ; } + highest_perf = ret; }else { highest_perf = perf_caps.highest_perf; }
drivers/cpufreq/amd-pstate.c +9 -5
@@ -555,11 +555,13 @@ static int msr_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; - ret =rdmsrq_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req); + numerator = ret; + + ret =rdmsrq_safe_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req);if (ret)return ret;
@@ -590,10 +592,12 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; + numerator = ret; + perf.highest_perf = numerator; perf.max_limit_perf = numerator; perf.min_limit_perf = cppc_perf.lowest_perf;
include/acpi/cppc_acpi.h +12 -2
@@ -202,7 +202,9 @@ extern int cppc_set_auto_sel(int cpu, bool enable);extern int cppc_get_perf_limited (int cpu,u64 *perf_limited);extern int cppc_set_perf_limited (int cpu,u64 bits_to_clear);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf); -extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator); +extern int amd_get_effective_highest_perf (unsigned int cpu); +extern int amd_get_max_frequency (unsigned int cpu); +extern int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator);extern int amd_detect_prefcore (bool *detected);#else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf (int cpunum,u64 *desired_perf)
@@ -321,7 +323,15 @@ static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) {return -ENODEV ; } -static inline int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +static inline int amd_get_effective_highest_perf (unsigned int cpu) +{ +return -EOPNOTSUPP ; +} +static inline int amd_get_max_frequency (unsigned int cpu) +{ +return 0 ; +} +static inline int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) {return -EOPNOTSUPP ; }
Signature · 1 line
2.53.0
Christian Loehle
maintainerRe: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 6 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.
Quoted 6 lines
Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Quoted 328 lines
The frequency values will eventually come from the BIOS, but for now use some hardcoded values for Zen6 platforms.
Tested-by K Prateek Nayak <[email protected]>Signed-off-by Mario Limonciello <[email protected]>--- arch/x86/kernel/acpi/cppc.c | 166 ++++++++++++++++++++++----------- drivers/cpufreq/acpi-cpufreq.c | 5 +- drivers/cpufreq/amd-pstate.c | 14 ++- include/acpi/cppc_acpi.h | 14 ++- 4 files changed, 134 insertions(+), 65 deletions(-)arch/x86/kernel/acpi/cppc.c +110
-56@@ -11,6 +11,7 @@#include <asm/msr.h> #include <asm/processor.h> #include <asm/topology.h> +#include <asm/cpu_device_id.h> #define CPPC_HIGHEST_PERF_PERFORMANCE 196#define CPPC_HIGHEST_PERF_PREFCORE 166@@ -95,31 +96,18 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)static void amd_set_max_freq_ratio (void ) { -struct cppc_perf_caps perf_caps; -u64 numerator, nominal_perf; +u64 numerator, denominator;u64 perf_ratio;int rc; - rc =cppc_get_perf_caps (0 , &perf_caps); -if (rc) { -pr_debug ("Could not retrieve perf counters (%d)\n" , rc); -return ; - } - - rc =amd_get_boost_ratio_numerator (0 , &numerator); + rc =amd_get_boost_ratio (0 , &numerator, &denominator);if (rc) { -pr_debug ("Could not retrieve highest performance (%d)\n" , rc); -return ; - } - nominal_perf = perf_caps.nominal_perf; - -if (!nominal_perf) { -pr_debug ("Could not retrieve nominal performance\n" ); +pr_debug ("Could not retrieve boost ratio (%d)\n" , rc);return ; }/* midpoint between max_boost and max_P */ - perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , nominal_perf) +SCHED_CAPACITY_SCALE ) >>1 ; + perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , denominator) +SCHED_CAPACITY_SCALE ) >>1 ;freq_invariance_set_perf_ratio (perf_ratio, false); }@@ -239,35 +227,30 @@ int amd_detect_prefcore(bool *detected)EXPORT_SYMBOL_GPL (amd_detect_prefcore);/** -* amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation -* @cpu: CPU to get numerator for. -* @numerator: Output variable for numerator. -* -* Determine the numerator to use for calculating the boost ratio on -* a CPU. On systems that support preferred cores, this will be a hardcoded -* value. On other systems this will the highest performance register value. +* amd_get_effective_highest_perf: Get the effective highest performance value +* @cpu: CPU to get highest performance for. * -* If booting the system with amd-pstate enabled but preferred cores disabled then -* the correct boost numerator will be returned to match hardware capabilities -* even if the preferred cores scheduling hints are not enabled. +* Get the effective highest performance value for a CPU, accounting for +* preferred cores and heterogeneous topologies. On systems with preferred +* cores, this may be a hardcoded value. On heterogeneous systems, this +* may be a per-CPU value. On other systems, this is the shared highest +* performance value. * -* Return: 0 for success, negative error code otherwise. +* Return: Effective highest performance value, or negative error code. */ -int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +int amd_get_effective_highest_perf (unsigned int cpu) {bool prefcore;int ret;u32 tmp; ret =amd_detect_prefcore (&prefcore); -if (ret) +if (ret <0 )return ret;/* without preferred cores, return the highest perf register value */ -if (!prefcore) { - *numerator = boost_numerator; -return 0 ; - } +if (!prefcore) +return boost_numerator;/* * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f, @@ -277,8 +260,7 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)if (cpu_feature_enabled (X86_FEATURE_ZEN4 )) {switch (boot_cpu_data.x86_model) { case 0x70 ... 0x7f: - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; +return CPPC_HIGHEST_PERF_PERFORMANCE ;default :break ; }@@ -286,28 +268,100 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (cpu_data (cpu).topo.cpu_type) { -case TOPO_CPU_TYPE_UNKNOWN : -case TOPO_CPU_TYPE_ANY : -pr_warn ("Undefined core type found for cpu %d\n" , cpu); -break ; -case TOPO_CPU_TYPE_PERFORMANCE : -/* use the max scale for performance cores */ - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; -case TOPO_CPU_TYPE_LOW_POWER : -case TOPO_CPU_TYPE_EFFICIENCY : -/* use the highest perf value for efficiency and low-power cores */ - ret =amd_get_highest_perf (cpu, &tmp); -if (ret) -return ret; - *numerator = tmp; -return 0 ; - } +if (cpu_feature_enabled (X86_FEATURE_ZEN5 ) && +cpu_data (cpu).topo.cpu_type ==TOPO_CPU_TYPE_PERFORMANCE ) +return CPPC_HIGHEST_PERF_PERFORMANCE ; + +/* Zen 5 efficiency, and Zen 6+ */ + ret =amd_get_highest_perf (cpu, &tmp); +if (ret <0 ) +return ret; + +return tmp; + } + +return CPPC_HIGHEST_PERF_PREFCORE ; +} +EXPORT_SYMBOL_GPL (amd_get_effective_highest_perf); + +struct amd_max_freq { +u32 performance; +u32 efficiency; +u32 low_power; +}; + +static const struct amd_max_freq max_freq_zen6_client = { + .performance =5025 , + .efficiency =3524 , + .low_power =2399 , +}; + +int amd_get_max_frequency (unsigned int cpu) +{ +enum x86_topology_cpu_type type =cpu_data (cpu).topo.cpu_type; +const struct amd_max_freq *max_freq =NULL ; + +if (cpu_feature_enabled (X86_FEATURE_ZEN6 ) && +cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) + max_freq = &max_freq_zen6_client; + +if (!max_freq) +return 0 ; + +switch (type) { +case TOPO_CPU_TYPE_PERFORMANCE : +return max_freq->performance; +case TOPO_CPU_TYPE_EFFICIENCY : +return max_freq->efficiency; +case TOPO_CPU_TYPE_LOW_POWER : +return max_freq->low_power; +default : +break ; } - *numerator =CPPC_HIGHEST_PERF_PREFCORE ; +return 0 ; +} +EXPORT_SYMBOL_GPL (amd_get_max_frequency); + +/** +* amd_get_boost_ratio: Get numerator and denominator for boost ratio +* @cpu: CPU to get the boost ratio for. +* @numerator: Output variable for numerator. +* @denominator: Output variable for denominator. +* +* Get the numerator and denominator for calculating the boost ratio. +* +* Return: 0 for success, negative error code otherwise. +*/ +int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) +{ +struct cppc_perf_caps perf_caps; +int max_frequency; +int ret; + + ret =cppc_get_perf_caps (cpu, &perf_caps); +if (ret) +return ret; + + max_frequency =amd_get_max_frequency (cpu); +/* Use frequency values if available */ +if (max_frequency && perf_caps.nominal_freq) { + *numerator = max_frequency; + *denominator = perf_caps.nominal_freq; +return 0 ; + } + +/* Fall back to performance values */ + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) +return ret; + + *numerator = ret; + + *denominator = perf_caps.nominal_perf; +if (!*denominator) +return -EINVAL ;return 0 ; } -EXPORT_SYMBOL_GPL (amd_get_boost_ratio_numerator); +EXPORT_SYMBOL_GPL (amd_get_boost_ratio);drivers/cpufreq/acpi-cpufreq.c +3
-2@@ -640,12 +640,13 @@ static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq) }if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { - ret =amd_get_boost_ratio_numerator (cpu, &highest_perf); -if (ret) { + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) {pr_debug ("CPU%d: Unable to get boost ratio numerator (%d)\n" , cpu, ret);return 0 ; } + highest_perf = ret; }else { highest_perf = perf_caps.highest_perf; }drivers/cpufreq/amd-pstate.c +9
-5@@ -555,11 +555,13 @@ static int msr_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; - ret =rdmsrq_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req); + numerator = ret; + + ret =rdmsrq_safe_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req);if (ret)return ret;@@ -590,10 +592,12 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; + numerator = ret; + perf.highest_perf = numerator; perf.max_limit_perf = numerator; perf.min_limit_perf = cppc_perf.lowest_perf;include/acpi/cppc_acpi.h +12
-2@@ -202,7 +202,9 @@ extern int cppc_set_auto_sel(int cpu, bool enable);extern int cppc_get_perf_limited (int cpu,u64 *perf_limited);extern int cppc_set_perf_limited (int cpu,u64 bits_to_clear);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf); -extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator); +extern int amd_get_effective_highest_perf (unsigned int cpu); +extern int amd_get_max_frequency (unsigned int cpu); +extern int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator);extern int amd_detect_prefcore (bool *detected);#else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf (int cpunum,u64 *desired_perf)@@ -321,7 +323,15 @@ static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) {return -ENODEV ; } -static inline int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +static inline int amd_get_effective_highest_perf (unsigned int cpu) +{ +return -EOPNOTSUPP ; +} +static inline int amd_get_max_frequency (unsigned int cpu) +{ +return 0 ; +} +static inline int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) {return -EOPNOTSUPP ; }
Re: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 10 lines · Christian Loehle
Quoted 9 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.
Quoted 7 lines
Quoted 3 lines
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Do you mean in the commit message, like spin the patch? Or just in this thread?
Not all cores will operate at the same frequency and fixed scaling values from CPPC perf don't apply anymore.
Quoted 330 lines
Quoted 329 lines
The frequency values will eventually come from the BIOS, but for now use some hardcoded values for Zen6 platforms.
Tested-by K Prateek Nayak <[email protected]>Signed-off-by Mario Limonciello <[email protected]>--- arch/x86/kernel/acpi/cppc.c | 166 ++++++++++++++++++++++----------- drivers/cpufreq/acpi-cpufreq.c | 5 +- drivers/cpufreq/amd-pstate.c | 14 ++- include/acpi/cppc_acpi.h | 14 ++- 4 files changed, 134 insertions(+), 65 deletions(-)arch/x86/kernel/acpi/cppc.c +110
-56@@ -11,6 +11,7 @@#include <asm/msr.h> #include <asm/processor.h> #include <asm/topology.h> +#include <asm/cpu_device_id.h> #define CPPC_HIGHEST_PERF_PERFORMANCE 196#define CPPC_HIGHEST_PERF_PREFCORE 166@@ -95,31 +96,18 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)static void amd_set_max_freq_ratio (void ) { -struct cppc_perf_caps perf_caps; -u64 numerator, nominal_perf; +u64 numerator, denominator;u64 perf_ratio;int rc; - rc =cppc_get_perf_caps (0 , &perf_caps); -if (rc) { -pr_debug ("Could not retrieve perf counters (%d)\n" , rc); -return ; - } - - rc =amd_get_boost_ratio_numerator (0 , &numerator); + rc =amd_get_boost_ratio (0 , &numerator, &denominator);if (rc) { -pr_debug ("Could not retrieve highest performance (%d)\n" , rc); -return ; - } - nominal_perf = perf_caps.nominal_perf; - -if (!nominal_perf) { -pr_debug ("Could not retrieve nominal performance\n" ); +pr_debug ("Could not retrieve boost ratio (%d)\n" , rc);return ; }/* midpoint between max_boost and max_P */ - perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , nominal_perf) +SCHED_CAPACITY_SCALE ) >>1 ; + perf_ratio = (div_u64 (numerator *SCHED_CAPACITY_SCALE , denominator) +SCHED_CAPACITY_SCALE ) >>1 ;freq_invariance_set_perf_ratio (perf_ratio, false); }@@ -239,35 +227,30 @@ int amd_detect_prefcore(bool *detected)EXPORT_SYMBOL_GPL (amd_detect_prefcore);/** -* amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation -* @cpu: CPU to get numerator for. -* @numerator: Output variable for numerator. -* -* Determine the numerator to use for calculating the boost ratio on -* a CPU. On systems that support preferred cores, this will be a hardcoded -* value. On other systems this will the highest performance register value. +* amd_get_effective_highest_perf: Get the effective highest performance value +* @cpu: CPU to get highest performance for. * -* If booting the system with amd-pstate enabled but preferred cores disabled then -* the correct boost numerator will be returned to match hardware capabilities -* even if the preferred cores scheduling hints are not enabled. +* Get the effective highest performance value for a CPU, accounting for +* preferred cores and heterogeneous topologies. On systems with preferred +* cores, this may be a hardcoded value. On heterogeneous systems, this +* may be a per-CPU value. On other systems, this is the shared highest +* performance value. * -* Return: 0 for success, negative error code otherwise. +* Return: Effective highest performance value, or negative error code. */ -int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +int amd_get_effective_highest_perf (unsigned int cpu) {bool prefcore;int ret;u32 tmp; ret =amd_detect_prefcore (&prefcore); -if (ret) +if (ret <0 )return ret;/* without preferred cores, return the highest perf register value */ -if (!prefcore) { - *numerator = boost_numerator; -return 0 ; - } +if (!prefcore) +return boost_numerator;/* * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f, @@ -277,8 +260,7 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)if (cpu_feature_enabled (X86_FEATURE_ZEN4 )) {switch (boot_cpu_data.x86_model) { case 0x70 ... 0x7f: - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; +return CPPC_HIGHEST_PERF_PERFORMANCE ;default :break ; }@@ -286,28 +268,100 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)/* detect if running on heterogeneous design */ if (cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) { -switch (cpu_data (cpu).topo.cpu_type) { -case TOPO_CPU_TYPE_UNKNOWN : -case TOPO_CPU_TYPE_ANY : -pr_warn ("Undefined core type found for cpu %d\n" , cpu); -break ; -case TOPO_CPU_TYPE_PERFORMANCE : -/* use the max scale for performance cores */ - *numerator =CPPC_HIGHEST_PERF_PERFORMANCE ; -return 0 ; -case TOPO_CPU_TYPE_LOW_POWER : -case TOPO_CPU_TYPE_EFFICIENCY : -/* use the highest perf value for efficiency and low-power cores */ - ret =amd_get_highest_perf (cpu, &tmp); -if (ret) -return ret; - *numerator = tmp; -return 0 ; - } +if (cpu_feature_enabled (X86_FEATURE_ZEN5 ) && +cpu_data (cpu).topo.cpu_type ==TOPO_CPU_TYPE_PERFORMANCE ) +return CPPC_HIGHEST_PERF_PERFORMANCE ; + +/* Zen 5 efficiency, and Zen 6+ */ + ret =amd_get_highest_perf (cpu, &tmp); +if (ret <0 ) +return ret; + +return tmp; + } + +return CPPC_HIGHEST_PERF_PREFCORE ; +} +EXPORT_SYMBOL_GPL (amd_get_effective_highest_perf); + +struct amd_max_freq { +u32 performance; +u32 efficiency; +u32 low_power; +}; + +static const struct amd_max_freq max_freq_zen6_client = { + .performance =5025 , + .efficiency =3524 , + .low_power =2399 , +}; + +int amd_get_max_frequency (unsigned int cpu) +{ +enum x86_topology_cpu_type type =cpu_data (cpu).topo.cpu_type; +const struct amd_max_freq *max_freq =NULL ; + +if (cpu_feature_enabled (X86_FEATURE_ZEN6 ) && +cpu_feature_enabled (X86_FEATURE_AMD_HTR_CORES )) + max_freq = &max_freq_zen6_client; + +if (!max_freq) +return 0 ; + +switch (type) { +case TOPO_CPU_TYPE_PERFORMANCE : +return max_freq->performance; +case TOPO_CPU_TYPE_EFFICIENCY : +return max_freq->efficiency; +case TOPO_CPU_TYPE_LOW_POWER : +return max_freq->low_power; +default : +break ; } - *numerator =CPPC_HIGHEST_PERF_PREFCORE ; +return 0 ; +} +EXPORT_SYMBOL_GPL (amd_get_max_frequency); + +/** +* amd_get_boost_ratio: Get numerator and denominator for boost ratio +* @cpu: CPU to get the boost ratio for. +* @numerator: Output variable for numerator. +* @denominator: Output variable for denominator. +* +* Get the numerator and denominator for calculating the boost ratio. +* +* Return: 0 for success, negative error code otherwise. +*/ +int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) +{ +struct cppc_perf_caps perf_caps; +int max_frequency; +int ret; + + ret =cppc_get_perf_caps (cpu, &perf_caps); +if (ret) +return ret; + + max_frequency =amd_get_max_frequency (cpu); +/* Use frequency values if available */ +if (max_frequency && perf_caps.nominal_freq) { + *numerator = max_frequency; + *denominator = perf_caps.nominal_freq; +return 0 ; + } + +/* Fall back to performance values */ + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) +return ret; + + *numerator = ret; + + *denominator = perf_caps.nominal_perf; +if (!*denominator) +return -EINVAL ;return 0 ; } -EXPORT_SYMBOL_GPL (amd_get_boost_ratio_numerator); +EXPORT_SYMBOL_GPL (amd_get_boost_ratio);drivers/cpufreq/acpi-cpufreq.c +3
-2@@ -640,12 +640,13 @@ static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq) }if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { - ret =amd_get_boost_ratio_numerator (cpu, &highest_perf); -if (ret) { + ret =amd_get_effective_highest_perf (cpu); +if (ret <0 ) {pr_debug ("CPU%d: Unable to get boost ratio numerator (%d)\n" , cpu, ret);return 0 ; } + highest_perf = ret; }else { highest_perf = perf_caps.highest_perf; }drivers/cpufreq/amd-pstate.c +9
-5@@ -555,11 +555,13 @@ static int msr_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; - ret =rdmsrq_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req); + numerator = ret; + + ret =rdmsrq_safe_on_cpu (cpudata->cpu,MSR_AMD_CPPC_REQ , &cppc_req);if (ret)return ret;@@ -590,10 +592,12 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)if (ret)return ret; - ret =amd_get_boost_ratio_numerator (cpudata->cpu, &numerator); -if (ret) + ret =amd_get_effective_highest_perf (cpudata->cpu); +if (ret <0 )return ret; + numerator = ret; + perf.highest_perf = numerator; perf.max_limit_perf = numerator; perf.min_limit_perf = cppc_perf.lowest_perf;include/acpi/cppc_acpi.h +12
-2@@ -202,7 +202,9 @@ extern int cppc_set_auto_sel(int cpu, bool enable);extern int cppc_get_perf_limited (int cpu,u64 *perf_limited);extern int cppc_set_perf_limited (int cpu,u64 bits_to_clear);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf); -extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator); +extern int amd_get_effective_highest_perf (unsigned int cpu); +extern int amd_get_max_frequency (unsigned int cpu); +extern int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator);extern int amd_detect_prefcore (bool *detected);#else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf (int cpunum,u64 *desired_perf)@@ -321,7 +323,15 @@ static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) {return -ENODEV ; } -static inline int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator) +static inline int amd_get_effective_highest_perf (unsigned int cpu) +{ +return -EOPNOTSUPP ; +} +static inline int amd_get_max_frequency (unsigned int cpu) +{ +return 0 ; +} +static inline int amd_get_boost_ratio (unsigned int cpu,u64 *numerator,u64 *denominator) {return -EOPNOTSUPP ; }
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 20 lines · Mario Limonciello
Quoted 10 lines · Christian Loehle
Quoted 9 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.Quoted 7 lines
Quoted 3 lines
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Quoted 5 lines
Do you mean in the commit message, like spin the patch? Or just in this thread?
Not all cores will operate at the same frequency and fixed scaling values from CPPC perf don't apply anymore.
Well, CPPC is per-CPU at least in principle, so the above doesn't explain much TBH.
It kind of follows from the cover letter that there's something missing in CPPC, so this is a stop-gap thing, but it would be good to put the information from the cover letter to the changelog of this patch.
Re: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 27 lines · Rafael J. Wysocki (Intel)
Quoted 20 lines · Mario Limonciello
Quoted 10 lines · Christian Loehle
Quoted 9 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.Quoted 7 lines
Quoted 3 lines
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Quoted 5 lines
Do you mean in the commit message, like spin the patch? Or just in this thread?
Not all cores will operate at the same frequency and fixed scaling values from CPPC perf don't apply anymore.
Quoted 7 lines
Well, CPPC is per-CPU at least in principle, so the above doesn't explain much TBH.
It kind of follows from the cover letter that there's something missing in CPPC, so this is a stop-gap thing, but it would be good to put the information from the cover letter to the changelog of this patch.
OK; I'll respin the series with the detail in this commit message.
And yeah; this is totally stop gap to allow other development that needs this.
Once next ACPI spec is out I'll tear out the stop gap and put in the right support.
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 32 lines · Mario Limonciello
Quoted 30 lines · Rafael J. Wysocki (Intel)
Quoted 20 lines · Mario Limonciello
Quoted 10 lines · Christian Loehle
Quoted 9 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.Quoted 7 lines
Quoted 3 lines
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Quoted 5 lines
Do you mean in the commit message, like spin the patch? Or just in this thread?
Not all cores will operate at the same frequency and fixed scaling values from CPPC perf don't apply anymore.
Well, CPPC is per-CPU at least in principle, so the above doesn't explain much TBH.
Quoted 6 lines
Quoted 4 lines
It kind of follows from the cover letter that there's something missing in CPPC, so this is a stop-gap thing, but it would be good to put the information from the cover letter to the changelog of this patch.
OK; I'll respin the series with the detail in this commit message.
Thanks!
With that, please feel free to add my ACKs to the first two patches in this series and route it as a whole through the amd-pstate tree.
Quoted 5 lines
And yeah; this is totally stop gap to allow other development that needs this.
Once next ACPI spec is out I'll tear out the stop gap and put in the right support.
OK
Re: [PATCH v3 1/3] ACPI: CPPC: Refactor boost ratio handling
Quoted 38 lines · Rafael J. Wysocki (Intel)
Quoted 37 lines · Mario Limonciello
Quoted 34 lines · Rafael J. Wysocki (Intel)
Quoted 20 lines · Mario Limonciello
Quoted 10 lines · Christian Loehle
Quoted 9 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Rename
amd_get_boost_ratio_numerator()toamd_get_effective_highest_perf()to better reflect that it returns the effective highest performance value for a CPU, accounting for preferred cores and heterogeneous topologies.Add a new helper
amd_get_boost_ratio()for doing both for boost ratio calculations and update callers to use it.Quoted 7 lines
Quoted 3 lines
This refactoring is needed because on some AMD systems (Zen6+), the boost ratio should be calculated from frequency values rather than performance values.
I think I see why you chose to implement it this way (the x86 APERF / MPERF) issue, but I'd still prefer it to be spelled out here why this is necessary.
Quoted 5 lines
Do you mean in the commit message, like spin the patch? Or just in this thread?
Not all cores will operate at the same frequency and fixed scaling values from CPPC perf don't apply anymore.
Well, CPPC is per-CPU at least in principle, so the above doesn't explain much TBH.
It kind of follows from the cover letter that there's something missing in CPPC, so this is a stop-gap thing, but it would be good to put the information from the cover letter to the changelog of this patch.
Quoted 6 lines
Quoted 1 line
OK; I'll respin the series with the detail in this commit message.
Thanks!
With that, please feel free to add my ACKs to the first two patches in this series and route it as a whole through the amd-pstate tree.
Will do; thanks.
Quoted 8 lines
Quoted 6 lines
And yeah; this is totally stop gap to allow other development that needs this.
Once next ACPI spec is out I'll tear out the stop gap and put in the right support.
OK
PATCH v3 2/3 cpufreq/acpi-cpufreq: Use amd_get_boost_ratio()
In reply to Mario Limonciello (AMD)From: Mario Limonciello <[email protected]>
Update get_max_boost_ratio() to use the new amd_get_boost_ratio() helper function instead of calling amd_get_effective_highest_perf() directly.
This ensures the boost ratio is calculated correctly on systems where frequency values should be used instead of performance values.
--- drivers/cpufreq/acpi-cpufreq.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +9 -11
@@ -626,7 +626,7 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)static u64 get_max_boost_ratio (unsigned int cpu,u64 *nominal_freq) {struct cppc_perf_caps perf_caps; -u64 highest_perf, nominal_perf; +u64 numerator, denominator;int ret;if (acpi_pstate_strict)
@@ -640,33 +640,31 @@ static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq) }if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { - ret =amd_get_effective_highest_perf (cpu); -if (ret <0 ) { -pr_debug ("CPU%d: Unable to get boost ratio numerator (%d)\n" , + ret =amd_get_boost_ratio (cpu, &numerator, &denominator); +if (ret) { +pr_debug ("CPU%d: Unable to get boost ratio (%d)\n" , cpu, ret);return 0 ; } - highest_perf = ret; }else { - highest_perf = perf_caps.highest_perf; + numerator = perf_caps.highest_perf; + denominator = perf_caps.nominal_perf; } - nominal_perf = perf_caps.nominal_perf; -if (nominal_freq) *nominal_freq = perf_caps.nominal_freq *1000 ; -if (!highest_perf || !nominal_perf) { +if (!numerator || !denominator) {pr_debug ("CPU%d: highest or nominal performance missing\n" , cpu);return 0 ; } -if (highest_perf < nominal_perf) { +if (numerator < denominator) {pr_debug ("CPU%d: nominal performance above highest\n" , cpu);return 0 ; } -return div_u64 (highest_perf <<SCHED_CAPACITY_SHIFT , nominal_perf); +return div_u64 (numerator <<SCHED_CAPACITY_SHIFT , denominator); }#else
Signature · 1 line
2.53.0
PATCH v3 3/3 cpufreq/amd-pstate: Get Highest Freq for a CPU
In reply to Mario Limonciello (AMD)From: Mario Limonciello <[email protected]>
If the highest frequency is known for a CPU, use this instead of trying to calculate by linear interpolation.
--- drivers/cpufreq/amd-pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -2
@@ -1102,8 +1102,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)WRITE_ONCE (cpudata->nominal_freq, nominal_freq); -/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */ - max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf); +/* 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 ; +if (!max_freq) + max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf);WRITE_ONCE (cpudata->max_freq, max_freq); lowest_nonlinear_freq =perf_to_freq (perf, nominal_freq, perf.lowest_nonlinear_perf);
Signature · 1 line
2.53.0
Christian Loehle
maintainerRe: [PATCH v3 3/3] cpufreq/amd-pstate: Get Highest Freq for a CPU
Quoted 15 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
If the highest frequency is known for a CPU, use this instead of trying to calculate by linear interpolation.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/cpufreq/amd-pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +0
-0
drivers/cpufreq/amd-pstate.c static int amd_pstate_init_freq(struct amd_cpudata *cpudata) · line 1108
Quoted 9 lines
drivers/cpufreq/amd-pstate.c +4
-2@@ -1102,8 +1102,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)WRITE_ONCE (cpudata->nominal_freq, nominal_freq); -/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */ - max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf); +/* 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 ; +if (!max_freq) + max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf);
Don't you need to align freq_to_perf() (or the callers) for the BIOS-overwrite case too? amd_pstate_update_min_max_limit() still uses the nominal-based conversion for policy->max, so the new maximum frequency maps back to highest_perf on each core type? (and we end up with max_limit_perf < highest_perf if the BIOS-overwrite values are below the interpolation result.)
Quoted 3 lines
drivers/cpufreq/amd-pstate.c +0
-0WRITE_ONCE (cpudata->max_freq, max_freq); lowest_nonlinear_freq =perf_to_freq (perf, nominal_freq, perf.lowest_nonlinear_perf);
Re: [PATCH v3 3/3] cpufreq/amd-pstate: Get Highest Freq for a CPU
Quoted 19 lines · Christian Loehle
Quoted 18 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
If the highest frequency is known for a CPU, use this instead of trying to calculate by linear interpolation.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/cpufreq/amd-pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +0
-0@@ -1102,8 +1102,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)WRITE_ONCE (cpudata->nominal_freq, nominal_freq);
Quoted 14 lines
drivers/cpufreq/amd-pstate.c static int amd_pstate_init_freq(struct amd_cpudata *cpudata) · line 1108
Quoted 6 lines
drivers/cpufreq/amd-pstate.c +4
-2-/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */ - max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf); +/* 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 ; +if (!max_freq) + max_freq =perf_to_freq (perf, nominal_freq, perf.highest_perf);Don't you need to align
freq_to_perf()(or the callers) for the BIOS-overwrite case too?amd_pstate_update_min_max_limit()still uses the nominal-based conversion forpolicy->max, so the new maximum frequency maps back tohighest_perfon each core type? (and we end up withmax_limit_perf<highest_perfif the BIOS-overwrite values are below the interpolation result.)
That's an excellent finding, thanks.
Hello Mario,
Quoted 10 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
Zen6 client platforms use CPPC differently than previous platforms and knowing maximum frequency for a core type is needed for capacity calculations.
Newer versions of the ACPI will introduce a proper interface for getting this information, but for now hardcode values so that these systems perform as intended and to unblock future scheduler work while we continue to wait.
For the whole series, feel free to include:
FWIW, I've been running bleeding-edge branch for a bunch of tests today and everything looks fine.
Signature · 2 lines
Thanks and Regards, Prateek