Skip to content

Commit c626a43

Browse files
committed
cpufreq: intel_pstate: Rearrange show_no_turbo() and store_no_turbo()
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 <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]>
1 parent 0940f1a commit c626a43

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,10 +1262,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
12621262
return -EAGAIN;
12631263
}
12641264

1265-
if (global.turbo_disabled)
1266-
ret = sprintf(buf, "%u\n", global.turbo_disabled);
1267-
else
1268-
ret = sprintf(buf, "%u\n", global.no_turbo);
1265+
ret = sprintf(buf, "%u\n", global.no_turbo);
12691266

12701267
mutex_unlock(&intel_pstate_driver_lock);
12711268

@@ -1276,31 +1273,34 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12761273
const char *buf, size_t count)
12771274
{
12781275
unsigned int input;
1279-
int ret;
1276+
bool no_turbo;
12801277

1281-
ret = sscanf(buf, "%u", &input);
1282-
if (ret != 1)
1278+
if (sscanf(buf, "%u", &input) != 1)
12831279
return -EINVAL;
12841280

12851281
mutex_lock(&intel_pstate_driver_lock);
12861282

12871283
if (!intel_pstate_driver) {
1288-
mutex_unlock(&intel_pstate_driver_lock);
1289-
return -EAGAIN;
1284+
count = -EAGAIN;
1285+
goto unlock_driver;
12901286
}
12911287

1292-
mutex_lock(&intel_pstate_limits_lock);
1288+
no_turbo = !!clamp_t(int, input, 0, 1);
1289+
1290+
if (no_turbo == global.no_turbo)
1291+
goto unlock_driver;
12931292

12941293
if (global.turbo_disabled) {
12951294
pr_notice_once("Turbo disabled by BIOS or unavailable on processor\n");
1296-
mutex_unlock(&intel_pstate_limits_lock);
1297-
mutex_unlock(&intel_pstate_driver_lock);
1298-
return -EPERM;
1295+
count = -EPERM;
1296+
goto unlock_driver;
12991297
}
13001298

1301-
global.no_turbo = clamp_t(int, input, 0, 1);
1299+
global.no_turbo = no_turbo;
1300+
1301+
mutex_lock(&intel_pstate_limits_lock);
13021302

1303-
if (global.no_turbo) {
1303+
if (no_turbo) {
13041304
struct cpudata *cpu = all_cpu_data[0];
13051305
int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate;
13061306

@@ -1312,8 +1312,9 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
13121312
mutex_unlock(&intel_pstate_limits_lock);
13131313

13141314
intel_pstate_update_policies();
1315-
arch_set_max_freq_ratio(global.no_turbo);
1315+
arch_set_max_freq_ratio(no_turbo);
13161316

1317+
unlock_driver:
13171318
mutex_unlock(&intel_pstate_driver_lock);
13181319

13191320
return count;
@@ -3094,6 +3095,7 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
30943095
memset(&global, 0, sizeof(global));
30953096
global.max_perf_pct = 100;
30963097
global.turbo_disabled = turbo_is_disabled();
3098+
global.no_turbo = global.turbo_disabled;
30973099

30983100
arch_set_max_freq_ratio(global.turbo_disabled);
30993101

0 commit comments

Comments
 (0)