1 From c14122415c0b53cd234d058a55e7183a750a0eda Mon Sep 17 00:00:00 2001
2 From: Ram Chandrasekar <rkumbako@codeaurora.org>
3 Date: Mon, 7 May 2018 11:54:08 -0600
4 Subject: [PATCH] drivers: thermal: step_wise: add support for
7 Step wise governor increases the mitigation level when the temperature
8 goes above a threshold and will decrease the mitigation when the
9 temperature falls below the threshold. If it were a case, where the
10 temperature hovers around a threshold, the mitigation will be applied
11 and removed at every iteration. This reaction to the temperature is
12 inefficient for performance.
14 The use of hysteresis temperature could avoid this ping-pong of
15 mitigation by relaxing the mitigation to happen only when the
16 temperature goes below this lower hysteresis value.
18 Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
19 Signed-off-by: Lina Iyer <ilina@codeaurora.org>
21 drivers/thermal/step_wise.c | 33 +++++++++++++++++++++++----------
22 1 file changed, 23 insertions(+), 10 deletions(-)
24 --- a/drivers/thermal/step_wise.c
25 +++ b/drivers/thermal/step_wise.c
28 * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit
30 - * If the temperature is lower than a trip point,
31 + * If the temperature is lower than a hysteresis temperature,
32 * a. if the trend is THERMAL_TREND_RAISING, do nothing
33 * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling
34 * state for this trip point, if the cooling state already
35 @@ -115,7 +115,7 @@ static void update_passive_instance(stru
37 static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
40 + int trip_temp, hyst_temp;
41 enum thermal_trip_type trip_type;
42 enum thermal_trend trend;
43 struct thermal_instance *instance;
44 @@ -123,22 +123,23 @@ static void thermal_zone_trip_update(str
47 if (trip == THERMAL_TRIPS_NONE) {
48 - trip_temp = tz->forced_passive;
49 + hyst_temp = trip_temp = tz->forced_passive;
50 trip_type = THERMAL_TRIPS_NONE;
52 tz->ops->get_trip_temp(tz, trip, &trip_temp);
53 + hyst_temp = trip_temp;
54 + if (tz->ops->get_trip_hyst) {
55 + tz->ops->get_trip_hyst(tz, trip, &hyst_temp);
56 + hyst_temp = trip_temp - hyst_temp;
58 tz->ops->get_trip_type(tz, trip, &trip_type);
61 trend = get_tz_trend(tz, trip);
63 - if (tz->temperature >= trip_temp) {
65 - trace_thermal_zone_trip(tz, trip, trip_type);
68 - dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
69 - trip, trip_type, trip_temp, trend, throttle);
70 + dev_dbg(&tz->device,
71 + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n",
72 + trip, trip_type, trip_temp, hyst_temp, trend, throttle);
74 mutex_lock(&tz->lock);
76 @@ -147,6 +148,18 @@ static void thermal_zone_trip_update(str
79 old_target = instance->target;
82 + * Lower the mitigation only if the temperature
83 + * goes below the hysteresis temperature.
85 + if (tz->temperature >= trip_temp ||
86 + (tz->temperature >= hyst_temp &&
87 + old_target != THERMAL_NO_TARGET)) {
89 + trace_thermal_zone_trip(tz, trip, trip_type);
92 instance->target = get_target_state(instance, trend, throttle);
93 dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
94 old_target, (int)instance->target);