Skip to content

Commit

Permalink
cpufreq: Consolidate cpufreq_update_current_freq() and __cpufreq_get()
Browse files Browse the repository at this point in the history
Their implementations are quite similar, so modify
cpufreq_update_current_freq() somewhat and call it from
__cpufreq_get().

Also rename cpufreq_update_current_freq() to
cpufreq_verify_current_freq(), as that's what it is doing.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Subject & changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Viresh Kumar authored and Rafael J. Wysocki committed Jun 28, 2019
1 parent 9801522 commit 5980752
Showing 1 changed file with 28 additions and 42 deletions.
70 changes: 28 additions & 42 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,30 @@ static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
cpufreq_freq_transition_end(policy, &freqs, 0);
}

static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update)
{
unsigned int new_freq;

new_freq = cpufreq_driver->get(policy->cpu);
if (!new_freq)
return 0;

/*
* If fast frequency switching is used with the given policy, the check
* against policy->cur is pointless, so skip it in that case.
*/
if (policy->fast_switch_enabled || !has_target())
return new_freq;

if (policy->cur != new_freq) {
cpufreq_out_of_sync(policy, new_freq);
if (update)
schedule_work(&policy->update);
}

return new_freq;
}

/**
* cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
* @cpu: CPU number
Expand Down Expand Up @@ -1600,30 +1624,10 @@ EXPORT_SYMBOL(cpufreq_quick_get_max);

static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
{
unsigned int ret_freq = 0;

if (unlikely(policy_is_inactive(policy)))
return ret_freq;

ret_freq = cpufreq_driver->get(policy->cpu);

/*
* If fast frequency switching is used with the given policy, the check
* against policy->cur is pointless, so skip it in that case too.
*/
if (policy->fast_switch_enabled)
return ret_freq;

if (has_target() && ret_freq && policy->cur) {
/* verify no discrepancy between actual and
saved value exists */
if (unlikely(ret_freq != policy->cur)) {
cpufreq_out_of_sync(policy, ret_freq);
schedule_work(&policy->update);
}
}
return 0;

return ret_freq;
return cpufreq_verify_current_freq(policy, true);
}

/**
Expand All @@ -1650,24 +1654,6 @@ unsigned int cpufreq_get(unsigned int cpu)
}
EXPORT_SYMBOL(cpufreq_get);

static unsigned int cpufreq_update_current_freq(struct cpufreq_policy *policy)
{
unsigned int new_freq;

new_freq = cpufreq_driver->get(policy->cpu);
if (!new_freq)
return 0;

if (!policy->cur) {
pr_debug("cpufreq: Driver did not initialize current freq\n");
policy->cur = new_freq;
} else if (policy->cur != new_freq && has_target()) {
cpufreq_out_of_sync(policy, new_freq);
}

return new_freq;
}

static struct subsys_interface cpufreq_interface = {
.name = "cpufreq",
.subsys = &cpu_subsys,
Expand Down Expand Up @@ -2149,7 +2135,7 @@ static int cpufreq_start_governor(struct cpufreq_policy *policy)
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);

if (cpufreq_driver->get)
cpufreq_update_current_freq(policy);
cpufreq_verify_current_freq(policy, false);

if (policy->governor->start) {
ret = policy->governor->start(policy);
Expand Down Expand Up @@ -2400,7 +2386,7 @@ void cpufreq_update_policy(unsigned int cpu)
* -> ask driver for current freq and notify governors about a change
*/
if (cpufreq_driver->get && has_target() &&
(cpufreq_suspended || WARN_ON(!cpufreq_update_current_freq(policy))))
(cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
goto unlock;

pr_debug("updating policy for CPU %u\n", cpu);
Expand Down

0 comments on commit 5980752

Please sign in to comment.