4812f543fa6bde5dbcac4786a6054f47ddb7ed37
[openwrt/staging/xback.git] /
1 From 3fc58056cba3cb56f20f98432de2c144f3d07308 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/gov_step_wise.c | 34 ++++++++++++++++++++++++---------
22 1 file changed, 25 insertions(+), 9 deletions(-)
23
24 --- a/drivers/thermal/gov_step_wise.c
25 +++ b/drivers/thermal/gov_step_wise.c
26 @@ -25,7 +25,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 @@ -97,7 +97,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 @@ -107,21 +107,37 @@ 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);
47
48 - trend = get_tz_trend(tz, trip);
49 -
50 - if (tz->temperature >= trip_temp) {
51 - throttle = true;
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;
58 }
59 + tz->ops->get_trip_type(tz, trip, &trip_type);
60
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);
64 +
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);
68
69 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
70 if (instance->trip != trip)
71 continue;
72
73 old_target = instance->target;
74 + throttle = false;
75 + /*
76 + * Lower the mitigation only if the temperature
77 + * goes below the hysteresis temperature.
78 + */
79 + if (tz->temperature >= trip_temp ||
80 + (tz->temperature >= hyst_temp &&
81 + old_target != THERMAL_NO_TARGET)) {
82 + throttle = true;
83 + trace_thermal_zone_trip(tz, trip, trip_type);
84 + }
85 +
86 instance->target = get_target_state(instance, trend, throttle);
87 dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n",
88 old_target, (int)instance->target);