]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cpufreq: Introduce cpufreq_policy_refresh()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Mar 2025 20:47:31 +0000 (21:47 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 9 Apr 2025 19:22:16 +0000 (21:22 +0200)
Since cpufreq_update_limits() obtains a cpufreq policy pointer for the
given CPU and reference counts the object pointed to by it, calling
cpufreq_update_policy() from cpufreq_update_limits() is somewhat
wasteful because that function calls cpufreq_cpu_get() on the same
CPU again.

To avoid that unnecessary overhead, move the part of the code running
under the policy rwsem from cpufreq_update_policy() to a new function
called cpufreq_policy_refresh() and invoke that new function from
both cpufreq_update_policy() and cpufreq_update_limits().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://patch.msgid.link/6047110.MhkbZ0Pkbq@rjwysocki.net
drivers/cpufreq/cpufreq.c

index 29130aa1b09a1f2c2bd499d72c3efcc200dda74a..c885e0ec174ff6090f85884cc13132f6c9177e9b 100644 (file)
@@ -2717,6 +2717,21 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
        return ret;
 }
 
+static void cpufreq_policy_refresh(struct cpufreq_policy *policy)
+{
+       guard(cpufreq_policy_write)(policy);
+
+       /*
+        * BIOS might change freq behind our back
+        * -> ask driver for current freq and notify governors about a change
+        */
+       if (cpufreq_driver->get && has_target() &&
+           (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
+               return;
+
+       refresh_frequency_limits(policy);
+}
+
 /**
  * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
  * @cpu: CPU to re-evaluate the policy for.
@@ -2734,17 +2749,7 @@ void cpufreq_update_policy(unsigned int cpu)
        if (!policy)
                return;
 
-       guard(cpufreq_policy_write)(policy);
-
-       /*
-        * BIOS might change freq behind our back
-        * -> ask driver for current freq and notify governors about a change
-        */
-       if (cpufreq_driver->get && has_target() &&
-           (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
-               return;
-
-       refresh_frequency_limits(policy);
+       cpufreq_policy_refresh(policy);
 }
 EXPORT_SYMBOL(cpufreq_update_policy);
 
@@ -2753,7 +2758,7 @@ EXPORT_SYMBOL(cpufreq_update_policy);
  * @cpu: CPU to update the policy limits for.
  *
  * Invoke the driver's ->update_limits callback if present or call
- * cpufreq_update_policy() for @cpu.
+ * cpufreq_policy_refresh() for @cpu.
  */
 void cpufreq_update_limits(unsigned int cpu)
 {
@@ -2766,7 +2771,7 @@ void cpufreq_update_limits(unsigned int cpu)
        if (cpufreq_driver->update_limits)
                cpufreq_driver->update_limits(cpu);
        else
-               cpufreq_update_policy(cpu);
+               cpufreq_policy_refresh(policy);
 }
 EXPORT_SYMBOL_GPL(cpufreq_update_limits);