3f85c34d29111e2535c0792c9fa235177ebe9ae6
[openwrt/staging/noltari.git] /
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
5 hysteresis
6
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.
13
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.
17
18 Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
19 Signed-off-by: Lina Iyer <ilina@codeaurora.org>
20 ---
21 drivers/thermal/step_wise.c | 33 +++++++++++++++++++++++----------
22 1 file changed, 23 insertions(+), 10 deletions(-)
23
24 --- a/drivers/thermal/step_wise.c
25 +++ b/drivers/thermal/step_wise.c
26 @@ -24,7 +24,7 @@
27 * for this trip point
28 * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit
29 * for this trip point
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
36
37 static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
38 {
39 - int trip_temp;
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
45 int old_target;
46
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;
51 } else {
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;
57 + }
58 tz->ops->get_trip_type(tz, trip, &trip_type);
59 }
60
61 trend = get_tz_trend(tz, trip);
62
63 - if (tz->temperature >= trip_temp) {
64 - throttle = true;
65 - trace_thermal_zone_trip(tz, trip, trip_type);
66 - }
67 -
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);
73
74 mutex_lock(&tz->lock);
75
76 @@ -147,6 +148,18 @@ static void thermal_zone_trip_update(str
77 continue;
78
79 old_target = instance->target;
80 + throttle = false;
81 + /*
82 + * Lower the mitigation only if the temperature
83 + * goes below the hysteresis temperature.
84 + */
85 + if (tz->temperature >= trip_temp ||
86 + (tz->temperature >= hyst_temp &&
87 + old_target != THERMAL_NO_TARGET)) {
88 + throttle = true;
89 + trace_thermal_zone_trip(tz, trip, trip_type);
90 + }
91 +
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);