thermal/governors: Fix cooling device setting cooling state failure
Subsystems (2)
PATCH 1/1 thermal/governors: Fix cooling device setting cooling state failure
Because the __thermal_cdev_update function traverses the cooling_device->thermal_instances list to obtain the maximum target state, and then the cooling device sets the maximum cooling state. However, the power_actor_set_power function only updates the target value of thermal_zone->thermal_instances to the target state, and does not update the target value of cooling_device->thermal_instances, resulting in the target being 0 all the time.
--- drivers/thermal/gov_power_allocator.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/thermal/gov_power_allocator.c +5 -0
@@ -293,6 +293,7 @@ power_actor_set_power(struct thermal_cooling_device *cdev, struct thermal_instance *instance, u32 power) {unsigned long state; +struct thermal_instance *cdev_instance;int ret; ret = cdev->ops->power2state (cdev, power, &state);
@@ -300,6 +301,10 @@ power_actor_set_power(struct thermal_cooling_device *cdev,return ret; instance->target =clamp_val (state, instance->lower, instance->upper); +list_for_each_entry (cdev_instance, &cdev->thermal_instances, cdev_node) { +if (cdev_instance->tz->id == instance->tz->id) + cdev_instance->target = state; + }mutex_lock (&cdev->lock);__thermal_cdev_update (cdev);mutex_unlock (&cdev->lock);
Signature · 1 line
2.37.1
Lukasz Luba
maintainerHi Qibo,
Thank you for using IPA and sending a patch. Unfortunately, this code cannot be added into the governor.
Quoted 27 lines · Qibo Huang
Because the
__thermal_cdev_updatefunction traverses thecooling_device->thermal_instanceslist to obtain the maximum target state, and then the cooling device sets the maximum cooling state. However, thepower_actor_set_powerfunction only updates the target value ofthermal_zone->thermal_instancesto the target state, and does not update the target value ofcooling_device->thermal_instances, resulting in the target being 0 all the time.Signed-off-by Qibo Huang <[email protected]>--- drivers/thermal/gov_power_allocator.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/thermal/gov_power_allocator.c +1
-0@@ -293,6 +293,7 @@ power_actor_set_power(struct thermal_cooling_device *cdev, struct thermal_instance *instance, u32 power) {unsigned long state; +struct thermal_instance *cdev_instance;int ret; ret = cdev->ops->power2state (cdev, power, &state);
drivers/thermal/gov_power_allocator.c power_actor_set_power(struct thermal_cooling_device *cdev, · line 303
Quoted 3 lines
drivers/thermal/gov_power_allocator.c +0
-0@@ -300,6 +301,10 @@ power_actor_set_power(struct thermal_cooling_device *cdev,return ret; instance->target =clamp_val (state, instance->lower, instance->upper);
For our 'instance', which IPA was given be the framework, we set the new 'target' value above.
drivers/thermal/gov_power_allocator.c power_actor_set_power(struct thermal_cooling_device *cdev, · line 306
Quoted 3 lines
drivers/thermal/gov_power_allocator.c +3
-0+list_for_each_entry (cdev_instance, &cdev->thermal_instances, cdev_node) { +if (cdev_instance->tz->id == instance->tz->id) + cdev_instance->target = state;
This is not the approach for the governor of a single thermal zone. Please check the implementation of the function below __thermal_cdev_update()
You will see there the 'voting' code. This belongs to the framework code.
drivers/thermal/gov_power_allocator.c power_actor_set_power(struct thermal_cooling_device *cdev, · line 309
Quoted 3 lines
drivers/thermal/gov_power_allocator.c +1
-0+ }mutex_lock (&cdev->lock);__thermal_cdev_update (cdev);
This is the place where the right 'targe't is picked for cooling device from different thermal zones (and maybe governors). When a new target value is higher than other target values, the framework would throttle the device. Then other thermal framework are kicked to make this change propagated correctly.
Also important, please see that this work is done under the cdev->lock. Not every code is safe to run, because e.g. this list cdev->thermal_instances might change in the meantime.
drivers/thermal/gov_power_allocator.c power_actor_set_power(struct thermal_cooling_device *cdev, · line 310
Quoted 1 line
drivers/thermal/gov_power_allocator.c +0
-0mutex_unlock (&cdev->lock);
Regards,
Lukasz