cpufreq: create cpufreq_table_count_valid_entries()

We need such a routine at two places already, lets create one.

Signed-off-by: Viresh Kumar <[email protected]>
Reviewed-by: Lukasz Luba <[email protected]>
Tested-by: Lukasz Luba <[email protected]>
Signed-off-by: Eduardo Valentin <[email protected]>
This commit is contained in:
Viresh Kumar 2017-04-25 15:57:15 +05:30 • committed by Eduardo Valentin
commit 55d8529313
3 changed files with 27 additions and 22 deletions

View file

@ -170,11 +170,10 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
unsigned int i = 0, count = 0, ret = -ENOMEM;
struct cpufreq_stats *stats;
unsigned int alloc_size;
struct cpufreq_frequency_table *pos, *table;
struct cpufreq_frequency_table *pos;
/* We need cpufreq table for creating stats table */
table = policy->freq_table;
if (unlikely(!table))
count = cpufreq_table_count_valid_entries(policy);
if (!count)
return;
/* stats already initialized */
@ -185,10 +184,6 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
if (!stats)
return;
/* Find total allocation size */
cpufreq_for_each_valid_entry(pos, table)
count++;
alloc_size = count * sizeof(int) + count * sizeof(u64);
alloc_size += count * count * sizeof(int);
@ -205,7 +200,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
stats->max_state = count;
/* Find valid-unique entries */
cpufreq_for_each_valid_entry(pos, table)
cpufreq_for_each_valid_entry(pos, policy->freq_table)
if (freq_table_get_index(stats, pos->frequency) == -1)
stats->freq_table[i++] = pos->frequency;