Commit 3853c737 authored by Lifeng Zheng's avatar Lifeng Zheng
Browse files

cpufreq: Introduce a more generic way to set default per-policy boost flag

mainline inclusion
from mainline-v6.7-rc5
commit dd016f379ebc2d43a9405742d1a6066577509bd7
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQYEH
CVE: NA

Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=dd016f379ebc2d43a9405742d1a6066577509bd7



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

In cpufreq_online() of cpufreq.c, the per-policy boost flag is already
set to mirror the cpufreq_driver boost during init but using freq_table
to judge if the policy has boost frequency. There are two drawbacks to
this approach:

 1. It doesn't work for the cpufreq drivers that do not use a frequency
    table. For now, acpi-cpufreq and amd-pstate have to enable boost in
    policy initialization. And cppc_cpufreq never set policy to boost
    when going online no matter what the cpufreq_driver boost flag is.

 2. If the CPU goes offline when cpufreq_driver boost is enabled and
    then goes online when cpufreq_driver boost is disabled, the
    per-policy boost flag will incorrectly remain true.

Running set_boost at the end of the online process is a more generic way
for all cpufreq drivers.

Signed-off-by: default avatarLifeng Zheng <zhenglifeng1@huawei.com>
Link: https://patch.msgid.link/20250117101457.1530653-3-zhenglifeng1@huawei.com


Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
[ rjw: Changelog edits ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarXinghai Cen <cenxinghai@h-partners.com>
parent 9876fd09
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -1421,10 +1421,6 @@ static int cpufreq_online(unsigned int cpu)
			goto out_free_policy;
		}

		/* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
		if (cpufreq_boost_enabled() && policy_has_boost_freq(policy))
			policy->boost_enabled = true;

		/*
		 * The initialization has succeeded and the policy is online.
		 * If there is a problem with its frequency table, take it
@@ -1585,6 +1581,18 @@ static int cpufreq_online(unsigned int cpu)
	if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver))
		policy->cdev = of_cpufreq_cooling_register(policy);

	/* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
	if (policy->boost_enabled != cpufreq_boost_enabled()) {
		policy->boost_enabled = cpufreq_boost_enabled();
		ret = cpufreq_driver->set_boost(policy, policy->boost_enabled);
		if (ret) {
			/* If the set_boost fails, the online operation is not affected */
			pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu,
				policy->boost_enabled ? "enable" : "disable");
			policy->boost_enabled = !policy->boost_enabled;
		}
	}

	pr_debug("initialization complete\n");

	return 0;