cpufreq: Introduce policy_set_boost()
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 24 Apr 2025 16:20:16 +0000 (21:50 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 25 Apr 2025 16:28:22 +0000 (18:28 +0200)
Introduce policy_set_boost() to update boost state of a cpufreq policy.

No intentional function change.

Reviewed-by: Lifeng Zheng <zhenglifeng1@huawei.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://patch.msgid.link/1863178ac17340c810519c8593014b8e561797ea.1745511526.git.viresh.kumar@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 5e6e34e7a5b89c6b93368a2deba0418e9c51fd6d..b4adf4a6f45a95198ad0580f1c349ae1355d49ab 100644 (file)
@@ -588,6 +588,22 @@ static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf)
        return sysfs_emit(buf, "%d\n", policy->boost_enabled);
 }
 
+static int policy_set_boost(struct cpufreq_policy *policy, bool enable)
+{
+       int ret;
+
+       if (policy->boost_enabled == enable)
+               return 0;
+
+       policy->boost_enabled = enable;
+
+       ret = cpufreq_driver->set_boost(policy, enable);
+       if (ret)
+               policy->boost_enabled = !policy->boost_enabled;
+
+       return ret;
+}
+
 static ssize_t store_local_boost(struct cpufreq_policy *policy,
                                 const char *buf, size_t count)
 {
@@ -603,21 +619,14 @@ static ssize_t store_local_boost(struct cpufreq_policy *policy,
        if (!policy->boost_supported)
                return -EINVAL;
 
-       if (policy->boost_enabled == enable)
-               return count;
-
-       policy->boost_enabled = enable;
-
        cpus_read_lock();
-       ret = cpufreq_driver->set_boost(policy, enable);
+       ret = policy_set_boost(policy, enable);
        cpus_read_unlock();
 
-       if (ret) {
-               policy->boost_enabled = !policy->boost_enabled;
-               return ret;
-       }
+       if (!ret)
+               return count;
 
-       return count;
+       return ret;
 }
 
 static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);
@@ -1615,15 +1624,12 @@ static int cpufreq_online(unsigned int cpu)
                policy->cdev = of_cpufreq_cooling_register(policy);
 
        /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
-       if (cpufreq_driver->set_boost && policy->boost_supported &&
-           policy->boost_enabled != cpufreq_boost_enabled()) {
-               policy->boost_enabled = cpufreq_boost_enabled();
-               ret = cpufreq_driver->set_boost(policy, policy->boost_enabled);
+       if (cpufreq_driver->set_boost && policy->boost_supported) {
+               ret = policy_set_boost(policy, cpufreq_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,
-                               str_enable_disable(policy->boost_enabled));
-                       policy->boost_enabled = !policy->boost_enabled;
+                               str_enable_disable(cpufreq_boost_enabled()));
                }
        }
 
@@ -2807,15 +2813,12 @@ static int cpufreq_boost_trigger_state(int state)
 
        cpus_read_lock();
        for_each_active_policy(policy) {
-               if (!policy->boost_supported || policy->boost_enabled == state)
+               if (!policy->boost_supported)
                        continue;
 
-               policy->boost_enabled = state;
-               ret = cpufreq_driver->set_boost(policy, state);
-               if (ret) {
-                       policy->boost_enabled = !policy->boost_enabled;
+               ret = policy_set_boost(policy, state);
+               if (ret)
                        goto err_reset_state;
-               }
        }
        cpus_read_unlock();