[COMMON] theraml: cpu_cooling: Skip util normalize power
authorHyeonseong Gil <hs.gil@samsung.com>
Mon, 16 May 2016 11:37:01 +0000 (20:37 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:12:40 +0000 (17:12 +0900)
Resolved migration conflicts from kernel 4.9 to 4.14.
- rename cpufreq_device -> cpufreq_cdev
- allowed_cpus -> policy->related_cpus

Change-Id: I4dcd4a7d61ec6d7d33b4032dac2e4aaf26e48cf7
Signed-off-by: Hyeonseong Gil <hs.gil@samsung.com>
drivers/thermal/cpu_cooling.c

index 49ceb0394f2e0005dee19287f5d92a9affdf8e67..0a3880b59d6b009ec037ac95b222b3ec36358aca 100644 (file)
@@ -697,12 +697,19 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
                               struct thermal_zone_device *tz, u32 power,
                               unsigned long *state)
 {
-       unsigned int cur_freq, target_freq;
+       unsigned int cpu, cur_freq, target_freq;
        int ret;
        s32 dyn_power;
-       u32 last_load, normalised_power, static_power;
+       u32 normalised_power, static_power;
        struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
        struct cpufreq_policy *policy = cpufreq_cdev->policy;
+       cpumask_t tempmask;
+       int num_cpus;
+
+       cpumask_and(&tempmask, policy->related_cpus, cpu_online_mask);
+       num_cpus = cpumask_weight(&tempmask);
+
+       cpu = cpumask_any_and(policy->related_cpus, cpu_online_mask);
 
        cur_freq = cpufreq_quick_get(policy->cpu);
        ret = get_static_power(cpufreq_cdev, tz, cur_freq, &static_power);
@@ -711,10 +718,17 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
 
        dyn_power = power - static_power;
        dyn_power = dyn_power > 0 ? dyn_power : 0;
-       last_load = cpufreq_cdev->last_load ?: 1;
-       normalised_power = (dyn_power * 100) / last_load;
+       normalised_power = dyn_power / num_cpus;
        target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power);
 
+       *state = cpufreq_cooling_get_level(cpu, target_freq);
+       if (*state == THERMAL_CSTATE_INVALID) {
+               dev_warn_ratelimited(&cdev->device,
+                                    "Failed to convert %dKHz for cpu %d into a cdev state\n",
+                                    target_freq, cpu);
+               return -EINVAL;
+       }
+
        *state = get_level(cpufreq_cdev, target_freq);
        trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state,
                                      power);