Skip to content

Commit a8c9594

Browse files
lukaszluba-armrafaeljw
authored andcommitted
thermal: core: Add governor callback for thermal zone change
Add a new callback to the struct thermal_governor. It can be used for updating governors when there is a change in the thermal zone internals, e.g. thermal cooling device is bind to the thermal zone. That makes possible to move some heavy operations like memory allocations related to the number of cooling instances out of the throttle() callback. Both callback code paths (throttle() and update_tz()) are protected with the same thermal zone lock, which guaranties the consistency. Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 04c3b03 commit a8c9594

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

drivers/thermal/thermal_core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz,
309309
def_governor->throttle(tz, trip);
310310
}
311311

312+
void thermal_governor_update_tz(struct thermal_zone_device *tz,
313+
enum thermal_notify_event reason)
314+
{
315+
if (!tz->governor || !tz->governor->update_tz)
316+
return;
317+
318+
tz->governor->update_tz(tz, reason);
319+
}
320+
312321
void thermal_zone_device_critical(struct thermal_zone_device *tz)
313322
{
314323
/*
@@ -715,6 +724,8 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
715724
list_add_tail(&dev->tz_node, &tz->thermal_instances);
716725
list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
717726
atomic_set(&tz->need_update, 1);
727+
728+
thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
718729
}
719730
mutex_unlock(&cdev->lock);
720731
mutex_unlock(&tz->lock);
@@ -773,6 +784,9 @@ int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
773784
if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
774785
list_del(&pos->tz_node);
775786
list_del(&pos->cdev_node);
787+
788+
thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
789+
776790
mutex_unlock(&cdev->lock);
777791
mutex_unlock(&tz->lock);
778792
goto unbind;

drivers/thermal/thermal_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
114114
int thermal_build_list_of_policies(char *buf);
115115
void __thermal_zone_device_update(struct thermal_zone_device *tz,
116116
enum thermal_notify_event event);
117+
void thermal_governor_update_tz(struct thermal_zone_device *tz,
118+
enum thermal_notify_event reason);
117119

118120
/* Helpers */
119121
#define for_each_trip(__tz, __trip) \

include/linux/thermal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ enum thermal_notify_event {
5151
THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */
5252
THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
5353
THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
54+
THERMAL_TZ_BIND_CDEV, /* Cooling dev is bind to the thermal zone */
55+
THERMAL_TZ_UNBIND_CDEV, /* Cooling dev is unbind from the thermal zone */
5456
};
5557

5658
/**
@@ -199,6 +201,8 @@ struct thermal_zone_device {
199201
* thermal zone.
200202
* @throttle: callback called for every trip point even if temperature is
201203
* below the trip point temperature
204+
* @update_tz: callback called when thermal zone internals have changed, e.g.
205+
* thermal cooling instance was added/removed
202206
* @governor_list: node in thermal_governor_list (in thermal_core.c)
203207
*/
204208
struct thermal_governor {
@@ -207,6 +211,8 @@ struct thermal_governor {
207211
void (*unbind_from_tz)(struct thermal_zone_device *tz);
208212
int (*throttle)(struct thermal_zone_device *tz,
209213
const struct thermal_trip *trip);
214+
void (*update_tz)(struct thermal_zone_device *tz,
215+
enum thermal_notify_event reason);
210216
struct list_head governor_list;
211217
};
212218

0 commit comments

Comments
 (0)