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. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20220629151012.3115773-1-daniel.lezcano@linaro.org Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
This commit is contained in:
parent
66a0b101ef
commit
25bff3ed9a
|
@ -11,6 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/thermal.h>
|
#include <linux/thermal.h>
|
||||||
|
#include <linux/minmax.h>
|
||||||
#include <trace/events/thermal.h>
|
#include <trace/events/thermal.h>
|
||||||
|
|
||||||
#include "thermal_core.h"
|
#include "thermal_core.h"
|
||||||
|
@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
|
||||||
|
|
||||||
if (!instance->initialized) {
|
if (!instance->initialized) {
|
||||||
if (throttle) {
|
if (throttle) {
|
||||||
next_target = (cur_state + 1) >= instance->upper ?
|
next_target = clamp((cur_state + 1), instance->lower, instance->upper);
|
||||||
instance->upper :
|
|
||||||
((cur_state + 1) < instance->lower ?
|
|
||||||
instance->lower : (cur_state + 1));
|
|
||||||
} else {
|
} else {
|
||||||
next_target = THERMAL_NO_TARGET;
|
next_target = THERMAL_NO_TARGET;
|
||||||
}
|
}
|
||||||
|
@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
|
||||||
switch (trend) {
|
switch (trend) {
|
||||||
case THERMAL_TREND_RAISING:
|
case THERMAL_TREND_RAISING:
|
||||||
if (throttle) {
|
if (throttle) {
|
||||||
next_target = cur_state < instance->upper ?
|
next_target = clamp((cur_state + 1), instance->lower, instance->upper);
|
||||||
(cur_state + 1) : instance->upper;
|
|
||||||
if (next_target < instance->lower)
|
|
||||||
next_target = instance->lower;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case THERMAL_TREND_RAISE_FULL:
|
case THERMAL_TREND_RAISE_FULL:
|
||||||
|
@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
|
||||||
next_target = THERMAL_NO_TARGET;
|
next_target = THERMAL_NO_TARGET;
|
||||||
} else {
|
} else {
|
||||||
if (!throttle) {
|
if (!throttle) {
|
||||||
next_target = cur_state - 1;
|
next_target = clamp((cur_state - 1), instance->lower, instance->upper);
|
||||||
if (next_target > instance->upper)
|
|
||||||
next_target = instance->upper;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue