From: Guangqing Zhu <zhuguangqin...@gmail.com>

The injected idle duration should be greater than the idle state min
residency, otherwise we end up consuming more energy and potentially invert
the mitigation effect.

In function __cpuidle_cooling_register(), if
of_property_read_u32(np, "exit-latency-us", &latency_us) is failed, then
maybe we should not use latency_us. In this case, a zero latency_us for
forced_idle_latency_limit_ns is better than UMAX_INT. It means to use
governors in the usual way.

Signed-off-by: Guangqing Zhu <zhuguangqin...@gmail.com>
---
 drivers/powercap/idle_inject.c    | 1 -
 drivers/thermal/cpuidle_cooling.c | 8 +++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c
index 6e1a0043c411..d76eef1e9387 100644
--- a/drivers/powercap/idle_inject.c
+++ b/drivers/powercap/idle_inject.c
@@ -309,7 +309,6 @@ struct idle_inject_device *idle_inject_register(struct 
cpumask *cpumask)
        cpumask_copy(to_cpumask(ii_dev->cpumask), cpumask);
        hrtimer_init(&ii_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        ii_dev->timer.function = idle_inject_timer_fn;
-       ii_dev->latency_us = UINT_MAX;
 
        for_each_cpu(cpu, to_cpumask(ii_dev->cpumask)) {
 
diff --git a/drivers/thermal/cpuidle_cooling.c 
b/drivers/thermal/cpuidle_cooling.c
index 7ecab4b16b29..de770eb5b2ba 100644
--- a/drivers/thermal/cpuidle_cooling.c
+++ b/drivers/thermal/cpuidle_cooling.c
@@ -175,7 +175,8 @@ static int __cpuidle_cooling_register(struct device_node 
*np,
        struct cpuidle_cooling_device *idle_cdev;
        struct thermal_cooling_device *cdev;
        unsigned int idle_duration_us = TICK_USEC;
-       unsigned int latency_us = UINT_MAX;
+       unsigned int latency_us = 0;
+       unsigned int residency_us = UINT_MAX;
        char dev_name[THERMAL_NAME_LENGTH];
        int id, ret;
 
@@ -199,6 +200,11 @@ static int __cpuidle_cooling_register(struct device_node 
*np,
 
        of_property_read_u32(np, "duration-us", &idle_duration_us);
        of_property_read_u32(np, "exit-latency-us", &latency_us);
+       of_property_read_u32(np, "min-residency-us", &residency_us);
+       if (idle_duration_us <= residency_us) {
+               ret = -EINVAL;
+               goto out_unregister;
+       }
 
        idle_inject_set_duration(ii_dev, TICK_USEC, idle_duration_us);
        idle_inject_set_latency(ii_dev, latency_us);
-- 
2.17.1

Reply via email to