Skip to content

Commit 5f64b4a

Browse files
committed
thermal: gov_bang_bang: Add .manage() callback
After recent changes, the Bang-bang governor may not adjust the initial configuration of cooling devices to the actual situation. Namely, if a cooling device bound to a certain trip point starts in the "on" state and the thermal zone temperature is below the threshold of that trip point, the trip point may never be crossed on the way up in which case the state of the cooling device will never be adjusted because the thermal core will never invoke the governor's .trip_crossed() callback. [Note that there is no issue if the zone temperature is at the trip threshold or above it to start with because .trip_crossed() will be invoked then to indicate the start of thermal mitigation for the given trip.] To address this, add a .manage() callback to the Bang-bang governor and use it to ensure that all of the thermal instances managed by the governor have been initialized properly and the states of all of the cooling devices involved have been adjusted to the current zone temperature as appropriate. Fixes: 530c932 ("thermal: gov_bang_bang: Use .trip_crossed() instead of .throttle()") Link: https://lore.kernel.org/linux-pm/[email protected]/ Cc: 6.10+ <[email protected]> # 6.10+ Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Peter Kästle <[email protected]> Reviewed-by: Zhang Rui <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 84248e3 commit 5f64b4a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static void bang_bang_set_instance_target(struct thermal_instance *instance,
2626
* when the trip is crossed on the way down.
2727
*/
2828
instance->target = target;
29+
instance->initialized = true;
2930

3031
dev_dbg(&instance->cdev->device, "target=%ld\n", instance->target);
3132

@@ -80,8 +81,37 @@ static void bang_bang_control(struct thermal_zone_device *tz,
8081
}
8182
}
8283

84+
static void bang_bang_manage(struct thermal_zone_device *tz)
85+
{
86+
const struct thermal_trip_desc *td;
87+
struct thermal_instance *instance;
88+
89+
for_each_trip_desc(tz, td) {
90+
const struct thermal_trip *trip = &td->trip;
91+
92+
if (tz->temperature >= td->threshold ||
93+
trip->temperature == THERMAL_TEMP_INVALID ||
94+
trip->type == THERMAL_TRIP_CRITICAL ||
95+
trip->type == THERMAL_TRIP_HOT)
96+
continue;
97+
98+
/*
99+
* If the initial cooling device state is "on", but the zone
100+
* temperature is not above the trip point, the core will not
101+
* call bang_bang_control() until the zone temperature reaches
102+
* the trip point temperature which may be never. In those
103+
* cases, set the initial state of the cooling device to 0.
104+
*/
105+
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
106+
if (!instance->initialized && instance->trip == trip)
107+
bang_bang_set_instance_target(instance, 0);
108+
}
109+
}
110+
}
111+
83112
static struct thermal_governor thermal_gov_bang_bang = {
84113
.name = "bang_bang",
85114
.trip_crossed = bang_bang_control,
115+
.manage = bang_bang_manage,
86116
};
87117
THERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);

0 commit comments

Comments
 (0)