From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Kajetan Puchalski <kajetan.puchalski@arm.com>
Subject: [PATCH v2 1/3] cpuidle: teo: Update idle duration estimate when choosing shallower state
Date: Fri, 28 Jul 2023 11:58:45 +0200 [thread overview]
Message-ID: <13326870.uLZWGnKmhe@kreacher> (raw)
In-Reply-To: <5707588.DvuYhMxLoT@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
The TEO governor takes CPU utilization into account by refining idle state
selection when the utilization is above a certain threshold. This is done by
choosing an idle state shallower than the previously selected one.
However, when doing this, the idle duration estimate needs to be
adjusted so as to prevent the scheduler tick from being stopped when the
candidate idle state is shallow, which may lead to excessive energy
usage if the CPU is not woken up quickly enough going forward.
Moreover, if the scheduler tick has been stopped already and the new
idle duration estimate is too small, the replacement candidate state
cannot be used.
Modify the relevant code to take the above observations into account.
Fixes: 9ce0f7c4bc64 ("cpuidle: teo: Introduce util-awareness")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v2:
* Rework the code handling the special case when the CPU is utilized and
there are only 2 idle states (drop the loop, avoid using state 0 when
the tick has been stopped already and it is too shallow, check if
state 1 is not disabled when about to use it, set low idle duration
estimate).
* Changelog edits.
---
drivers/cpuidle/governors/teo.c | 43 ++++++++++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 10 deletions(-)
Index: linux-pm/drivers/cpuidle/governors/teo.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/teo.c
+++ linux-pm/drivers/cpuidle/governors/teo.c
@@ -397,13 +397,26 @@ static int teo_select(struct cpuidle_dri
* the shallowest non-polling state and exit.
*/
if (drv->state_count < 3 && cpu_data->utilized) {
- for (i = 0; i < drv->state_count; ++i) {
- if (!dev->states_usage[i].disable &&
- !(drv->states[i].flags & CPUIDLE_FLAG_POLLING)) {
- idx = i;
- goto end;
- }
- }
+ /* The CPU is utilized, so assume a short idle duration. */
+ duration_ns = teo_middle_of_bin(0, drv);
+ /*
+ * If state 0 is enabled and it is not a polling one, select it
+ * right away unless the scheduler tick has been stopped, in
+ * which case care needs to be taken to leave the CPU in a
+ * deep enough state in case it is not woken up any time soon
+ * after all.
+ */
+ if (!idx && !(drv->states[0].flags & CPUIDLE_FLAG_POLLING) &&
+ teo_time_ok(duration_ns))
+ goto end;
+
+ /*
+ * Assume that state 1 is not a polling one and select it
+ * unless it is disabled, in which case state 0 must be used
+ * no matter what.
+ */
+ idx = dev->states_usage[1].disable ? 0 : 1;
+ goto end;
}
/*
@@ -539,10 +552,20 @@ static int teo_select(struct cpuidle_dri
/*
* If the CPU is being utilized over the threshold, choose a shallower
- * non-polling state to improve latency
+ * non-polling state to improve latency, unless the scheduler tick has
+ * been stopped already and the shallower state's target residency is
+ * not sufficiently large.
*/
- if (cpu_data->utilized)
- idx = teo_find_shallower_state(drv, dev, idx, duration_ns, true);
+ if (cpu_data->utilized) {
+ s64 span_ns;
+
+ i = teo_find_shallower_state(drv, dev, idx, duration_ns, true);
+ span_ns = teo_middle_of_bin(i, drv);
+ if (teo_time_ok(span_ns)) {
+ idx = i;
+ duration_ns = span_ns;
+ }
+ }
end:
/*
next prev parent reply other threads:[~2023-07-28 10:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 9:35 [PATCH v2 0/3] cpuidle: teo: Avoid stopping scheduler tick too often Rafael J. Wysocki
2023-07-28 9:58 ` Rafael J. Wysocki [this message]
2023-07-28 10:00 ` [PATCH v2 2/3] cpuidle: teo: Avoid stopping the tick unnecessarily when bailing out Rafael J. Wysocki
2023-07-28 10:01 ` [PATCH v2 3/3] cpuidle: teo: Drop utilized from struct teo_cpu Rafael J. Wysocki
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=13326870.uLZWGnKmhe@kreacher \
--to=rjw@rjwysocki.net \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=kajetan.puchalski@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox