Skip to content

Commit 9558fae

Browse files
committed
cpufreq: intel_pstate: Read global.no_turbo under READ_ONCE()
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 <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]>
1 parent c626a43 commit 9558fae

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12961296
goto unlock_driver;
12971297
}
12981298

1299-
global.no_turbo = no_turbo;
1299+
WRITE_ONCE(global.no_turbo, no_turbo);
13001300

13011301
mutex_lock(&intel_pstate_limits_lock);
13021302

@@ -1748,7 +1748,7 @@ static u64 atom_get_val(struct cpudata *cpudata, int pstate)
17481748
u32 vid;
17491749

17501750
val = (u64)pstate << 8;
1751-
if (global.no_turbo && !global.turbo_disabled)
1751+
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
17521752
val |= (u64)1 << 32;
17531753

17541754
vid_fp = cpudata->vid.min + mul_fp(
@@ -1913,7 +1913,7 @@ static u64 core_get_val(struct cpudata *cpudata, int pstate)
19131913
u64 val;
19141914

19151915
val = (u64)pstate << 8;
1916-
if (global.no_turbo && !global.turbo_disabled)
1916+
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
19171917
val |= (u64)1 << 32;
19181918

19191919
return val;
@@ -2211,7 +2211,7 @@ static inline int32_t get_target_pstate(struct cpudata *cpu)
22112211

22122212
sample->busy_scaled = busy_frac * 100;
22132213

2214-
target = global.no_turbo || global.turbo_disabled ?
2214+
target = READ_ONCE(global.no_turbo) ?
22152215
cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
22162216
target += target >> 2;
22172217
target = mul_fp(target, busy_frac);
@@ -2473,7 +2473,7 @@ static void intel_pstate_clear_update_util_hook(unsigned int cpu)
24732473

24742474
static int intel_pstate_get_max_freq(struct cpudata *cpu)
24752475
{
2476-
return global.turbo_disabled || global.no_turbo ?
2476+
return READ_ONCE(global.no_turbo) ?
24772477
cpu->pstate.max_freq : cpu->pstate.turbo_freq;
24782478
}
24792479

@@ -2610,7 +2610,7 @@ static void intel_pstate_verify_cpu_policy(struct cpudata *cpu,
26102610

26112611
if (hwp_active) {
26122612
intel_pstate_get_hwp_cap(cpu);
2613-
max_freq = global.no_turbo || global.turbo_disabled ?
2613+
max_freq = READ_ONCE(global.no_turbo) ?
26142614
cpu->pstate.max_freq : cpu->pstate.turbo_freq;
26152615
} else {
26162616
max_freq = intel_pstate_get_max_freq(cpu);

0 commit comments

Comments
 (0)