sched/power: collect unused power for future split
authorLukasz Luba <l.luba@partner.samsung.com>
Fri, 9 Nov 2018 15:16:49 +0000 (16:16 +0100)
committerLukasz Luba <l.luba@partner.samsung.com>
Fri, 17 May 2019 07:15:53 +0000 (09:15 +0200)
The power which cannot be applied to the cooling device
might be re-used in the next phase.

Signed-off-by: Lukasz Luba <l.luba@partner.samsung.com>
kernel/sched/power.c

index b0e103695fa27440074f9d523c718b50499315b8..a630f4a532ef30f8cdff0a8fadd1904e7fe361e8 100644 (file)
@@ -642,6 +642,7 @@ static int cooling_dev_set_state(struct _thermal_zone *zone,
 {
        struct thermal_cooling_device *cdev = cooling->cdev;
        unsigned long curr_state;
+       int ret = 0;
 
        cdev->ops->get_cur_state(cdev, &curr_state);
 
@@ -658,11 +659,13 @@ static int cooling_dev_set_state(struct _thermal_zone *zone,
        mutex_lock(&cdev->lock);
        if (!cdev->ops->set_cur_state(cdev, target))
                thermal_cooling_device_stats_update(cdev, target);
+       else
+               ret = -EINVAL;
 
        cdev->updated = true;
        mutex_unlock(&cdev->lock);
 
-       return 0;
+       return ret;
 }
 
 static int _set_power(struct _cooling_instance *inst, struct _thermal_zone *zone,
@@ -675,6 +678,8 @@ static int _set_power(struct _cooling_instance *inst, struct _thermal_zone *zone
 
        cdev = inst->cooling->cdev;
        ret = cdev->ops->power2state(cdev, tz, power, &state);
+       if (ret)
+               return ret;
 
        pr_info("inst_weight=%u, set_power=%u, state=%lu, temp=%d\n",
                inst->weight, power, state, tz->temperature);
@@ -788,7 +793,13 @@ static int share_power_budget(struct _thermal_zone *zone, u32 power_budget)
        i = 0;
        list_for_each_entry(inst, &zone->cooling_list, node) {
                p = &power[i];
-               _set_power(inst, zone, p->requested);
+               ret = _set_power(inst, zone, p->requested);
+               if (ret) {
+                       /* TODO: collect power which cannot be used for other
+                        * devices */
+                       extra_power += p->requested;
+                       p->requested = 0;
+               }
                i++;
        }