Skip to content

Commit 9ad1804

Browse files
committed
thermal: core: Send trip crossing notifications at init time if needed
If a trip point is already exceeded by the zone temperature at the initialization time, no trip crossing notification is send regarding this even though mitigation should be started then. Address this by rearranging the code in handle_thermal_trip() to send a trip crossing notification for trip points already exceeded by the zone temperature initially which also allows to reduce its size by using the observation that the initialization and regular trip crossing on the way up become the same case then. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
1 parent f99c1b8 commit 9ad1804

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

drivers/thermal/thermal_core.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
364364
struct thermal_trip_desc *td)
365365
{
366366
const struct thermal_trip *trip = &td->trip;
367+
int old_threshold;
367368

368369
if (trip->temperature == THERMAL_TEMP_INVALID)
369370
return;
@@ -375,25 +376,11 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
375376
* is what needs to be compared with the previous zone temperature
376377
* to decide which action to take.
377378
*/
378-
if (tz->last_temperature == THERMAL_TEMP_INVALID) {
379-
/* Initialization. */
380-
td->threshold = trip->temperature;
381-
if (tz->temperature >= td->threshold)
382-
td->threshold -= trip->hysteresis;
383-
} else if (tz->last_temperature < td->threshold) {
384-
/*
385-
* There is no mitigation under way, so it needs to be started
386-
* if the zone temperature exceeds the trip one. The new
387-
* threshold is then set to the low temperature of the trip.
388-
*/
389-
if (tz->temperature >= trip->temperature) {
390-
thermal_notify_tz_trip_up(tz, trip);
391-
thermal_debug_tz_trip_up(tz, trip);
392-
td->threshold = trip->temperature - trip->hysteresis;
393-
} else {
394-
td->threshold = trip->temperature;
395-
}
396-
} else {
379+
old_threshold = td->threshold;
380+
td->threshold = trip->temperature;
381+
382+
if (tz->last_temperature >= old_threshold &&
383+
tz->last_temperature != THERMAL_TEMP_INVALID) {
397384
/*
398385
* Mitigation is under way, so it needs to stop if the zone
399386
* temperature falls below the low temperature of the trip.
@@ -402,10 +389,18 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
402389
if (tz->temperature < trip->temperature - trip->hysteresis) {
403390
thermal_notify_tz_trip_down(tz, trip);
404391
thermal_debug_tz_trip_down(tz, trip);
405-
td->threshold = trip->temperature;
406392
} else {
407-
td->threshold = trip->temperature - trip->hysteresis;
393+
td->threshold -= trip->hysteresis;
408394
}
395+
} else if (tz->temperature >= trip->temperature) {
396+
/*
397+
* There is no mitigation under way, so it needs to be started
398+
* if the zone temperature exceeds the trip one. The new
399+
* threshold is then set to the low temperature of the trip.
400+
*/
401+
thermal_notify_tz_trip_up(tz, trip);
402+
thermal_debug_tz_trip_up(tz, trip);
403+
td->threshold -= trip->hysteresis;
409404
}
410405

411406
if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT)

0 commit comments

Comments
 (0)