Skip to content

Commit f227c2f

Browse files
rafaeljwgregkh
authored andcommitted
cpufreq: intel_pstate: Read global.no_turbo under READ_ONCE()
[ Upstream commit 9558fae ] Because global.no_turbo is generally not read under intel_pstate_driver_lock make store_no_turbo() use WRITE_ONCE() for updating it (this is the only place at which it is updated except for the initialization) and make the majority of places reading it use READ_ONCE(). Also remove redundant global.turbo_disabled checks from places that depend on the 'true' value of global.no_turbo because it can only be 'true' if global.turbo_disabled is also 'true'. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Stable-dep-of: 350cbb5 ("cpufreq: intel_pstate: Check turbo_is_disabled() in store_no_turbo()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 51a5790 commit f227c2f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/cpufreq/intel_pstate.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12641264
goto unlock_driver;
12651265
}
12661266

1267-
global.no_turbo = no_turbo;
1267+
WRITE_ONCE(global.no_turbo, no_turbo);
12681268

12691269
mutex_lock(&intel_pstate_limits_lock);
12701270

@@ -1730,7 +1730,7 @@ static u64 atom_get_val(struct cpudata *cpudata, int pstate)
17301730
u32 vid;
17311731

17321732
val = (u64)pstate << 8;
1733-
if (global.no_turbo && !global.turbo_disabled)
1733+
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
17341734
val |= (u64)1 << 32;
17351735

17361736
vid_fp = cpudata->vid.min + mul_fp(
@@ -1900,7 +1900,7 @@ static u64 core_get_val(struct cpudata *cpudata, int pstate)
19001900
u64 val;
19011901

19021902
val = (u64)pstate << 8;
1903-
if (global.no_turbo && !global.turbo_disabled)
1903+
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
19041904
val |= (u64)1 << 32;
19051905

19061906
return val;
@@ -2186,7 +2186,7 @@ static inline int32_t get_target_pstate(struct cpudata *cpu)
21862186

21872187
sample->busy_scaled = busy_frac * 100;
21882188

2189-
target = global.no_turbo || global.turbo_disabled ?
2189+
target = READ_ONCE(global.no_turbo) ?
21902190
cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
21912191
target += target >> 2;
21922192
target = mul_fp(target, busy_frac);
@@ -2455,7 +2455,7 @@ static void intel_pstate_clear_update_util_hook(unsigned int cpu)
24552455

24562456
static int intel_pstate_get_max_freq(struct cpudata *cpu)
24572457
{
2458-
return global.turbo_disabled || global.no_turbo ?
2458+
return READ_ONCE(global.no_turbo) ?
24592459
cpu->pstate.max_freq : cpu->pstate.turbo_freq;
24602460
}
24612461

@@ -2592,7 +2592,7 @@ static void intel_pstate_verify_cpu_policy(struct cpudata *cpu,
25922592

25932593
if (hwp_active) {
25942594
intel_pstate_get_hwp_cap(cpu);
2595-
max_freq = global.no_turbo || global.turbo_disabled ?
2595+
max_freq = READ_ONCE(global.no_turbo) ?
25962596
cpu->pstate.max_freq : cpu->pstate.turbo_freq;
25972597
} else {
25982598
max_freq = intel_pstate_get_max_freq(cpu);

0 commit comments

Comments
 (0)