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 2/3] cpuidle: teo: Avoid stopping the tick unnecessarily when bailing out
Date: Fri, 28 Jul 2023 12:00:46 +0200 [thread overview]
Message-ID: <3254124.aeNJFYEL58@kreacher> (raw)
In-Reply-To: <5707588.DvuYhMxLoT@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
When teo_select() is going to return early in some special cases, make
it avoid stopping the tick if the idle state to be returned is shallow.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpuidle/governors/teo.c | 50 +++++++++++++++++++++++++---------------
1 file changed, 32 insertions(+), 18 deletions(-)
Index: linux-pm/drivers/cpuidle/governors/teo.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/teo.c
+++ linux-pm/drivers/cpuidle/governors/teo.c
@@ -462,9 +462,9 @@ static int teo_select(struct cpuidle_dri
/* Avoid unnecessary overhead. */
if (idx < 0) {
idx = 0; /* No states enabled, must use 0. */
- goto end;
+ goto bail_out;
} else if (idx == idx0) {
- goto end;
+ goto bail_out;
}
/*
@@ -547,8 +547,10 @@ static int teo_select(struct cpuidle_dri
* If there is a latency constraint, it may be necessary to select an
* idle state shallower than the current candidate one.
*/
- if (idx > constraint_idx)
+ if (idx > constraint_idx) {
idx = constraint_idx;
+ goto bail_out;
+ }
/*
* If the CPU is being utilized over the threshold, choose a shallower
@@ -569,23 +571,35 @@ static int teo_select(struct cpuidle_dri
end:
/*
- * Don't stop the tick if the selected state is a polling one or if the
- * expected idle duration is shorter than the tick period length.
+ * Allow the tick to be stopped unless the selected state is a polling
+ * one or the expected idle duration is shorter than the tick period
+ * length.
*/
- if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) ||
- duration_ns < TICK_NSEC) && !tick_nohz_tick_stopped()) {
- *stop_tick = false;
+ if ((!(drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
+ duration_ns >= TICK_NSEC) || tick_nohz_tick_stopped())
+ return idx;
- /*
- * The tick is not going to be stopped, so if the target
- * residency of the state to be returned is not within the time
- * till the closest timer including the tick, try to correct
- * that.
- */
- if (idx > idx0 &&
- drv->states[idx].target_residency_ns > delta_tick)
- idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false);
- }
+retain_tick:
+ *stop_tick = false;
+
+ /*
+ * The tick is not going to be stopped, so if the target residency of
+ * the state to be returned is not within the time till the closest
+ * timer including the tick, try to correct that.
+ */
+ if (idx > idx0 &&
+ drv->states[idx].target_residency_ns > delta_tick)
+ idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false);
+
+ return idx;
+
+bail_out:
+ /*
+ * Do not allow the tick to be stopped if the selected state is shallow
+ * enough.
+ */
+ if (drv->states[idx].target_residency_ns < TICK_NSEC)
+ goto retain_tick;
return idx;
}
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 ` [PATCH v2 1/3] cpuidle: teo: Update idle duration estimate when choosing shallower state Rafael J. Wysocki
2023-07-28 10:00 ` Rafael J. Wysocki [this message]
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=3254124.aeNJFYEL58@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