Message ID | 20240816081241.1925221-2-daniel.lezcano@linaro.org (mailing list archive) |
---|---|
State | Mainlined, archived |
Headers | show |
Series | Add thermal thresholds support | expand |
On Fri, Aug 16, 2024 at 10:12 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > In order to set the scene for the thresholds support which have to > manipulate the low and high temperature boundaries for the interrupt > support, we must pass the low and high values to the incoming > thresholds routine. > > The variables are set from the thermal_zone_set_trips() where the > function loops the thermal trips to figure out the next and the > previous temperatures to set the interrupt to be triggered when they > are crossed. > > These variables will be needed by the function in charge of handling > the thresholds in the incoming changes but they are local to the > aforementioned function thermal_zone_set_trips(). > > Move the low and high boundaries computation out of the function in > thermal_zone_device_update() so they are accessible from there. > > The positive side effect is they are computed in the same loop as > handle_thermal_trip(), so we remove one loop. > > Co-developed-by: Rafael J. Wysocki <rjw@rjwysocki.net> > Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Looks good to me and I'd like to apply it earlier separately as I have material depending on it in the works. > --- > drivers/thermal/thermal_core.c | 12 ++++++++++-- > drivers/thermal/thermal_core.h | 2 +- > drivers/thermal/thermal_trip.c | 27 +-------------------------- > 3 files changed, 12 insertions(+), 29 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 95c399f94744..166f48071487 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -547,6 +547,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, > struct thermal_trip_desc *td; > LIST_HEAD(way_down_list); > LIST_HEAD(way_up_list); > + int low = -INT_MAX, high = INT_MAX; > int temp, ret; > > if (tz->suspended) > @@ -580,10 +581,17 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, > > tz->notify_event = event; > > - for_each_trip_desc(tz, td) > + for_each_trip_desc(tz, td) { > handle_thermal_trip(tz, td, &way_up_list, &way_down_list); > > - thermal_zone_set_trips(tz); > + if (td->threshold <= tz->temperature && td->threshold > low) > + low = td->threshold; > + > + if (td->threshold >= tz->temperature && td->threshold < high) > + high = td->threshold; > + } > + > + thermal_zone_set_trips(tz, low, high); > > list_sort(NULL, &way_up_list, thermal_trip_notify_cmp); > list_for_each_entry(td, &way_up_list, notify_list_node) > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index 4cf2b7230d04..67a09f90eb95 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -259,7 +259,7 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz, > > const char *thermal_trip_type_name(enum thermal_trip_type trip_type); > > -void thermal_zone_set_trips(struct thermal_zone_device *tz); > +void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high); > int thermal_zone_trip_id(const struct thermal_zone_device *tz, > const struct thermal_trip *trip); > void thermal_zone_trip_updated(struct thermal_zone_device *tz, > diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c > index 06a0554ddc38..1d43ab52e86a 100644 > --- a/drivers/thermal/thermal_trip.c > +++ b/drivers/thermal/thermal_trip.c > @@ -61,25 +61,8 @@ int thermal_zone_get_num_trips(struct thermal_zone_device *tz) > } > EXPORT_SYMBOL_GPL(thermal_zone_get_num_trips); > > -/** > - * thermal_zone_set_trips - Computes the next trip points for the driver > - * @tz: a pointer to a thermal zone device structure > - * > - * The function computes the next temperature boundaries by browsing > - * the trip points. The result is the closer low and high trip points > - * to the current temperature. These values are passed to the backend > - * driver to let it set its own notification mechanism (usually an > - * interrupt). > - * > - * This function must be called with tz->lock held. Both tz and tz->ops > - * must be valid pointers. > - * > - * It does not return a value > - */ > -void thermal_zone_set_trips(struct thermal_zone_device *tz) > +void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high) > { > - const struct thermal_trip_desc *td; > - int low = -INT_MAX, high = INT_MAX; > int ret; > > lockdep_assert_held(&tz->lock); > @@ -87,14 +70,6 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz) > if (!tz->ops.set_trips) > return; > > - for_each_trip_desc(tz, td) { > - if (td->threshold <= tz->temperature && td->threshold > low) > - low = td->threshold; > - > - if (td->threshold >= tz->temperature && td->threshold < high) > - high = td->threshold; > - } > - > /* No need to change trip points */ > if (tz->prev_low_trip == low && tz->prev_high_trip == high) > return; > -- > 2.43.0 >
On 16/08/2024 13:34, Rafael J. Wysocki wrote: > On Fri, Aug 16, 2024 at 10:12 AM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: >> >> In order to set the scene for the thresholds support which have to >> manipulate the low and high temperature boundaries for the interrupt >> support, we must pass the low and high values to the incoming >> thresholds routine. >> >> The variables are set from the thermal_zone_set_trips() where the >> function loops the thermal trips to figure out the next and the >> previous temperatures to set the interrupt to be triggered when they >> are crossed. >> >> These variables will be needed by the function in charge of handling >> the thresholds in the incoming changes but they are local to the >> aforementioned function thermal_zone_set_trips(). >> >> Move the low and high boundaries computation out of the function in >> thermal_zone_device_update() so they are accessible from there. >> >> The positive side effect is they are computed in the same loop as >> handle_thermal_trip(), so we remove one loop. >> >> Co-developed-by: Rafael J. Wysocki <rjw@rjwysocki.net> >> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> > > Looks good to me and I'd like to apply it earlier separately as I have > material depending on it in the works. Sure
On Fri, Aug 16, 2024 at 2:06 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 16/08/2024 13:34, Rafael J. Wysocki wrote: > > On Fri, Aug 16, 2024 at 10:12 AM Daniel Lezcano > > <daniel.lezcano@linaro.org> wrote: > >> > >> In order to set the scene for the thresholds support which have to > >> manipulate the low and high temperature boundaries for the interrupt > >> support, we must pass the low and high values to the incoming > >> thresholds routine. > >> > >> The variables are set from the thermal_zone_set_trips() where the > >> function loops the thermal trips to figure out the next and the > >> previous temperatures to set the interrupt to be triggered when they > >> are crossed. > >> > >> These variables will be needed by the function in charge of handling > >> the thresholds in the incoming changes but they are local to the > >> aforementioned function thermal_zone_set_trips(). > >> > >> Move the low and high boundaries computation out of the function in > >> thermal_zone_device_update() so they are accessible from there. > >> > >> The positive side effect is they are computed in the same loop as > >> handle_thermal_trip(), so we remove one loop. > >> > >> Co-developed-by: Rafael J. Wysocki <rjw@rjwysocki.net> > >> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> > > > > Looks good to me and I'd like to apply it earlier separately as I have > > material depending on it in the works. > > Sure Applied as 6.12 material, thanks!
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 95c399f94744..166f48071487 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -547,6 +547,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, struct thermal_trip_desc *td; LIST_HEAD(way_down_list); LIST_HEAD(way_up_list); + int low = -INT_MAX, high = INT_MAX; int temp, ret; if (tz->suspended) @@ -580,10 +581,17 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, tz->notify_event = event; - for_each_trip_desc(tz, td) + for_each_trip_desc(tz, td) { handle_thermal_trip(tz, td, &way_up_list, &way_down_list); - thermal_zone_set_trips(tz); + if (td->threshold <= tz->temperature && td->threshold > low) + low = td->threshold; + + if (td->threshold >= tz->temperature && td->threshold < high) + high = td->threshold; + } + + thermal_zone_set_trips(tz, low, high); list_sort(NULL, &way_up_list, thermal_trip_notify_cmp); list_for_each_entry(td, &way_up_list, notify_list_node) diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 4cf2b7230d04..67a09f90eb95 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -259,7 +259,7 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz, const char *thermal_trip_type_name(enum thermal_trip_type trip_type); -void thermal_zone_set_trips(struct thermal_zone_device *tz); +void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high); int thermal_zone_trip_id(const struct thermal_zone_device *tz, const struct thermal_trip *trip); void thermal_zone_trip_updated(struct thermal_zone_device *tz, diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c index 06a0554ddc38..1d43ab52e86a 100644 --- a/drivers/thermal/thermal_trip.c +++ b/drivers/thermal/thermal_trip.c @@ -61,25 +61,8 @@ int thermal_zone_get_num_trips(struct thermal_zone_device *tz) } EXPORT_SYMBOL_GPL(thermal_zone_get_num_trips); -/** - * thermal_zone_set_trips - Computes the next trip points for the driver - * @tz: a pointer to a thermal zone device structure - * - * The function computes the next temperature boundaries by browsing - * the trip points. The result is the closer low and high trip points - * to the current temperature. These values are passed to the backend - * driver to let it set its own notification mechanism (usually an - * interrupt). - * - * This function must be called with tz->lock held. Both tz and tz->ops - * must be valid pointers. - * - * It does not return a value - */ -void thermal_zone_set_trips(struct thermal_zone_device *tz) +void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high) { - const struct thermal_trip_desc *td; - int low = -INT_MAX, high = INT_MAX; int ret; lockdep_assert_held(&tz->lock); @@ -87,14 +70,6 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz) if (!tz->ops.set_trips) return; - for_each_trip_desc(tz, td) { - if (td->threshold <= tz->temperature && td->threshold > low) - low = td->threshold; - - if (td->threshold >= tz->temperature && td->threshold < high) - high = td->threshold; - } - /* No need to change trip points */ if (tz->prev_low_trip == low && tz->prev_high_trip == high) return;
In order to set the scene for the thresholds support which have to manipulate the low and high temperature boundaries for the interrupt support, we must pass the low and high values to the incoming thresholds routine. The variables are set from the thermal_zone_set_trips() where the function loops the thermal trips to figure out the next and the previous temperatures to set the interrupt to be triggered when they are crossed. These variables will be needed by the function in charge of handling the thresholds in the incoming changes but they are local to the aforementioned function thermal_zone_set_trips(). Move the low and high boundaries computation out of the function in thermal_zone_device_update() so they are accessible from there. The positive side effect is they are computed in the same loop as handle_thermal_trip(), so we remove one loop. Co-developed-by: Rafael J. Wysocki <rjw@rjwysocki.net> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> --- drivers/thermal/thermal_core.c | 12 ++++++++++-- drivers/thermal/thermal_core.h | 2 +- drivers/thermal/thermal_trip.c | 27 +-------------------------- 3 files changed, 12 insertions(+), 29 deletions(-)