Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/core: Compute low and high boundaries in thermal_zone_device_update()

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>
Link: https://patch.msgid.link/20240816081241.1925221-2-daniel.lezcano@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Daniel Lezcano and committed by
Rafael J. Wysocki
f9ba1e05 5ae98b5a

+12 -29
+10 -2
drivers/thermal/thermal_core.c
··· 547 547 struct thermal_trip_desc *td; 548 548 LIST_HEAD(way_down_list); 549 549 LIST_HEAD(way_up_list); 550 + int low = -INT_MAX, high = INT_MAX; 550 551 int temp, ret; 551 552 552 553 if (tz->suspended) ··· 581 580 582 581 tz->notify_event = event; 583 582 584 - for_each_trip_desc(tz, td) 583 + for_each_trip_desc(tz, td) { 585 584 handle_thermal_trip(tz, td, &way_up_list, &way_down_list); 586 585 587 - thermal_zone_set_trips(tz); 586 + if (td->threshold <= tz->temperature && td->threshold > low) 587 + low = td->threshold; 588 + 589 + if (td->threshold >= tz->temperature && td->threshold < high) 590 + high = td->threshold; 591 + } 592 + 593 + thermal_zone_set_trips(tz, low, high); 588 594 589 595 list_sort(NULL, &way_up_list, thermal_trip_notify_cmp); 590 596 list_for_each_entry(td, &way_up_list, notify_list_node)
+1 -1
drivers/thermal/thermal_core.h
··· 255 255 256 256 const char *thermal_trip_type_name(enum thermal_trip_type trip_type); 257 257 258 - void thermal_zone_set_trips(struct thermal_zone_device *tz); 258 + void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high); 259 259 int thermal_zone_trip_id(const struct thermal_zone_device *tz, 260 260 const struct thermal_trip *trip); 261 261 int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
+1 -26
drivers/thermal/thermal_trip.c
··· 55 55 } 56 56 EXPORT_SYMBOL_GPL(thermal_zone_for_each_trip); 57 57 58 - /** 59 - * thermal_zone_set_trips - Computes the next trip points for the driver 60 - * @tz: a pointer to a thermal zone device structure 61 - * 62 - * The function computes the next temperature boundaries by browsing 63 - * the trip points. The result is the closer low and high trip points 64 - * to the current temperature. These values are passed to the backend 65 - * driver to let it set its own notification mechanism (usually an 66 - * interrupt). 67 - * 68 - * This function must be called with tz->lock held. Both tz and tz->ops 69 - * must be valid pointers. 70 - * 71 - * It does not return a value 72 - */ 73 - void thermal_zone_set_trips(struct thermal_zone_device *tz) 58 + void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high) 74 59 { 75 - const struct thermal_trip_desc *td; 76 - int low = -INT_MAX, high = INT_MAX; 77 60 int ret; 78 61 79 62 lockdep_assert_held(&tz->lock); 80 63 81 64 if (!tz->ops.set_trips) 82 65 return; 83 - 84 - for_each_trip_desc(tz, td) { 85 - if (td->threshold <= tz->temperature && td->threshold > low) 86 - low = td->threshold; 87 - 88 - if (td->threshold >= tz->temperature && td->threshold < high) 89 - high = td->threshold; 90 - } 91 66 92 67 /* No need to change trip points */ 93 68 if (tz->prev_low_trip == low && tz->prev_high_trip == high)