Skip to content

Commit ad4caad

Browse files
committed
cpufreq: amd-pstate: Merge amd_pstate_highest_perf_set() into amd_get_boost_ratio_numerator()
The special case in amd_pstate_highest_perf_set() is the value used for calculating the boost numerator. Merge this into amd_get_boost_ratio_numerator() and then use that to calculate boost ratio. This allows dropping more special casing of the highest perf value. Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent 279f838 commit ad4caad

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

Documentation/admin-guide/pm/amd-pstate.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ performance supported in `AMD CPPC Performance Capability <perf_cap_>`_).
251251
In some ASICs, the highest CPPC performance is not the one in the ``_CPC``
252252
table, so we need to expose it to sysfs. If boost is not active, but
253253
still supported, this maximum frequency will be larger than the one in
254-
``cpuinfo``.
254+
``cpuinfo``. On systems that support preferred core, the driver will have
255+
different values for some cores than others.
255256
This attribute is read-only.
256257

257258
``amd_pstate_lowest_nonlinear_freq``

arch/x86/kernel/acpi/cppc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <asm/processor.h>
1010
#include <asm/topology.h>
1111

12+
#define CPPC_HIGHEST_PERF_PERFORMANCE 196
1213
#define CPPC_HIGHEST_PERF_PREFCORE 166
1314

1415
enum amd_pref_core {
@@ -245,6 +246,21 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
245246
*numerator = boost_numerator;
246247
return 0;
247248
}
249+
250+
/*
251+
* For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f,
252+
* the highest performance level is set to 196.
253+
* https://bugzilla.kernel.org/show_bug.cgi?id=218759
254+
*/
255+
if (cpu_feature_enabled(X86_FEATURE_ZEN4)) {
256+
switch (boot_cpu_data.x86_model) {
257+
case 0x70 ... 0x7f:
258+
*numerator = CPPC_HIGHEST_PERF_PERFORMANCE;
259+
return 0;
260+
default:
261+
break;
262+
}
263+
}
248264
*numerator = CPPC_HIGHEST_PERF_PREFCORE;
249265

250266
return 0;

drivers/cpufreq/amd-pstate.c

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#define AMD_PSTATE_TRANSITION_LATENCY 20000
5353
#define AMD_PSTATE_TRANSITION_DELAY 1000
5454
#define AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY 600
55-
#define CPPC_HIGHEST_PERF_PERFORMANCE 196
56-
#define CPPC_HIGHEST_PERF_DEFAULT 166
5755

5856
#define AMD_CPPC_EPP_PERFORMANCE 0x00
5957
#define AMD_CPPC_EPP_BALANCE_PERFORMANCE 0x80
@@ -372,43 +370,17 @@ static inline int amd_pstate_enable(bool enable)
372370
return static_call(amd_pstate_enable)(enable);
373371
}
374372

375-
static u32 amd_pstate_highest_perf_set(struct amd_cpudata *cpudata)
376-
{
377-
struct cpuinfo_x86 *c = &cpu_data(0);
378-
379-
/*
380-
* For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f,
381-
* the highest performance level is set to 196.
382-
* https://bugzilla.kernel.org/show_bug.cgi?id=218759
383-
*/
384-
if (c->x86 == 0x19 && (c->x86_model >= 0x70 && c->x86_model <= 0x7f))
385-
return CPPC_HIGHEST_PERF_PERFORMANCE;
386-
387-
return CPPC_HIGHEST_PERF_DEFAULT;
388-
}
389-
390373
static int pstate_init_perf(struct amd_cpudata *cpudata)
391374
{
392375
u64 cap1;
393-
u32 highest_perf;
394376

395377
int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1,
396378
&cap1);
397379
if (ret)
398380
return ret;
399381

400-
/* For platforms that do not support the preferred core feature, the
401-
* highest_pef may be configured with 166 or 255, to avoid max frequency
402-
* calculated wrongly. we take the AMD_CPPC_HIGHEST_PERF(cap1) value as
403-
* the default max perf.
404-
*/
405-
if (cpudata->hw_prefcore)
406-
highest_perf = amd_pstate_highest_perf_set(cpudata);
407-
else
408-
highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
409-
410-
WRITE_ONCE(cpudata->highest_perf, highest_perf);
411-
WRITE_ONCE(cpudata->max_limit_perf, highest_perf);
382+
WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));
383+
WRITE_ONCE(cpudata->max_limit_perf, AMD_CPPC_HIGHEST_PERF(cap1));
412384
WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1));
413385
WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1));
414386
WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1));
@@ -420,19 +392,13 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
420392
static int cppc_init_perf(struct amd_cpudata *cpudata)
421393
{
422394
struct cppc_perf_caps cppc_perf;
423-
u32 highest_perf;
424395

425396
int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
426397
if (ret)
427398
return ret;
428399

429-
if (cpudata->hw_prefcore)
430-
highest_perf = amd_pstate_highest_perf_set(cpudata);
431-
else
432-
highest_perf = cppc_perf.highest_perf;
433-
434-
WRITE_ONCE(cpudata->highest_perf, highest_perf);
435-
WRITE_ONCE(cpudata->max_limit_perf, highest_perf);
400+
WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf);
401+
WRITE_ONCE(cpudata->max_limit_perf, cppc_perf.highest_perf);
436402
WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf);
437403
WRITE_ONCE(cpudata->lowest_nonlinear_perf,
438404
cppc_perf.lowest_nonlinear_perf);
@@ -918,8 +884,8 @@ static u32 amd_pstate_get_transition_latency(unsigned int cpu)
918884
static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
919885
{
920886
int ret;
921-
u32 min_freq;
922-
u32 highest_perf, max_freq;
887+
u32 min_freq, max_freq;
888+
u64 numerator;
923889
u32 nominal_perf, nominal_freq;
924890
u32 lowest_nonlinear_perf, lowest_nonlinear_freq;
925891
u32 boost_ratio, lowest_nonlinear_ratio;
@@ -941,8 +907,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
941907

942908
nominal_perf = READ_ONCE(cpudata->nominal_perf);
943909

944-
highest_perf = READ_ONCE(cpudata->highest_perf);
945-
boost_ratio = div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
910+
ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator);
911+
if (ret)
912+
return ret;
913+
boost_ratio = div_u64(numerator << SCHED_CAPACITY_SHIFT, nominal_perf);
946914
max_freq = (nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT) * 1000;
947915

948916
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);

0 commit comments

Comments
 (0)