Message ID | 1963742.PYKUYFuaPT@kreacher (mailing list archive) |
---|---|
State | In Next |
Delegated to: | Rafael Wysocki |
Headers | show |
Series | thermal: More separation between the core and drivers | expand |
On 4/2/24 20:02, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > 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> > --- > > v2 -> v3: New patch > > --- > drivers/thermal/thermal_core.c | 37 ++++++++++++++++--------------------- > 1 file changed, 16 insertions(+), 21 deletions(-) > > Index: linux-pm/drivers/thermal/thermal_core.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_core.c > +++ linux-pm/drivers/thermal/thermal_core.c > @@ -364,6 +364,7 @@ static void handle_thermal_trip(struct t > struct thermal_trip_desc *td) > { > const struct thermal_trip *trip = &td->trip; > + int old_threshold; > > if (trip->temperature == THERMAL_TEMP_INVALID) > return; > @@ -375,25 +376,11 @@ static void handle_thermal_trip(struct t > * is what needs to be compared with the previous zone temperature > * to decide which action to take. > */ > - if (tz->last_temperature == THERMAL_TEMP_INVALID) { > - /* Initialization. */ > - td->threshold = trip->temperature; > - if (tz->temperature >= td->threshold) > - td->threshold -= trip->hysteresis; > - } else if (tz->last_temperature < td->threshold) { > - /* > - * There is no mitigation under way, so it needs to be started > - * if the zone temperature exceeds the trip one. The new > - * threshold is then set to the low temperature of the trip. > - */ > - if (tz->temperature >= trip->temperature) { > - thermal_notify_tz_trip_up(tz, trip); > - thermal_debug_tz_trip_up(tz, trip); > - td->threshold = trip->temperature - trip->hysteresis; > - } else { > - td->threshold = trip->temperature; > - } > - } else { > + old_threshold = td->threshold; > + td->threshold = trip->temperature; > + > + if (tz->last_temperature >= old_threshold && > + tz->last_temperature != THERMAL_TEMP_INVALID) { > /* > * Mitigation is under way, so it needs to stop if the zone > * temperature falls below the low temperature of the trip. > @@ -402,10 +389,18 @@ static void handle_thermal_trip(struct t > if (tz->temperature < trip->temperature - trip->hysteresis) { > thermal_notify_tz_trip_down(tz, trip); > thermal_debug_tz_trip_down(tz, trip); > - td->threshold = trip->temperature; > } else { > - td->threshold = trip->temperature - trip->hysteresis; > + td->threshold -= trip->hysteresis; > } > + } else if (tz->temperature >= trip->temperature) { > + /* > + * There is no mitigation under way, so it needs to be started > + * if the zone temperature exceeds the trip one. The new > + * threshold is then set to the low temperature of the trip. > + */ > + thermal_notify_tz_trip_up(tz, trip); > + thermal_debug_tz_trip_up(tz, trip); > + td->threshold -= trip->hysteresis; > } > > if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT) > > > Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -364,6 +364,7 @@ static void handle_thermal_trip(struct t struct thermal_trip_desc *td) { const struct thermal_trip *trip = &td->trip; + int old_threshold; if (trip->temperature == THERMAL_TEMP_INVALID) return; @@ -375,25 +376,11 @@ static void handle_thermal_trip(struct t * is what needs to be compared with the previous zone temperature * to decide which action to take. */ - if (tz->last_temperature == THERMAL_TEMP_INVALID) { - /* Initialization. */ - td->threshold = trip->temperature; - if (tz->temperature >= td->threshold) - td->threshold -= trip->hysteresis; - } else if (tz->last_temperature < td->threshold) { - /* - * There is no mitigation under way, so it needs to be started - * if the zone temperature exceeds the trip one. The new - * threshold is then set to the low temperature of the trip. - */ - if (tz->temperature >= trip->temperature) { - thermal_notify_tz_trip_up(tz, trip); - thermal_debug_tz_trip_up(tz, trip); - td->threshold = trip->temperature - trip->hysteresis; - } else { - td->threshold = trip->temperature; - } - } else { + old_threshold = td->threshold; + td->threshold = trip->temperature; + + if (tz->last_temperature >= old_threshold && + tz->last_temperature != THERMAL_TEMP_INVALID) { /* * Mitigation is under way, so it needs to stop if the zone * temperature falls below the low temperature of the trip. @@ -402,10 +389,18 @@ static void handle_thermal_trip(struct t if (tz->temperature < trip->temperature - trip->hysteresis) { thermal_notify_tz_trip_down(tz, trip); thermal_debug_tz_trip_down(tz, trip); - td->threshold = trip->temperature; } else { - td->threshold = trip->temperature - trip->hysteresis; + td->threshold -= trip->hysteresis; } + } else if (tz->temperature >= trip->temperature) { + /* + * There is no mitigation under way, so it needs to be started + * if the zone temperature exceeds the trip one. The new + * threshold is then set to the low temperature of the trip. + */ + thermal_notify_tz_trip_up(tz, trip); + thermal_debug_tz_trip_up(tz, trip); + td->threshold -= trip->hysteresis; } if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT)