Skip to content

Commit 3bf8c63

Browse files
wkarnyrafaeljw
authored andcommitted
cpufreq: amd-pstate: Update policy->cur in amd_pstate_adjust_perf()
Driver should update policy->cur after updating the frequency. Currently amd_pstate doesn't update policy->cur when `adjust_perf` is used. Which causes /proc/cpuinfo to show wrong cpu frequency. Fix this by updating policy->cur with correct frequency value in adjust_perf function callback. - Before the fix: (setting min freq to 1.5 MHz) [root@amd]# cat /proc/cpuinfo | grep "cpu MHz" | sort | uniq --count 1 cpu MHz : 1777.016 1 cpu MHz : 1797.160 1 cpu MHz : 1797.270 189 cpu MHz : 400.000 - After the fix: (setting min freq to 1.5 MHz) [root@amd]# cat /proc/cpuinfo | grep "cpu MHz" | sort | uniq --count 1 cpu MHz : 1753.353 1 cpu MHz : 1756.838 1 cpu MHz : 1776.466 1 cpu MHz : 1776.873 1 cpu MHz : 1777.308 1 cpu MHz : 1779.900 183 cpu MHz : 1805.231 1 cpu MHz : 1956.815 1 cpu MHz : 2246.203 1 cpu MHz : 2259.984 Fixes: 1d215f0 ("cpufreq: amd-pstate: Add fast switch function for AMD P-State") Signed-off-by: Wyes Karny <wyes.karny@amd.com> [ rjw: Subject edits ] Cc: 5.17+ <stable@vger.kernel.org> # 5.17+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 249b62c commit 3bf8c63

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,14 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
501501
unsigned long capacity)
502502
{
503503
unsigned long max_perf, min_perf, des_perf,
504-
cap_perf, lowest_nonlinear_perf;
504+
cap_perf, lowest_nonlinear_perf, max_freq;
505505
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
506506
struct amd_cpudata *cpudata = policy->driver_data;
507+
unsigned int target_freq;
507508

508509
cap_perf = READ_ONCE(cpudata->highest_perf);
509510
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
511+
max_freq = READ_ONCE(cpudata->max_freq);
510512

511513
des_perf = cap_perf;
512514
if (target_perf < capacity)
@@ -523,6 +525,10 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
523525
if (max_perf < min_perf)
524526
max_perf = min_perf;
525527

528+
des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
529+
target_freq = div_u64(des_perf * max_freq, max_perf);
530+
policy->cur = target_freq;
531+
526532
amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true,
527533
policy->governor->flags);
528534
cpufreq_cpu_put(policy);

0 commit comments

Comments
 (0)