From a44cc10cdb7f035d17d00c70f07718461848e697 Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Mon, 7 May 2018 11:54:08 -0600 Subject: [PATCH 1/4] drivers: thermal: step_wise: add support for hysteresis From: Ram Chandrasekar Step wise governor increases the mitigation level when the temperature goes above a threshold and will decrease the mitigation when the temperature falls below the threshold. If it were a case, where the temperature hovers around a threshold, the mitigation will be applied and removed at every iteration. This reaction to the temperature is inefficient for performance. The use of hysteresis temperature could avoid this ping-pong of mitigation by relaxing the mitigation to happen only when the temperature goes below this lower hysteresis value. Signed-off-by: Ram Chandrasekar Signed-off-by: Lina Iyer --- drivers/thermal/step_wise.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index ee047ca43084dc..cf07e22692913b 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -36,7 +36,7 @@ * for this trip point * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit * for this trip point - * If the temperature is lower than a trip point, + * If the temperature is lower than a hysteresis temperature, * a. if the trend is THERMAL_TREND_RAISING, do nothing * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling * state for this trip point, if the cooling state already @@ -127,7 +127,7 @@ static void update_passive_instance(struct thermal_zone_device *tz, static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) { - int trip_temp; + int trip_temp, hyst_temp; enum thermal_trip_type trip_type; enum thermal_trend trend; struct thermal_instance *instance; @@ -135,22 +135,23 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) int old_target; if (trip == THERMAL_TRIPS_NONE) { - trip_temp = tz->forced_passive; + hyst_temp = trip_temp = tz->forced_passive; trip_type = THERMAL_TRIPS_NONE; } else { tz->ops->get_trip_temp(tz, trip, &trip_temp); + hyst_temp = trip_temp; + if (tz->ops->get_trip_hyst) { + tz->ops->get_trip_hyst(tz, trip, &hyst_temp); + hyst_temp = trip_temp - hyst_temp; + } tz->ops->get_trip_type(tz, trip, &trip_type); } trend = get_tz_trend(tz, trip); - if (tz->temperature >= trip_temp) { - throttle = true; - trace_thermal_zone_trip(tz, trip, trip_type); - } - - dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n", - trip, trip_type, trip_temp, trend, throttle); + dev_dbg(&tz->device, + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n", + trip, trip_type, trip_temp, hyst_temp, trend, throttle); mutex_lock(&tz->lock); @@ -159,6 +160,18 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) continue; old_target = instance->target; + throttle = false; + /* + * Lower the mitigation only if the temperature + * goes below the hysteresis temperature. + */ + if (tz->temperature >= trip_temp || + (tz->temperature >= hyst_temp && + old_target != THERMAL_NO_TARGET)) { + throttle = true; + trace_thermal_zone_trip(tz, trip, trip_type); + } + instance->target = get_target_state(instance, trend, throttle); dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n", old_target, (int)instance->target); From 4bd3d37016174d5a3afa14a55e929b32529a145b Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Tue, 2 Oct 2018 11:14:15 +0100 Subject: [PATCH 2/4] drivers: thermal: step_wise: avoid throttling at hysteresis temperature after dropping below it Signed-off-by: Serge Schneider --- drivers/thermal/step_wise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index cf07e22692913b..da695d8f293902 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -167,7 +167,7 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) */ if (tz->temperature >= trip_temp || (tz->temperature >= hyst_temp && - old_target != THERMAL_NO_TARGET)) { + old_target == instance->upper)) { throttle = true; trace_thermal_zone_trip(tz, trip, trip_type); } From 78d1c5d4885d4f211b8435f62548ea706ea56c8f Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Wed, 26 Sep 2018 19:44:59 +0100 Subject: [PATCH 3/4] hwmon: adjust rpi-poe-fan overlay trip points Signed-off-by: Serge Schneider --- .../arm/boot/dts/overlays/rpi-poe-overlay.dts | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts index 0a32fff036a7cc..f24af60f1593ad 100644 --- a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts +++ b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts @@ -14,9 +14,9 @@ compatible = "raspberrypi,rpi-poe-fan"; firmware = <&firmware>; cooling-min-state = <0>; - cooling-max-state = <3>; + cooling-max-state = <2>; #cooling-cells = <2>; - cooling-levels = <0 50 150 255>; + cooling-levels = <0 150 255>; status = "okay"; }; }; @@ -26,35 +26,27 @@ target = <&cpu_thermal>; __overlay__ { trips { - threshold: trip-point@0 { - temperature = <45000>; - hysteresis = <5000>; - type = "active"; - }; - target: trip-point@1 { + trip0: trip0 { temperature = <50000>; - hysteresis = <2000>; + hysteresis = <5000>; type = "active"; }; - cpu_hot: cpu_hot@0 { + trip1: trip1 { + temperature = <55000>; - hysteresis = <2000>; + hysteresis = <5000>; type = "active"; }; }; cooling-maps { map0 { - trip = <&threshold>; + trip = <&trip0>; cooling-device = <&fan0 0 1>; }; map1 { - trip = <&target>; + trip = <&trip1>; cooling-device = <&fan0 1 2>; }; - map2 { - trip = <&cpu_hot>; - cooling-device = <&fan0 2 3>; - }; }; }; }; From 6368165d1095fd813c09c8450f659d934f36ff10 Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Tue, 2 Oct 2018 17:13:48 +0100 Subject: [PATCH 4/4] overlays: add overrides for PoE HAT fan control Signed-off-by: Serge Schneider --- arch/arm/boot/dts/overlays/README | 13 ++++++++++--- arch/arm/boot/dts/overlays/rpi-poe-overlay.dts | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README index 57fa9d83e85d97..2c2b5ab7683561 100644 --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -1596,9 +1596,16 @@ Params: touchscreen-size-x Touchscreen X resolution (default 800) Name: rpi-poe -Info: Raspberry Pi POE HAT -Load: dtoverlay=rpi-poe -Params: +Info: Raspberry Pi PoE HAT fan +Load: dtoverlay=rpi-poe,[=] +Params: poe_fan_temp0 Temperature (in millicelcius) at which the fan + turns on (default 50000) + poe_fan_temp0_hyst Temperature delta (in millicelcius) at which + the fan turns off (default 5000) + poe_fan_temp1 Temperature (in millicelcius) at which the fan + speeds up (default 55000) + poe_fan_temp1_hyst Temperature delta (in millicelcius) at which + the fan slows down (default 5000) Name: rpi-proto diff --git a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts index f24af60f1593ad..1dacd3b33085cd 100644 --- a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts +++ b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts @@ -50,4 +50,14 @@ }; }; }; + + fragment@2 { + target-path = "/__overrides__"; + __overlay__ { + poe_fan_temp0 = <&trip0>,"temperature:0"; + poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; + poe_fan_temp1 = <&trip1>,"temperature:0"; + poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; + }; + }; };