Skip to content

Commit 51a5790

Browse files
rafaeljwgregkh
authored andcommitted
cpufreq: intel_pstate: Rearrange show_no_turbo() and store_no_turbo()
[ Upstream commit c626a43 ] Now that global.turbo_disabled can only change at the cpufreq driver registration time, initialize global.no_turbo at that time too so they are in sync to start with (if the former is set, the latter cannot be updated later anyway). That allows show_no_turbo() to be simlified because it does not need to check global.turbo_disabled and store_no_turbo() can be rearranged to avoid doing anything if the new value of global.no_turbo is equal to the current one and only return an error on attempts to clear global.no_turbo when global.turbo_disabled. While at it, eliminate the redundant ret variable from store_no_turbo(). No intentional functional impact. 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 4907546 commit 51a5790

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

drivers/cpufreq/intel_pstate.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
12301230
return -EAGAIN;
12311231
}
12321232

1233-
if (global.turbo_disabled)
1234-
ret = sprintf(buf, "%u\n", global.turbo_disabled);
1235-
else
1236-
ret = sprintf(buf, "%u\n", global.no_turbo);
1233+
ret = sprintf(buf, "%u\n", global.no_turbo);
12371234

12381235
mutex_unlock(&intel_pstate_driver_lock);
12391236

@@ -1244,31 +1241,34 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12441241
const char *buf, size_t count)
12451242
{
12461243
unsigned int input;
1247-
int ret;
1244+
bool no_turbo;
12481245

1249-
ret = sscanf(buf, "%u", &input);
1250-
if (ret != 1)
1246+
if (sscanf(buf, "%u", &input) != 1)
12511247
return -EINVAL;
12521248

12531249
mutex_lock(&intel_pstate_driver_lock);
12541250

12551251
if (!intel_pstate_driver) {
1256-
mutex_unlock(&intel_pstate_driver_lock);
1257-
return -EAGAIN;
1252+
count = -EAGAIN;
1253+
goto unlock_driver;
12581254
}
12591255

1260-
mutex_lock(&intel_pstate_limits_lock);
1256+
no_turbo = !!clamp_t(int, input, 0, 1);
1257+
1258+
if (no_turbo == global.no_turbo)
1259+
goto unlock_driver;
12611260

12621261
if (global.turbo_disabled) {
12631262
pr_notice_once("Turbo disabled by BIOS or unavailable on processor\n");
1264-
mutex_unlock(&intel_pstate_limits_lock);
1265-
mutex_unlock(&intel_pstate_driver_lock);
1266-
return -EPERM;
1263+
count = -EPERM;
1264+
goto unlock_driver;
12671265
}
12681266

1269-
global.no_turbo = clamp_t(int, input, 0, 1);
1267+
global.no_turbo = no_turbo;
1268+
1269+
mutex_lock(&intel_pstate_limits_lock);
12701270

1271-
if (global.no_turbo) {
1271+
if (no_turbo) {
12721272
struct cpudata *cpu = all_cpu_data[0];
12731273
int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate;
12741274

@@ -1280,8 +1280,9 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12801280
mutex_unlock(&intel_pstate_limits_lock);
12811281

12821282
intel_pstate_update_policies();
1283-
arch_set_max_freq_ratio(global.no_turbo);
1283+
arch_set_max_freq_ratio(no_turbo);
12841284

1285+
unlock_driver:
12851286
mutex_unlock(&intel_pstate_driver_lock);
12861287

12871288
return count;
@@ -3078,6 +3079,7 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
30783079
memset(&global, 0, sizeof(global));
30793080
global.max_perf_pct = 100;
30803081
global.turbo_disabled = turbo_is_disabled();
3082+
global.no_turbo = global.turbo_disabled;
30813083

30823084
arch_set_max_freq_ratio(global.turbo_disabled);
30833085

0 commit comments

Comments
 (0)