Skip to content

Commit 9f5daa2

Browse files
committed
cpufreq/amd-pstate: Cache CPPC request in shared mem case too
In order to prevent a potential write for shmem_update_perf() cache the request into the cppc_req_cached variable normally only used for the MSR case. This adds symmetry into the code and potentially avoids extra writes. Reviewed-by: Dhananjay Ugwekar <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent b4cc466 commit 9f5daa2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ static int shmem_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
496496
u8 des_perf, u8 max_perf, u8 epp, bool fast_switch)
497497
{
498498
struct cppc_perf_ctrls perf_ctrls;
499+
u64 value, prev;
500+
int ret;
499501

500502
if (cppc_state == AMD_PSTATE_ACTIVE) {
501503
int ret = shmem_set_epp(cpudata, epp);
@@ -504,11 +506,29 @@ static int shmem_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
504506
return ret;
505507
}
506508

509+
value = prev = READ_ONCE(cpudata->cppc_req_cached);
510+
511+
value &= ~(AMD_CPPC_MAX_PERF_MASK | AMD_CPPC_MIN_PERF_MASK |
512+
AMD_CPPC_DES_PERF_MASK | AMD_CPPC_EPP_PERF_MASK);
513+
value |= FIELD_PREP(AMD_CPPC_MAX_PERF_MASK, max_perf);
514+
value |= FIELD_PREP(AMD_CPPC_DES_PERF_MASK, des_perf);
515+
value |= FIELD_PREP(AMD_CPPC_MIN_PERF_MASK, min_perf);
516+
value |= FIELD_PREP(AMD_CPPC_EPP_PERF_MASK, epp);
517+
518+
if (value == prev)
519+
return 0;
520+
507521
perf_ctrls.max_perf = max_perf;
508522
perf_ctrls.min_perf = min_perf;
509523
perf_ctrls.desired_perf = des_perf;
510524

511-
return cppc_set_perf(cpudata->cpu, &perf_ctrls);
525+
ret = cppc_set_perf(cpudata->cpu, &perf_ctrls);
526+
if (ret)
527+
return ret;
528+
529+
WRITE_ONCE(cpudata->cppc_req_cached, value);
530+
531+
return 0;
512532
}
513533

514534
static inline bool amd_pstate_sample(struct amd_cpudata *cpudata)

0 commit comments

Comments
 (0)