Skip to content

Commit 05648c2

Browse files
committed
Merge tag 'amd-pstate-v6.13-2024-12-11' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/superm1/linux
Merge amd-pstate driver fixes for 6.13-rc4 from Mario Liminciello: "Fix a problem where systems without preferred cores were misdetecting preferred cores. Fix issues with with boost numerator handling leading to inconsistently programmed CPPC max performance values." * tag 'amd-pstate-v6.13-2024-12-11' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/superm1/linux: cpufreq/amd-pstate: Use boost numerator for upper bound of frequencies cpufreq/amd-pstate: Store the boost numerator as highest perf again cpufreq/amd-pstate: Detect preferred core support before driver registration
2 parents 78d4f34 + 2993b29 commit 05648c2

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ 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``. On systems that support preferred core, the driver will have
255-
different values for some cores than others and this will reflect the values
256-
advertised by the platform at bootup.
254+
``cpuinfo``.
257255
This attribute is read-only.
258256

259257
``amd_pstate_lowest_nonlinear_freq``

drivers/cpufreq/amd-pstate.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,19 @@ static inline int amd_pstate_cppc_enable(bool enable)
374374

375375
static int msr_init_perf(struct amd_cpudata *cpudata)
376376
{
377-
u64 cap1;
377+
u64 cap1, numerator;
378378

379379
int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1,
380380
&cap1);
381381
if (ret)
382382
return ret;
383383

384-
WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));
385-
WRITE_ONCE(cpudata->max_limit_perf, AMD_CPPC_HIGHEST_PERF(cap1));
384+
ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator);
385+
if (ret)
386+
return ret;
387+
388+
WRITE_ONCE(cpudata->highest_perf, numerator);
389+
WRITE_ONCE(cpudata->max_limit_perf, numerator);
386390
WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1));
387391
WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1));
388392
WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1));
@@ -394,13 +398,18 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
394398
static int shmem_init_perf(struct amd_cpudata *cpudata)
395399
{
396400
struct cppc_perf_caps cppc_perf;
401+
u64 numerator;
397402

398403
int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
399404
if (ret)
400405
return ret;
401406

402-
WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf);
403-
WRITE_ONCE(cpudata->max_limit_perf, cppc_perf.highest_perf);
407+
ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator);
408+
if (ret)
409+
return ret;
410+
411+
WRITE_ONCE(cpudata->highest_perf, numerator);
412+
WRITE_ONCE(cpudata->max_limit_perf, numerator);
404413
WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf);
405414
WRITE_ONCE(cpudata->lowest_nonlinear_perf,
406415
cppc_perf.lowest_nonlinear_perf);
@@ -561,16 +570,13 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy_data)
561570

562571
static int amd_pstate_update_min_max_limit(struct cpufreq_policy *policy)
563572
{
564-
u32 max_limit_perf, min_limit_perf, lowest_perf, max_perf;
573+
u32 max_limit_perf, min_limit_perf, lowest_perf, max_perf, max_freq;
565574
struct amd_cpudata *cpudata = policy->driver_data;
566575

567-
if (cpudata->boost_supported && !policy->boost_enabled)
568-
max_perf = READ_ONCE(cpudata->nominal_perf);
569-
else
570-
max_perf = READ_ONCE(cpudata->highest_perf);
571-
572-
max_limit_perf = div_u64(policy->max * max_perf, policy->cpuinfo.max_freq);
573-
min_limit_perf = div_u64(policy->min * max_perf, policy->cpuinfo.max_freq);
576+
max_perf = READ_ONCE(cpudata->highest_perf);
577+
max_freq = READ_ONCE(cpudata->max_freq);
578+
max_limit_perf = div_u64(policy->max * max_perf, max_freq);
579+
min_limit_perf = div_u64(policy->min * max_perf, max_freq);
574580

575581
lowest_perf = READ_ONCE(cpudata->lowest_perf);
576582
if (min_limit_perf < lowest_perf)
@@ -889,7 +895,6 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
889895
{
890896
int ret;
891897
u32 min_freq, max_freq;
892-
u64 numerator;
893898
u32 nominal_perf, nominal_freq;
894899
u32 lowest_nonlinear_perf, lowest_nonlinear_freq;
895900
u32 boost_ratio, lowest_nonlinear_ratio;
@@ -911,10 +916,7 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
911916

912917
nominal_perf = READ_ONCE(cpudata->nominal_perf);
913918

914-
ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator);
915-
if (ret)
916-
return ret;
917-
boost_ratio = div_u64(numerator << SCHED_CAPACITY_SHIFT, nominal_perf);
919+
boost_ratio = div_u64(cpudata->highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
918920
max_freq = (nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT) * 1000;
919921

920922
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
@@ -1869,18 +1871,18 @@ static int __init amd_pstate_init(void)
18691871
static_call_update(amd_pstate_update_perf, shmem_update_perf);
18701872
}
18711873

1872-
ret = amd_pstate_register_driver(cppc_state);
1873-
if (ret) {
1874-
pr_err("failed to register with return %d\n", ret);
1875-
return ret;
1876-
}
1877-
18781874
if (amd_pstate_prefcore) {
18791875
ret = amd_detect_prefcore(&amd_pstate_prefcore);
18801876
if (ret)
18811877
return ret;
18821878
}
18831879

1880+
ret = amd_pstate_register_driver(cppc_state);
1881+
if (ret) {
1882+
pr_err("failed to register with return %d\n", ret);
1883+
return ret;
1884+
}
1885+
18841886
dev_root = bus_get_dev_root(&cpu_subsys);
18851887
if (dev_root) {
18861888
ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group);

0 commit comments

Comments
 (0)