Commit 0137ef5a authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Jia, Yingbao
Browse files

cpufreq: intel_pstate: Rearrange show_no_turbo() and store_no_turbo()

mainline inclusion
from mainline-v6.10
commit c626a438452079824139f97137f17af47b1a8989
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/IB6QC4
CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c626a438452079824139f97137f17af47b1a8989



-------------------------------------------------

Intel-SIG: commit c626a4384520 cpufreq: intel_pstate: Rearrange show_no_turbo() and store_no_turbo().
Backport intel_pstate driver update for 6.6 from 6.11

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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
[ Yingbao Jia: amend commit log ]
Signed-off-by: default avatarYingbao Jia <yingbao.jia@intel.com>
parent 86ccb129
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -1258,9 +1258,6 @@ static ssize_t show_no_turbo(struct kobject *kobj,
		return -EAGAIN;
	}

	if (global.turbo_disabled)
		ret = sprintf(buf, "%u\n", global.turbo_disabled);
	else
	ret = sprintf(buf, "%u\n", global.no_turbo);

	mutex_unlock(&intel_pstate_driver_lock);
@@ -1272,31 +1269,34 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
			      const char *buf, size_t count)
{
	unsigned int input;
	int ret;
	bool no_turbo;

	ret = sscanf(buf, "%u", &input);
	if (ret != 1)
	if (sscanf(buf, "%u", &input) != 1)
		return -EINVAL;

	mutex_lock(&intel_pstate_driver_lock);

	if (!intel_pstate_driver) {
		mutex_unlock(&intel_pstate_driver_lock);
		return -EAGAIN;
		count = -EAGAIN;
		goto unlock_driver;
	}

	mutex_lock(&intel_pstate_limits_lock);
	no_turbo = !!clamp_t(int, input, 0, 1);

	if (no_turbo == global.no_turbo)
		goto unlock_driver;

	if (global.turbo_disabled) {
		pr_notice_once("Turbo disabled by BIOS or unavailable on processor\n");
		mutex_unlock(&intel_pstate_limits_lock);
		mutex_unlock(&intel_pstate_driver_lock);
		return -EPERM;
		count = -EPERM;
		goto unlock_driver;
	}

	global.no_turbo = clamp_t(int, input, 0, 1);
	global.no_turbo = no_turbo;

	mutex_lock(&intel_pstate_limits_lock);

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

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

	intel_pstate_update_policies();
	arch_set_max_freq_ratio(global.no_turbo);
	arch_set_max_freq_ratio(no_turbo);

unlock_driver:
	mutex_unlock(&intel_pstate_driver_lock);

	return count;
@@ -3093,6 +3094,7 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
	memset(&global, 0, sizeof(global));
	global.max_perf_pct = 100;
	global.turbo_disabled = turbo_is_disabled();
	global.no_turbo = global.turbo_disabled;

	arch_set_max_freq_ratio(global.turbo_disabled);