2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-16 01:04:08 +08:00

cpufreq: Optimize cpufreq_frequency_table_verify()

cpufreq_frequency_table_verify() is rewritten here to make it more logical
and efficient.
 - merge multiple lines for variable declarations together.
 - quit early if any frequency between min/max is found.
 - don't call cpufreq_verify_within_limits() in case any valid freq is
   found as it is of no use.
 - rename the count variable as found and change its type to boolean.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Viresh Kumar 2013-10-02 14:13:15 +05:30 committed by Rafael J. Wysocki
parent 27a862e983
commit 77db50c4eb

View File

@ -54,9 +54,8 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_cpuinfo);
int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *table) struct cpufreq_frequency_table *table)
{ {
unsigned int next_larger = ~0; unsigned int next_larger = ~0, freq, i = 0;
unsigned int i; bool found = false;
unsigned int count = 0;
pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
policy->min, policy->max, policy->cpu); policy->min, policy->max, policy->cpu);
@ -64,21 +63,23 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
policy->cpuinfo.max_freq); policy->cpuinfo.max_freq);
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) {
unsigned int freq = table[i].frequency;
if (freq == CPUFREQ_ENTRY_INVALID) if (freq == CPUFREQ_ENTRY_INVALID)
continue; continue;
if ((freq >= policy->min) && (freq <= policy->max)) if ((freq >= policy->min) && (freq <= policy->max)) {
count++; found = true;
else if ((next_larger > freq) && (freq > policy->max)) break;
}
if ((next_larger > freq) && (freq > policy->max))
next_larger = freq; next_larger = freq;
} }
if (!count) if (!found) {
policy->max = next_larger; policy->max = next_larger;
cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
policy->cpuinfo.max_freq); }
pr_debug("verification lead to (%u - %u kHz) for cpu %u\n", pr_debug("verification lead to (%u - %u kHz) for cpu %u\n",
policy->min, policy->max, policy->cpu); policy->min, policy->max, policy->cpu);