[PATCH 2/2] cpufreq: amd-pstate: Use amd_get_highest_perf() to lookup perf values

Mario Limonciello
2024-06-26T04:21:46Z

To keep consistency with amd-pstate and acpi-cpufreq behavior, use
amd_get_highest_perf() to find the highest perf value for a given
platform.

This fixes the exact same problem as commit bf202e654bfa ("cpufreq:
amd-pstate: fix the highest frequency issue which limits performance")
from happening on acpi-cpufreq too.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
arch/x86/kernel/cpu/amd.c | 16 +++++++++++++++-
drivers/cpufreq/amd-pstate.c | 21 ++-------------------
2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 8b730193d79e..e69f640cc248 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -1218,7 +1218,21 @@ u32 amd_get_highest_perf(void)
}
}

- return CPPC_HIGHEST_PERF_MAX;
+ /*
+ * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f,
+ * the highest performance level is set to 196.
+ * https://bugzilla.kernel.org/show_bug.cgi?id=218759
+ */
+ if (cpu_feature_enabled(X86_FEATURE_ZEN4)) {
+ switch (c->x86_model) {
+ case 0x70 ... 0x7f:
+ return CPPC_HIGHEST_PERF_PERFORMANCE;
+ default:
+ return CPPC_HIGHEST_PERF_DEFAULT;
+ }
+ }
+
+ return CPPC_HIGHEST_PERF_DEFAULT;
}
EXPORT_SYMBOL_GPL(amd_get_highest_perf);

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 80eaa58f1405..f468d8562e17 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -52,8 +52,6 @@
#define AMD_PSTATE_TRANSITION_LATENCY 20000
#define AMD_PSTATE_TRANSITION_DELAY 1000
#define AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY 600
-#define CPPC_HIGHEST_PERF_PERFORMANCE 196
-#define CPPC_HIGHEST_PERF_DEFAULT 166

#define AMD_CPPC_EPP_PERFORMANCE 0x00
#define AMD_CPPC_EPP_BALANCE_PERFORMANCE 0x80
@@ -349,21 +347,6 @@ static inline int amd_pstate_enable(bool enable)
return static_call(amd_pstate_enable)(enable);
}

-static u32 amd_pstate_highest_perf_set(struct amd_cpudata *cpudata)
-{
- struct cpuinfo_x86 *c = &cpu_data(0);
-
- /*
- * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f,
- * the highest performance level is set to 196.
- * https://bugzilla.kernel.org/show_bug.cgi?id=218759
- */
- if (c->x86 == 0x19 && (c->x86_model >= 0x70 && c->x86_model <= 0x7f))
- return CPPC_HIGHEST_PERF_PERFORMANCE;
-
- return CPPC_HIGHEST_PERF_DEFAULT;
-}
-
static int pstate_init_perf(struct amd_cpudata *cpudata)
{
u64 cap1;
@@ -380,7 +363,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
* the default max perf.
*/
if (cpudata->hw_prefcore)
- highest_perf = amd_pstate_highest_perf_set(cpudata);
+ highest_perf = amd_get_highest_perf();
else
highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);

@@ -404,7 +387,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
return ret;

if (cpudata->hw_prefcore)
- highest_perf = amd_pstate_highest_perf_set(cpudata);
+ highest_perf = amd_get_highest_perf();
else
highest_perf = cppc_perf.highest_perf;

--
2.43.0