Skip to content

Commit a44d090

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 524ee26 commit a44d090

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
@@ -1263,10 +1263,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
12631263
return -EAGAIN;
12641264
}
12651265

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

12711268
mutex_unlock(&intel_pstate_driver_lock);
12721269

@@ -1277,31 +1274,34 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12771274
const char *buf, size_t count)
12781275
{
12791276
unsigned int input;
1280-
int ret;
1277+
bool no_turbo;
12811278

1282-
ret = sscanf(buf, "%u", &input);
1283-
if (ret != 1)
1279+
if (sscanf(buf, "%u", &input) != 1)
12841280
return -EINVAL;
12851281

12861282
mutex_lock(&intel_pstate_driver_lock);
12871283

12881284
if (!intel_pstate_driver) {
1289-
mutex_unlock(&intel_pstate_driver_lock);
1290-
return -EAGAIN;
1285+
count = -EAGAIN;
1286+
goto unlock_driver;
12911287
}
12921288

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

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

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

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

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

13151315
intel_pstate_update_policies();
1316-
arch_set_max_freq_ratio(global.no_turbo);
1316+
arch_set_max_freq_ratio(no_turbo);
13171317

1318+
unlock_driver:
13181319
mutex_unlock(&intel_pstate_driver_lock);
13191320

13201321
return count;
@@ -3113,6 +3114,7 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
31133114
memset(&global, 0, sizeof(global));
31143115
global.max_perf_pct = 100;
31153116
global.turbo_disabled = turbo_is_disabled();
3117+
global.no_turbo = global.turbo_disabled;
31163118

31173119
arch_set_max_freq_ratio(global.turbo_disabled);
31183120

0 commit comments

Comments
 (0)