Skip to content

Commit

Permalink
cpufreq: handle calls to ->target_index() in separate routine
Browse files Browse the repository at this point in the history
Handling calls to ->target_index() has got complex over time and might become
more complex. So, its better to take target_index() bits out in another routine
__target_index() for better code readability. Shouldn't have any functional
impact.

Tested-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Viresh Kumar authored and Rafael J. Wysocki committed May 28, 2014
1 parent 1ef546f commit 8d65775
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1816,12 +1816,43 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier);
* GOVERNORS *
*********************************************************************/

static int __target_index(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *freq_table, int index)
{
struct cpufreq_freqs freqs;
int retval = -EINVAL;
bool notify;

notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);

if (notify) {
freqs.old = policy->cur;
freqs.new = freq_table[index].frequency;
freqs.flags = 0;

pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
__func__, policy->cpu, freqs.old, freqs.new);

cpufreq_freq_transition_begin(policy, &freqs);
}

retval = cpufreq_driver->target_index(policy, index);
if (retval)
pr_err("%s: Failed to change cpu frequency: %d\n", __func__,
retval);

if (notify)
cpufreq_freq_transition_end(policy, &freqs, retval);

return retval;
}

int __cpufreq_driver_target(struct cpufreq_policy *policy,
unsigned int target_freq,
unsigned int relation)
{
int retval = -EINVAL;
unsigned int old_target_freq = target_freq;
int retval = -EINVAL;

if (cpufreq_disabled())
return -ENODEV;
Expand All @@ -1848,8 +1879,6 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
retval = cpufreq_driver->target(policy, target_freq, relation);
else if (cpufreq_driver->target_index) {
struct cpufreq_frequency_table *freq_table;
struct cpufreq_freqs freqs;
bool notify;
int index;

freq_table = cpufreq_frequency_get_table(policy->cpu);
Expand All @@ -1870,26 +1899,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
goto out;
}

notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);

if (notify) {
freqs.old = policy->cur;
freqs.new = freq_table[index].frequency;
freqs.flags = 0;

pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
__func__, policy->cpu, freqs.old, freqs.new);

cpufreq_freq_transition_begin(policy, &freqs);
}

retval = cpufreq_driver->target_index(policy, index);
if (retval)
pr_err("%s: Failed to change cpu frequency: %d\n",
__func__, retval);

if (notify)
cpufreq_freq_transition_end(policy, &freqs, retval);
retval = __target_index(policy, freq_table, index);
}

out:
Expand Down

0 comments on commit 8d65775

Please sign in to comment.