thermal/core: Use clamp() helper in the stepwise governor
PATCH 1/2 thermal/core: Use clamp() helper in the stepwise governor
The code is actually clampling the next cooling device state using the lowest and highest states of the thermal instance.
That code can be replaced by the clamp() macro which does exactly the same. It results in a simpler routine to read.
--- drivers/thermal/gov_step_wise.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/thermal/gov_step_wise.c +4 -11
@@ -11,6 +11,7 @@*/ #include <linux/thermal.h> +#include <linux/minmax.h> #include <trace/events/thermal.h> #include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,if (!instance->initialized) {if (throttle) { - next_target = (cur_state +1 ) >= instance->upper ? - instance->upper : - ((cur_state +1 ) < instance->lower ? - instance->lower : (cur_state +1 )); + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }else { next_target =THERMAL_NO_TARGET ; }
@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,switch (trend) {case THERMAL_TREND_RAISING :if (throttle) { - next_target = cur_state < instance->upper ? - (cur_state +1 ) : instance->upper; -if (next_target < instance->lower) - next_target = instance->lower; + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ;case THERMAL_TREND_RAISE_FULL :
@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =THERMAL_NO_TARGET ; }else {if (!throttle) { - next_target = cur_state -1 ; -if (next_target > instance->upper) - next_target = instance->upper; + next_target =clamp ((cur_state -1 ), instance->lower, instance->upper); } }break ;
Signature · 1 line
2.25.1
PATCH 2/2 thermal/core: Remove DROP_FULL and RAISE_FULL
The trends DROP_FULL and RAISE_FULL are not used and were never used in the past AFAICT. Remove these conditions as they seems to not be handled anywhere.
--- drivers/thermal/gov_step_wise.c | 11 ----------- include/linux/thermal.h | 2 -- 2 files changed, 13 deletions(-)
drivers/thermal/gov_step_wise.c +0 -11
@@ -67,10 +67,6 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ; -case THERMAL_TREND_RAISE_FULL : -if (throttle) - next_target = instance->upper; -break ;case THERMAL_TREND_DROPPING :if (cur_state <= instance->lower) {if (!throttle)
@@ -81,13 +77,6 @@ static unsigned long get_target_state(struct thermal_instance *instance, } }break ; -case THERMAL_TREND_DROP_FULL : -if (cur_state == instance->lower) { -if (!throttle) - next_target =THERMAL_NO_TARGET ; - }else - next_target = instance->lower; -break ;default :break ; }
include/linux/thermal.h +0 -2
@@ -41,8 +41,6 @@ enum thermal_trend {THERMAL_TREND_STABLE ,/* temperature is stable */ THERMAL_TREND_RAISING ,/* temperature is raising */ THERMAL_TREND_DROPPING, /* temperature is dropping */ -THERMAL_TREND_RAISE_FULL ,/* apply highest cooling action */ - THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */ };/* Thermal notification reason */
Signature · 1 line
2.25.1
[thermal: thermal/next] thermal/core: Remove DROP_FULL and RAISE_FULL
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 4102c4042a33c682021683ec26c2dca3fd9d7cc2 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//4102c4042a33c682021683ec26c2dca3fd9d7cc2 Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 29 Jun 2022 17:10:12 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 28 Jul 2022 17:29:47 +02:00
thermal/core: Remove DROP_FULL and RAISE_FULL
The trends DROP_FULL and RAISE_FULL are not used and were never used in the past AFAICT. Remove these conditions as they seems to not be handled anywhere.
--- drivers/thermal/gov_step_wise.c | 11 ----------- include/linux/thermal.h | 2 -- 2 files changed, 13 deletions(-)
drivers/thermal/gov_step_wise.c +0 -11
@@ -67,10 +67,6 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ; -case THERMAL_TREND_RAISE_FULL : -if (throttle) - next_target = instance->upper; -break ;case THERMAL_TREND_DROPPING :if (cur_state <= instance->lower) {if (!throttle)
@@ -81,13 +77,6 @@ static unsigned long get_target_state(struct thermal_instance *instance, } }break ; -case THERMAL_TREND_DROP_FULL : -if (cur_state == instance->lower) { -if (!throttle) - next_target =THERMAL_NO_TARGET ; - }else - next_target = instance->lower; -break ;default :break ; }
include/linux/thermal.h +0 -2
@@ -40,8 +40,6 @@ enum thermal_trend {THERMAL_TREND_STABLE ,/* temperature is stable */ THERMAL_TREND_RAISING ,/* temperature is raising */ THERMAL_TREND_DROPPING, /* temperature is dropping */ -THERMAL_TREND_RAISE_FULL ,/* apply highest cooling action */ - THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */ };/* Thermal notification reason */
Quoted 8 lines · Daniel Lezcano
The code is actually clampling the next cooling device state using the lowest and highest states of the thermal instance.
That code can be replaced by the
clamp()macro which does exactly the same. It results in a simpler routine to read.Signed-off-by Daniel Lezcano <[email protected]>---
I'll apply this series if nobody has comments
Quoted 50 lines
drivers/thermal/gov_step_wise.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/thermal/gov_step_wise.c +4
-11@@ -11,6 +11,7 @@*/ #include <linux/thermal.h> +#include <linux/minmax.h> #include <trace/events/thermal.h> #include "thermal_core.h" @@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,if (!instance->initialized) {if (throttle) { - next_target = (cur_state +1 ) >= instance->upper ? - instance->upper : - ((cur_state +1 ) < instance->lower ? - instance->lower : (cur_state +1 )); + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }else { next_target =THERMAL_NO_TARGET ; }@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,switch (trend) {case THERMAL_TREND_RAISING :if (throttle) { - next_target = cur_state < instance->upper ? - (cur_state +1 ) : instance->upper; -if (next_target < instance->lower) - next_target = instance->lower; + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ;case THERMAL_TREND_RAISE_FULL :@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =THERMAL_NO_TARGET ; }else {if (!throttle) { - next_target = cur_state -1 ; -if (next_target > instance->upper) - next_target = instance->upper; + next_target =clamp ((cur_state -1 ), instance->lower, instance->upper); } }break ;
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Rafael J. Wysocki
maintainerQuoted 5 lines · Daniel Lezcano
Quoted 3 lines · Daniel Lezcano
The code is actually clampling the next cooling device state using the lowest and highest states of the thermal instance.
Quoted 7 lines
Quoted 5 lines
That code can be replaced by the
clamp()macro which does exactly the same. It results in a simpler routine to read.Signed-off-by Daniel Lezcano <[email protected]>---
I'll apply this series if nobody has comments
Sounds good to me.
Please feel free to add ACKs from me to the patches.
Quoted 59 lines
Quoted 41 lines
drivers/thermal/gov_step_wise.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/thermal/gov_step_wise.c +3
-8@@ -11,6 +11,7 @@*/ #include <linux/thermal.h> +#include <linux/minmax.h> #include <trace/events/thermal.h> #include "thermal_core.h" @@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,if (!instance->initialized) {if (throttle) { - next_target = (cur_state +1 ) >= instance->upper ? - instance->upper : - ((cur_state +1 ) < instance->lower ? - instance->lower : (cur_state +1 )); + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }else { next_target =THERMAL_NO_TARGET ; }@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,switch (trend) {case THERMAL_TREND_RAISING :if (throttle) { - next_target = cur_state < instance->upper ? - (cur_state +1 ) : instance->upper; -if (next_target < instance->lower) - next_target = instance->lower; + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ;case THERMAL_TREND_RAISE_FULL :drivers/thermal/gov_step_wise.c static unsigned long get_target_state(struct thermal_instance *instance, · line 83
Quoted 10 lines
drivers/thermal/gov_step_wise.c +1
-3@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =THERMAL_NO_TARGET ; }else {if (!throttle) { - next_target = cur_state -1 ; -if (next_target > instance->upper) - next_target = instance->upper; + next_target =clamp ((cur_state -1 ), instance->lower, instance->upper); } }break ;--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCsFollow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Daniel Lezcano
Quoted 6 lines · Daniel Lezcano
The code is actually clampling the next cooling device state using the lowest and highest states of the thermal instance.
That code can be replaced by the
clamp()macro which does exactly the same. It results in a simpler routine to read.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Daniel Lezcano <[email protected]>---
I'll apply this series if nobody has comments
Sounds good to me.
Please feel free to add ACKs from me to the patches.
Sure, thanks!
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 25bff3ed9a8aaee45c3b554cca58673f1bea1bdc Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//25bff3ed9a8aaee45c3b554cca58673f1bea1bdc Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 29 Jun 2022 17:10:11 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 28 Jul 2022 17:29:47 +02:00
thermal/core: Use clamp() helper in the stepwise governor
The code is actually clampling the next cooling device state using the lowest and highest states of the thermal instance.
That code can be replaced by the clamp() macro which does exactly the same. It results in a simpler routine to read.
--- drivers/thermal/gov_step_wise.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/thermal/gov_step_wise.c +4 -11
@@ -11,6 +11,7 @@*/ #include <linux/thermal.h> +#include <linux/minmax.h> #include <trace/events/thermal.h> #include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,if (!instance->initialized) {if (throttle) { - next_target = (cur_state +1 ) >= instance->upper ? - instance->upper : - ((cur_state +1 ) < instance->lower ? - instance->lower : (cur_state +1 )); + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }else { next_target =THERMAL_NO_TARGET ; }
@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,switch (trend) {case THERMAL_TREND_RAISING :if (throttle) { - next_target = cur_state < instance->upper ? - (cur_state +1 ) : instance->upper; -if (next_target < instance->lower) - next_target = instance->lower; + next_target =clamp ((cur_state +1 ), instance->lower, instance->upper); }break ;case THERMAL_TREND_RAISE_FULL :
@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, next_target =THERMAL_NO_TARGET ; }else {if (!throttle) { - next_target = cur_state -1 ; -if (next_target > instance->upper) - next_target = instance->upper; + next_target =clamp ((cur_state -1 ), instance->lower, instance->upper); } }break ;