[COMMON] thermal: cpu_cooling: calculate power by online cpus
authorEunseok Choi <es10.choi@samsung.com>
Thu, 9 Nov 2017 13:07:26 +0000 (22:07 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:22:06 +0000 (17:22 +0900)
Resolved migration conflicts from kernel 4.9 to 4.14.
- allowed_cpus -> policy->related_cpus

Change-Id: I82b186566d40f75f654393cb655f17d4c15dbcfb
Signed-off-by: Eunseok Choi <es10.choi@samsung.com>
drivers/thermal/cpu_cooling.c

index 70fe51e2d9802956432feadae99b78b85591ab5d..aa49fd3f8763795b5f6b6ed02a6e83123b1f5202 100644 (file)
@@ -374,11 +374,10 @@ static int lookup_static_power(struct cpufreq_cooling_device *cpufreq_cdev,
        int num_cpus;
        int max_cpus;
        struct cpufreq_policy *policy = cpufreq_cdev->policy;
-       struct cpumask *cpumask = policy->related_cpus;
        cpumask_t tempmask;
 
-       cpumask_and(&tempmask, cpumask, cpu_online_mask);
-       max_cpus = cpumask_weight(cpumask);
+       cpumask_and(&tempmask, policy->related_cpus, cpu_online_mask);
+       max_cpus = cpumask_weight(policy->related_cpus);
        num_cpus = cpumask_weight(&tempmask);
        voltage = voltage / 1000;
        temperature  = temperature / 1000;
@@ -410,7 +409,7 @@ static int lookup_static_power(struct cpufreq_cooling_device *cpufreq_cdev,
                temp_index = cpufreq_cdev->var_temp_size;
 
        index = (int)(volt_index * (cpufreq_cdev->var_temp_size + 1) + temp_index);
-       *power = (unsigned int)cpufreq_cdev->var_table[index] * num_cpus / max_cpus;
+       *power = (unsigned int)cpufreq_cdev->var_table[index];
 
        return 0;
 }
@@ -494,9 +493,11 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev,
        struct dev_pm_opp *opp;
        unsigned long voltage;
        struct cpufreq_policy *policy = cpufreq_cdev->policy;
-       struct cpumask *cpumask = policy->related_cpus;
        unsigned long freq_hz = freq * 1000;
        struct device *dev;
+       cpumask_t tempmask;
+       int num_cpus, max_cpus;
+       u32 raw_cpu_power;
 
        *power = 0;
 
@@ -519,7 +520,15 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev,
                return -EINVAL;
        }
 
-       return lookup_static_power(cpufreq_cdev, voltage, tz->temperature, power);
+       lookup_static_power(cpufreq_cdev, voltage, tz->temperature, &raw_cpu_power);
+
+       cpumask_and(&tempmask, policy->related_cpus, cpu_online_mask);
+       num_cpus = cpumask_weight(&tempmask);
+       max_cpus = cpumask_weight(policy->related_cpus);
+
+       *power = (raw_cpu_power * (num_cpus + 1)) / (max_cpus + 1);
+
+       return 0;
 }
 
 /**