Skip to content

Commit 684e185

Browse files
committed
cpufreq: Introduce cpufreq_policy_refresh()
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 <[email protected]> Acked-by: Viresh Kumar <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Acked-by: Sudeep Holla <[email protected]> Tested-by: Sudeep Holla <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent ece898d commit 684e185

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,21 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
27172717
return ret;
27182718
}
27192719

2720+
static void cpufreq_policy_refresh(struct cpufreq_policy *policy)
2721+
{
2722+
guard(cpufreq_policy_write)(policy);
2723+
2724+
/*
2725+
* BIOS might change freq behind our back
2726+
* -> ask driver for current freq and notify governors about a change
2727+
*/
2728+
if (cpufreq_driver->get && has_target() &&
2729+
(cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
2730+
return;
2731+
2732+
refresh_frequency_limits(policy);
2733+
}
2734+
27202735
/**
27212736
* cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
27222737
* @cpu: CPU to re-evaluate the policy for.
@@ -2734,17 +2749,7 @@ void cpufreq_update_policy(unsigned int cpu)
27342749
if (!policy)
27352750
return;
27362751

2737-
guard(cpufreq_policy_write)(policy);
2738-
2739-
/*
2740-
* BIOS might change freq behind our back
2741-
* -> ask driver for current freq and notify governors about a change
2742-
*/
2743-
if (cpufreq_driver->get && has_target() &&
2744-
(cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
2745-
return;
2746-
2747-
refresh_frequency_limits(policy);
2752+
cpufreq_policy_refresh(policy);
27482753
}
27492754
EXPORT_SYMBOL(cpufreq_update_policy);
27502755

@@ -2753,7 +2758,7 @@ EXPORT_SYMBOL(cpufreq_update_policy);
27532758
* @cpu: CPU to update the policy limits for.
27542759
*
27552760
* Invoke the driver's ->update_limits callback if present or call
2756-
* cpufreq_update_policy() for @cpu.
2761+
* cpufreq_policy_refresh() for @cpu.
27572762
*/
27582763
void cpufreq_update_limits(unsigned int cpu)
27592764
{
@@ -2766,7 +2771,7 @@ void cpufreq_update_limits(unsigned int cpu)
27662771
if (cpufreq_driver->update_limits)
27672772
cpufreq_driver->update_limits(cpu);
27682773
else
2769-
cpufreq_update_policy(cpu);
2774+
cpufreq_policy_refresh(policy);
27702775
}
27712776
EXPORT_SYMBOL_GPL(cpufreq_update_limits);
27722777

0 commit comments

Comments
 (0)