1 From 3989fb43951484788052cbf3b70658e117f027d3 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/gov_step_wise.c | 34 ++++++++++++++++++++++++---------
22 1 file changed, 25 insertions(+), 9 deletions(-)
24 --- a/drivers/thermal/gov_step_wise.c
25 +++ b/drivers/thermal/gov_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 @@ -125,15 +125,19 @@ static void thermal_zone_trip_update(str
45 tz->ops->get_trip_temp(tz, trip, &trip_temp);
46 tz->ops->get_trip_type(tz, trip, &trip_type);
48 - trend = get_tz_trend(tz, trip);
50 - if (tz->temperature >= trip_temp) {
52 - trace_thermal_zone_trip(tz, trip, trip_type);
53 + tz->ops->get_trip_temp(tz, trip, &trip_temp);
54 + hyst_temp = trip_temp;
55 + if (tz->ops->get_trip_hyst) {
56 + tz->ops->get_trip_hyst(tz, trip, &hyst_temp);
57 + hyst_temp = trip_temp - hyst_temp;
59 + tz->ops->get_trip_type(tz, trip, &trip_type);
61 - dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
62 - trip, trip_type, trip_temp, trend, throttle);
63 + trend = get_tz_trend(tz, trip);
65 + dev_dbg(&tz->device,
66 + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n",
67 + trip, trip_type, trip_temp, hyst_temp, trend, throttle);
69 mutex_lock(&tz->lock);
71 @@ -142,6 +146,18 @@ static void thermal_zone_trip_update(str
74 old_target = instance->target;
77 + * Lower the mitigation only if the temperature
78 + * goes below the hysteresis temperature.
80 + if (tz->temperature >= trip_temp ||
81 + (tz->temperature >= hyst_temp &&
82 + old_target != THERMAL_NO_TARGET)) {
84 + trace_thermal_zone_trip(tz, trip, trip_type);
87 instance->target = get_target_state(instance, trend, throttle);
88 dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
89 old_target, (int)instance->target);