Skip to content

Commit 80f5fd4

Browse files
committed
thermal: core: Introduce .trip_crossed() callback for thermal governors
Introduce a new thermal governor callback called .trip_crossed() that will be invoked whenever a trip point is crossed by the zone temperature, either on the way up or on the way down. The trip crossing direction information will be passed to it and if multiple trips are crossed in the same direction during one thermal zone update, the new callback will be invoked for them in temperature order, either ascending or descending, depending on the trip crossing direction. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]>
1 parent 5c897a9 commit 80f5fd4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

drivers/thermal/thermal_core.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,21 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
302302
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
303303
}
304304

305+
static struct thermal_governor *thermal_get_tz_governor(struct thermal_zone_device *tz)
306+
{
307+
if (tz->governor)
308+
return tz->governor;
309+
310+
return def_governor;
311+
}
312+
305313
static void handle_non_critical_trips(struct thermal_zone_device *tz,
306314
const struct thermal_trip *trip)
307315
{
308-
tz->governor ? tz->governor->throttle(tz, trip) :
309-
def_governor->throttle(tz, trip);
316+
struct thermal_governor *governor = thermal_get_tz_governor(tz);
317+
318+
if (governor->throttle)
319+
governor->throttle(tz, trip);
310320
}
311321

312322
void thermal_governor_update_tz(struct thermal_zone_device *tz,
@@ -470,6 +480,7 @@ static int thermal_trip_notify_cmp(void *ascending, const struct list_head *a,
470480
void __thermal_zone_device_update(struct thermal_zone_device *tz,
471481
enum thermal_notify_event event)
472482
{
483+
struct thermal_governor *governor = thermal_get_tz_governor(tz);
473484
struct thermal_trip_desc *td;
474485
LIST_HEAD(way_down_list);
475486
LIST_HEAD(way_up_list);
@@ -493,12 +504,16 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
493504
list_for_each_entry(td, &way_up_list, notify_list_node) {
494505
thermal_notify_tz_trip_up(tz, &td->trip);
495506
thermal_debug_tz_trip_up(tz, &td->trip);
507+
if (governor->trip_crossed)
508+
governor->trip_crossed(tz, &td->trip, true);
496509
}
497510

498511
list_sort(NULL, &way_down_list, thermal_trip_notify_cmp);
499512
list_for_each_entry(td, &way_down_list, notify_list_node) {
500513
thermal_notify_tz_trip_down(tz, &td->trip);
501514
thermal_debug_tz_trip_down(tz, &td->trip);
515+
if (governor->trip_crossed)
516+
governor->trip_crossed(tz, &td->trip, false);
502517
}
503518

504519
monitor_thermal_zone(tz);

drivers/thermal/thermal_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct thermal_trip_desc {
3030
* otherwise it fails.
3131
* @unbind_from_tz: callback called when a governor is unbound from a
3232
* thermal zone.
33+
* @trip_crossed: called for trip points that have just been crossed
3334
* @throttle: callback called for every trip point even if temperature is
3435
* below the trip point temperature
3536
* @update_tz: callback called when thermal zone internals have changed, e.g.
@@ -40,6 +41,9 @@ struct thermal_governor {
4041
const char *name;
4142
int (*bind_to_tz)(struct thermal_zone_device *tz);
4243
void (*unbind_from_tz)(struct thermal_zone_device *tz);
44+
void (*trip_crossed)(struct thermal_zone_device *tz,
45+
const struct thermal_trip *trip,
46+
bool crossed_up);
4347
int (*throttle)(struct thermal_zone_device *tz,
4448
const struct thermal_trip *trip);
4549
void (*update_tz)(struct thermal_zone_device *tz,

0 commit comments

Comments
 (0)