All of lore.kernel.org
 help / color / mirror / Atom feed
From: zhuguangqing83@gmail.com
To: Amit Daniel Kachhap <amit.kachhap@gmail.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Javi Merino <javi.merino@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>, Amit Kucheria <amitk@kernel.org>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Guangqing Zhu <zhuguangqing83@gmail.com>
Subject: [PATCH] thermal/drivers/cpuidle_cooling: Make sure that idle_duration is larger than residency
Date: Fri,  2 Apr 2021 12:56:14 +0800	[thread overview]
Message-ID: <20210402045615.22630-1-zhuguangqing83@gmail.com> (raw)

From: Guangqing Zhu <zhuguangqing83@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 <zhuguangqing83@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	other threads:[~2021-04-02  4:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210402045615.22630-1-zhuguangqing83@gmail.com \
    --to=zhuguangqing83@gmail.com \
    --cc=amit.kachhap@gmail.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=javi.merino@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.