Commit e8f555da authored by Meng Li's avatar Meng Li Committed by Mario Limonciello

cpufreq/amd-pstate: fix setting policy current frequency value

When scaling min/max freq values were being setted,
the value of policy->cur need to update.
Signed-off-by: default avatarMeng Li <li.meng@amd.com>
Acked-by: default avatarMario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20240227071133.3405003-1-li.meng@amd.comSigned-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
parent 4e4f600e
...@@ -511,6 +511,8 @@ static inline bool amd_pstate_sample(struct amd_cpudata *cpudata) ...@@ -511,6 +511,8 @@ static inline bool amd_pstate_sample(struct amd_cpudata *cpudata)
static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
u32 des_perf, u32 max_perf, bool fast_switch, int gov_flags) u32 des_perf, u32 max_perf, bool fast_switch, int gov_flags)
{ {
unsigned long max_freq;
struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);
u64 prev = READ_ONCE(cpudata->cppc_req_cached); u64 prev = READ_ONCE(cpudata->cppc_req_cached);
u64 value = prev; u64 value = prev;
...@@ -520,6 +522,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, ...@@ -520,6 +522,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
cpudata->max_limit_perf); cpudata->max_limit_perf);
des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf); des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
max_freq = READ_ONCE(cpudata->max_limit_freq);
policy->cur = div_u64(des_perf * max_freq, max_perf);
if ((cppc_state == AMD_PSTATE_GUIDED) && (gov_flags & CPUFREQ_GOV_DYNAMIC_SWITCHING)) { if ((cppc_state == AMD_PSTATE_GUIDED) && (gov_flags & CPUFREQ_GOV_DYNAMIC_SWITCHING)) {
min_perf = des_perf; min_perf = des_perf;
des_perf = 0; des_perf = 0;
...@@ -641,10 +646,9 @@ static void amd_pstate_adjust_perf(unsigned int cpu, ...@@ -641,10 +646,9 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
unsigned long capacity) unsigned long capacity)
{ {
unsigned long max_perf, min_perf, des_perf, unsigned long max_perf, min_perf, des_perf,
cap_perf, lowest_nonlinear_perf, max_freq; cap_perf, lowest_nonlinear_perf;
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
struct amd_cpudata *cpudata = policy->driver_data; struct amd_cpudata *cpudata = policy->driver_data;
unsigned int target_freq;
if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq) if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)
amd_pstate_update_min_max_limit(policy); amd_pstate_update_min_max_limit(policy);
...@@ -652,7 +656,6 @@ static void amd_pstate_adjust_perf(unsigned int cpu, ...@@ -652,7 +656,6 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
cap_perf = READ_ONCE(cpudata->highest_perf); cap_perf = READ_ONCE(cpudata->highest_perf);
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
max_freq = READ_ONCE(cpudata->max_freq);
des_perf = cap_perf; des_perf = cap_perf;
if (target_perf < capacity) if (target_perf < capacity)
...@@ -670,8 +673,6 @@ static void amd_pstate_adjust_perf(unsigned int cpu, ...@@ -670,8 +673,6 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
max_perf = min_perf; max_perf = min_perf;
des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf); des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
target_freq = div_u64(des_perf * max_freq, max_perf);
policy->cur = target_freq;
amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true, amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true,
policy->governor->flags); policy->governor->flags);
...@@ -1557,6 +1558,12 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy) ...@@ -1557,6 +1558,12 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
amd_pstate_epp_update_limit(policy); amd_pstate_epp_update_limit(policy);
/*
* policy->cur is never updated with the amd_pstate_epp driver, but it
* is used as a stale frequency value. So, keep it within limits.
*/
policy->cur = policy->min;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment