e715e4e219ba67801beed853a5b2a6c04a9efc8d
[openwrt/staging/dangole.git] /
1 From bcf41a406eb1c0e2a7f3e5ac0baef5455933afd7 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 426/454] drivers: thermal: step_wise: add support for
5 hysteresis
6
7 From: Ram Chandrasekar <rkumbako@codeaurora.org>
8
9 Step wise governor increases the mitigation level when the temperature
10 goes above a threshold and will decrease the mitigation when the
11 temperature falls below the threshold. If it were a case, where the
12 temperature hovers around a threshold, the mitigation will be applied
13 and removed at every iteration. This reaction to the temperature is
14 inefficient for performance.
15
16 The use of hysteresis temperature could avoid this ping-pong of
17 mitigation by relaxing the mitigation to happen only when the
18 temperature goes below this lower hysteresis value.
19
20 Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
21 Signed-off-by: Lina Iyer <ilina@codeaurora.org>
22 ---
23 drivers/thermal/step_wise.c | 33 +++++++++++++++++++++++----------
24 1 file changed, 23 insertions(+), 10 deletions(-)
25
26 --- a/drivers/thermal/step_wise.c
27 +++ b/drivers/thermal/step_wise.c
28 @@ -36,7 +36,7 @@
29 * for this trip point
30 * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit
31 * for this trip point
32 - * If the temperature is lower than a trip point,
33 + * If the temperature is lower than a hysteresis temperature,
34 * a. if the trend is THERMAL_TREND_RAISING, do nothing
35 * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling
36 * state for this trip point, if the cooling state already
37 @@ -127,7 +127,7 @@ static void update_passive_instance(stru
38
39 static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
40 {
41 - int trip_temp;
42 + int trip_temp, hyst_temp;
43 enum thermal_trip_type trip_type;
44 enum thermal_trend trend;
45 struct thermal_instance *instance;
46 @@ -135,22 +135,23 @@ static void thermal_zone_trip_update(str
47 int old_target;
48
49 if (trip == THERMAL_TRIPS_NONE) {
50 - trip_temp = tz->forced_passive;
51 + hyst_temp = trip_temp = tz->forced_passive;
52 trip_type = THERMAL_TRIPS_NONE;
53 } else {
54 tz->ops->get_trip_temp(tz, trip, &trip_temp);
55 + hyst_temp = trip_temp;
56 + if (tz->ops->get_trip_hyst) {
57 + tz->ops->get_trip_hyst(tz, trip, &hyst_temp);
58 + hyst_temp = trip_temp - hyst_temp;
59 + }
60 tz->ops->get_trip_type(tz, trip, &trip_type);
61 }
62
63 trend = get_tz_trend(tz, trip);
64
65 - if (tz->temperature >= trip_temp) {
66 - throttle = true;
67 - trace_thermal_zone_trip(tz, trip, trip_type);
68 - }
69 -
70 - dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
71 - trip, trip_type, trip_temp, trend, throttle);
72 + dev_dbg(&tz->device,
73 + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n",
74 + trip, trip_type, trip_temp, hyst_temp, trend, throttle);
75
76 mutex_lock(&tz->lock);
77
78 @@ -159,6 +160,18 @@ static void thermal_zone_trip_update(str
79 continue;
80
81 old_target = instance->target;
82 + throttle = false;
83 + /*
84 + * Lower the mitigation only if the temperature
85 + * goes below the hysteresis temperature.
86 + */
87 + if (tz->temperature >= trip_temp ||
88 + (tz->temperature >= hyst_temp &&
89 + old_target != THERMAL_NO_TARGET)) {
90 + throttle = true;
91 + trace_thermal_zone_trip(tz, trip, trip_type);
92 + }
93 +
94 instance->target = get_target_state(instance, trend, throttle);
95 dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
96 old_target, (int)instance->target);