Skip to content

Commit b919fb9

Browse files
Ram Chandrasekarpopcornmix
authored andcommitted
drivers: thermal: step_wise: add support for hysteresis
Step wise governor increases the mitigation level when the temperature goes above a threshold and will decrease the mitigation when the temperature falls below the threshold. If it were a case, where the temperature hovers around a threshold, the mitigation will be applied and removed at every iteration. This reaction to the temperature is inefficient for performance. The use of hysteresis temperature could avoid this ping-pong of mitigation by relaxing the mitigation to happen only when the temperature goes below this lower hysteresis value. Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org> Signed-off-by: Lina Iyer <ilina@codeaurora.org> drivers: thermal: step_wise: avoid throttling at hysteresis temperature after dropping below it Signed-off-by: Serge Schneider <serge@raspberrypi.org> Fix hysteresis support in gov_step_wise.c Directly get hyst value instead of going through an optional and, now, unimplemented function. Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
1 parent 3b300d0 commit b919fb9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

drivers/thermal/gov_step_wise.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
#include "thermal_core.h"
1818

1919
/*
20-
* If the temperature is higher than a trip point,
20+
* If the temperature is higher than a hysteresis temperature,
2121
* a. if the trend is THERMAL_TREND_RAISING, use higher cooling
2222
* state for this trip point
2323
* b. if the trend is THERMAL_TREND_DROPPING, use a lower cooling state
2424
* for this trip point, but keep the cooling state above the applicable
2525
* minimum
26-
* If the temperature is lower than a trip point,
26+
* If the temperature is lower than a hysteresis temperature,
2727
* a. if the trend is THERMAL_TREND_RAISING, do nothing
2828
* b. if the trend is THERMAL_TREND_DROPPING, use the minimum applicable
2929
* cooling state for this trip point, or if the cooling state already
@@ -82,22 +82,37 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz,
8282
const struct thermal_trip_desc *td,
8383
int trip_threshold)
8484
{
85-
bool throttle = tz->temperature >= trip_threshold;
8685
const struct thermal_trip *trip = &td->trip;
86+
int hyst_temp = trip->temperature - trip->hysteresis;
87+
bool throttle = tz->temperature >= hyst_temp;
8788
enum thermal_trend trend = get_tz_trend(tz, trip);
8889
int trip_id = thermal_zone_trip_id(tz, trip);
8990
struct thermal_instance *instance;
9091

9192
if (throttle)
9293
trace_thermal_zone_trip(tz, trip_id, trip->type);
9394

94-
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
95-
trip_id, trip->type, trip_threshold, trend, throttle);
95+
dev_dbg(&tz->device,
96+
"Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n",
97+
trip_id, trip->type, trip->temperature, hyst_temp, trend, throttle);
9698

9799
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
98100
int old_target;
99101

100102
old_target = instance->target;
103+
throttle = false;
104+
105+
/*
106+
* Lower the mitigation only if the temperature
107+
* goes below the hysteresis temperature.
108+
*/
109+
if (tz->temperature >= trip->temperature ||
110+
(tz->temperature >= hyst_temp &&
111+
old_target == instance->upper)) {
112+
throttle = true;
113+
trace_thermal_zone_trip(tz, trip_id, trip->type);
114+
}
115+
101116
instance->target = get_target_state(instance, trend, throttle);
102117

103118
dev_dbg(&instance->cdev->device, "old_target=%d, target=%ld\n",

0 commit comments

Comments
 (0)