Skip to content

Commit 6f0b13f

Browse files
committed
cpufreq/amd-pstate: Overhaul locking
amd_pstate_cpu_boost_update() and refresh_frequency_limits() both update the policy state and have nothing to do with the amd-pstate driver itself. A global "limits" lock doesn't make sense because each CPU can have policies changed independently. Each time a CPU changes values they will atomically be written to the per-CPU perf member. Drop per CPU locking cases. The remaining "global" driver lock is used to ensure that only one entity can change driver modes at a given time. Reviewed-by: Gautham R. Shenoy <[email protected]> Reviewed-by: Dhananjay Ugwekar <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent 009d1c2 commit 6f0b13f

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
196196
return -EINVAL;
197197
}
198198

199-
static DEFINE_MUTEX(amd_pstate_limits_lock);
200199
static DEFINE_MUTEX(amd_pstate_driver_lock);
201200

202201
static u8 msr_get_epp(struct amd_cpudata *cpudata)
@@ -752,7 +751,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
752751
pr_err("Boost mode is not supported by this processor or SBIOS\n");
753752
return -EOPNOTSUPP;
754753
}
755-
guard(mutex)(&amd_pstate_driver_lock);
756754

757755
ret = amd_pstate_cpu_boost_update(policy, state);
758756
refresh_frequency_limits(policy);
@@ -1170,8 +1168,6 @@ static ssize_t store_energy_performance_preference(
11701168
if (ret < 0)
11711169
return -EINVAL;
11721170

1173-
guard(mutex)(&amd_pstate_limits_lock);
1174-
11751171
ret = amd_pstate_set_energy_pref_index(policy, ret);
11761172

11771173
return ret ? ret : count;
@@ -1344,8 +1340,10 @@ int amd_pstate_update_status(const char *buf, size_t size)
13441340
if (mode_idx < 0 || mode_idx >= AMD_PSTATE_MAX)
13451341
return -EINVAL;
13461342

1347-
if (mode_state_machine[cppc_state][mode_idx])
1343+
if (mode_state_machine[cppc_state][mode_idx]) {
1344+
guard(mutex)(&amd_pstate_driver_lock);
13481345
return mode_state_machine[cppc_state][mode_idx](mode_idx);
1346+
}
13491347

13501348
return 0;
13511349
}
@@ -1366,7 +1364,6 @@ static ssize_t status_store(struct device *a, struct device_attribute *b,
13661364
char *p = memchr(buf, '\n', count);
13671365
int ret;
13681366

1369-
guard(mutex)(&amd_pstate_driver_lock);
13701367
ret = amd_pstate_update_status(buf, p ? p - buf : count);
13711368

13721369
return ret < 0 ? ret : count;
@@ -1638,8 +1635,6 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
16381635
if (cpudata->suspended)
16391636
return 0;
16401637

1641-
guard(mutex)(&amd_pstate_limits_lock);
1642-
16431638
if (trace_amd_pstate_epp_perf_enabled()) {
16441639
trace_amd_pstate_epp_perf(cpudata->cpu, perf.highest_perf,
16451640
AMD_CPPC_EPP_BALANCE_POWERSAVE,
@@ -1679,8 +1674,6 @@ static int amd_pstate_epp_resume(struct cpufreq_policy *policy)
16791674
struct amd_cpudata *cpudata = policy->driver_data;
16801675

16811676
if (cpudata->suspended) {
1682-
guard(mutex)(&amd_pstate_limits_lock);
1683-
16841677
/* enable amd pstate from suspend state*/
16851678
amd_pstate_epp_reenable(policy);
16861679

0 commit comments

Comments
 (0)