PM / AVS: rockchip-cpu-avs: check initial rate early
authorFinley Xiao <finley.xiao@rock-chips.com>
Sun, 8 Jan 2017 02:11:55 +0000 (10:11 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 9 Jan 2017 02:52:39 +0000 (10:52 +0800)
As merge the commit 388612baba20 ("cpufreq: Send START policy
notification after sending CREATE"), cpufreq stats table is
created earlier. In order to get correct table index, check
initial rate when receive CREATE and START notification events.

Change-Id: I1ccc6d41704ae8c01156103bbd82888e4e37cd0c
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
drivers/power/avs/rockchip-cpu-avs.c

index 93a1720dc37880591dc0b5a11d30725567531882..0f14d6919a9b723f8a5413bf54f75db891a42000 100644 (file)
@@ -47,6 +47,7 @@ struct cluster_info {
        unsigned int min_freq;
        unsigned int min_volt;
        struct leakage_volt_table *table;
+       unsigned int adjust_done;
 };
 
 struct rockchip_cpu_avs {
@@ -108,27 +109,19 @@ static int rockchip_cpu_avs_notifier(struct notifier_block *nb,
        int i, id, cpu = policy->cpu;
        int ret;
 
-       if (event == CPUFREQ_CREATE_POLICY) {
-               for (id = 0; id < MAX_CLUSTERS; id++) {
-                       if (cpumask_test_cpu(policy->cpu,
-                                            &avs->allowed_cpus[id]))
-                               break;
-                       if (cpumask_empty(&avs->allowed_cpus[id])) {
-                               cpumask_copy(&avs->allowed_cpus[id],
-                                            policy->related_cpus);
-                               break;
-                       }
-               }
-               goto out;
-       }
-
-       if (event != CPUFREQ_START)
+       if (event != CPUFREQ_CREATE_POLICY && event  != CPUFREQ_START)
                goto out;
 
        for (id = 0; id < MAX_CLUSTERS; id++) {
                if (cpumask_test_cpu(cpu, &avs->allowed_cpus[id]))
                        break;
+               if (cpumask_empty(&avs->allowed_cpus[id])) {
+                       cpumask_copy(&avs->allowed_cpus[id],
+                                    policy->related_cpus);
+                       break;
+               }
        }
+
        if (id == MAX_CLUSTERS) {
                pr_err("cpu%d invalid cluster id\n", cpu);
                goto out;
@@ -157,7 +150,23 @@ static int rockchip_cpu_avs_notifier(struct notifier_block *nb,
                goto next;
        }
 
-       rockchip_leakage_adjust_table(cpu_dev, policy->freq_table, cluster);
+       /*
+        * First time, CPUFREQ_CREATE_POLICY, adjust talbe
+        * Second time, CPUFREQ_START, no need to adjust again
+        * Later, cpu down and up, CPUFREQ_START, adjust table
+        */
+       if (event == CPUFREQ_CREATE_POLICY) {
+               rockchip_leakage_adjust_table(cpu_dev, policy->freq_table,
+                                             cluster);
+               cluster->adjust_done = 1;
+       } else if (event == CPUFREQ_START) {
+               if (cluster->adjust_done == 1)
+                       cluster->adjust_done = 0;
+               else
+                       rockchip_leakage_adjust_table(cpu_dev,
+                                                     policy->freq_table,
+                                                     cluster);
+       }
 
 next:
        if (avs->check_done[id] == 0) {