cpufreq: Iterate over all the possible cpus to create powerstats.
authorRuchi Kandoi <kandoiruchi@google.com>
Sat, 6 Jun 2015 01:21:56 +0000 (18:21 -0700)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 27 Oct 2015 08:27:25 +0000 (16:27 +0800)
For architectures which support a single policy for multiple cpus,
powerstats will not be initalized for all the cores. This change will
make sure powerstats is initialized for all the cores.

Also minor changes to increase code readability.

Bug: 21498425
Change-Id: I938f45e92ff6d5371c32c4d0e37274e6de66769c
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
(cherry picked from commit 5862c50d1970886b5b5a57b5b52ecfd6feb95ebd)

drivers/cpufreq/cpufreq_stats.c

index 4bb1ec49cb27e52a110505f81a1a8d897fee1bc9..2433e404721aa48d7094e03a30526096e79de8bf 100644 (file)
@@ -604,7 +604,7 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
        int ret, count = 0, i;
        struct cpufreq_policy *policy = data;
        struct cpufreq_frequency_table *table;
-       unsigned int cpu = policy->cpu;
+       unsigned int cpu_num, cpu = policy->cpu;
 
        if (val == CPUFREQ_UPDATE_POLICY_CPU) {
                cpufreq_stats_update_policy_cpu(policy);
@@ -628,8 +628,10 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
        if (!per_cpu(all_cpufreq_stats, cpu))
                cpufreq_allstats_create(cpu, table, count);
 
-       if (!per_cpu(cpufreq_power_stats, cpu))
-               cpufreq_powerstats_create(cpu, table, count);
+       for_each_possible_cpu(cpu_num) {
+               if (!per_cpu(cpufreq_power_stats, cpu_num))
+                       cpufreq_powerstats_create(cpu_num, table, count);
+       }
 
        ret = cpufreq_stats_create_table(policy, table, count);
        if (ret)
@@ -677,7 +679,7 @@ static int cpufreq_stats_create_table_cpu(unsigned int cpu)
 {
        struct cpufreq_policy *policy;
        struct cpufreq_frequency_table *table;
-       int ret = -ENODEV, i, count = 0;
+       int i, count, cpu_num, ret = -ENODEV;
 
        policy = cpufreq_cpu_get(cpu);
        if (!policy)
@@ -687,19 +689,21 @@ static int cpufreq_stats_create_table_cpu(unsigned int cpu)
        if (!table)
                goto out;
 
+       count = 0;
        for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
                unsigned int freq = table[i].frequency;
 
-               if (freq == CPUFREQ_ENTRY_INVALID)
-                       continue;
-               count++;
+               if (freq != CPUFREQ_ENTRY_INVALID)
+                       count++;
        }
 
        if (!per_cpu(all_cpufreq_stats, cpu))
                cpufreq_allstats_create(cpu, table, count);
 
-       if (!per_cpu(cpufreq_power_stats, cpu))
-               cpufreq_powerstats_create(cpu, table, count);
+       for_each_possible_cpu(cpu_num) {
+               if (!per_cpu(cpufreq_power_stats, cpu_num))
+                       cpufreq_powerstats_create(cpu_num, table, count);
+       }
 
        ret = cpufreq_stats_create_table(policy, table, count);