From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>,
Thomas Ilsche <thomas.ilsche@tu-dresden.de>,
Doug Smythies <dsmythies@telus.net>,
Rik van Riel <riel@surriel.com>,
Aubrey Li <aubrey.li@linux.intel.com>,
Mike Galbraith <mgalbraith@suse.de>,
LKML <linux-kernel@vger.kernel.org>,
Linux PM <linux-pm@vger.kernel.org>
Subject: [RFC/RFT][PATCH 5/7] cpuidle: New governor callback for predicting idle duration
Date: Sun, 04 Mar 2018 23:27:32 +0100 [thread overview]
Message-ID: <24524352.zYArR4Buth@aspire.rjw.lan> (raw)
In-Reply-To: <1657351.s4RTvEoqBQ@aspire.rjw.lan>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
In order to address the issue with short idle duration predictions
by the idle governor after the tick has been stopped, introduce a
new cpuidle governor callback for predicting idle duration and make
cpuidle_select() use it to obtain an idle duration estimate. Also
make cpuidle_select() return the expected idle duration to its caller
through an additional argument pointer.
For the menu governor, make the new callback pointer point to the
menu_predict() routine introduced previously and stop calling it
directly from menu_select().
This change is not expected to alter the functionality of the code.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpuidle/cpuidle.c | 37 +++++++++++++++++++++++++++++++++++--
drivers/cpuidle/governors/menu.c | 10 ++++++----
include/linux/cpuidle.h | 5 ++++-
kernel/sched/idle.c | 4 +++-
4 files changed, 48 insertions(+), 8 deletions(-)
Index: linux-pm/include/linux/cpuidle.h
===================================================================
--- linux-pm.orig/include/linux/cpuidle.h
+++ linux-pm/include/linux/cpuidle.h
@@ -131,7 +131,8 @@ extern bool cpuidle_not_available(struct
struct cpuidle_device *dev);
extern int cpuidle_select(struct cpuidle_driver *drv,
- struct cpuidle_device *dev);
+ struct cpuidle_device *dev,
+ unsigned int *duration_us_ptr);
extern int cpuidle_enter(struct cpuidle_driver *drv,
struct cpuidle_device *dev, int index);
extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
@@ -245,6 +246,8 @@ struct cpuidle_governor {
void (*disable) (struct cpuidle_driver *drv,
struct cpuidle_device *dev);
+ unsigned int (*predict) (struct cpuidle_driver *drv,
+ struct cpuidle_device *dev);
int (*select) (struct cpuidle_driver *drv,
struct cpuidle_device *dev);
void (*reflect) (struct cpuidle_device *dev, int index);
Index: linux-pm/drivers/cpuidle/governors/menu.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/menu.c
+++ linux-pm/drivers/cpuidle/governors/menu.c
@@ -276,7 +276,8 @@ again:
goto again;
}
-static void menu_predict(struct cpuidle_driver *drv, struct cpuidle_device *dev)
+static unsigned int menu_predict(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev)
{
struct menu_device *data = this_cpu_ptr(&menu_devices);
struct device *device = get_cpu_device(dev->cpu);
@@ -298,7 +299,7 @@ static void menu_predict(struct cpuidle_
/* Special case when user has set very strict latency requirement */
if (unlikely(data->latency_req == 0)) {
data->predicted_us = 0;
- return;
+ return 0;
}
/* determine the expected residency time, round up */
@@ -331,6 +332,8 @@ static void menu_predict(struct cpuidle_
interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load);
if (data->latency_req > interactivity_req)
data->latency_req = interactivity_req;
+
+ return data->predicted_us;
}
/**
@@ -343,8 +346,6 @@ static int menu_select(struct cpuidle_dr
struct menu_device *data = this_cpu_ptr(&menu_devices);
int first_idx, idx, i;
- menu_predict(drv, dev);
-
first_idx = 0;
if (drv->states[0].flags & CPUIDLE_FLAG_POLLING) {
struct cpuidle_state *s = &drv->states[1];
@@ -505,6 +506,7 @@ static struct cpuidle_governor menu_gove
.name = "menu",
.rating = 20,
.enable = menu_enable_device,
+ .predict = menu_predict,
.select = menu_select,
.reflect = menu_reflect,
};
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/cpuidle.c
+++ linux-pm/drivers/cpuidle/cpuidle.c
@@ -263,12 +263,45 @@ int cpuidle_enter_state(struct cpuidle_d
*
* @drv: the cpuidle driver
* @dev: the cpuidle device
+ * @duration_us_ptr: pointer to return the expected duration of idle period
*
* Returns the index of the idle state. The return value must not be negative.
+ *
+ * The memory location pointed to by @duration_us_ptr is written the expected
+ * duration of the upcoming idle period, in microseconds.
*/
-int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
+int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
+ unsigned int *duration_us_ptr)
{
- return cpuidle_curr_governor->select(drv, dev);
+ unsigned int duration_us;
+ int ret, i;
+
+ if (!cpuidle_curr_governor->predict) {
+ ret = cpuidle_curr_governor->select(drv, dev);
+ *duration_us_ptr = drv->states[ret].target_residency;
+ return ret;
+ }
+
+ duration_us = cpuidle_curr_governor->predict(drv, dev);
+
+ ret = cpuidle_curr_governor->select(drv, dev);
+
+ /*
+ * Return the target residency of the selected state as the expected
+ * idle period duration if there are any states available with target
+ * residencies greater than the predicted idle period duration (to
+ * avoid staying in a shallow state for too long).
+ */
+ for (i = ret + 1; i < drv->state_count; i++)
+ if (!drv->states[i].disabled &&
+ !dev->states_usage[i].disable &&
+ drv->states[i].target_residency > duration_us) {
+ duration_us = drv->states[ret].target_residency;
+ break;
+ }
+
+ *duration_us_ptr = duration_us;
+ return ret;
}
/**
Index: linux-pm/kernel/sched/idle.c
===================================================================
--- linux-pm.orig/kernel/sched/idle.c
+++ linux-pm/kernel/sched/idle.c
@@ -186,13 +186,15 @@ static void cpuidle_idle_call(void)
next_state = cpuidle_find_deepest_state(drv, dev);
call_cpuidle(drv, dev, next_state);
} else {
+ unsigned int duration_us;
+
tick_nohz_idle_go_idle(true);
rcu_idle_enter();
/*
* Ask the cpuidle framework to choose a convenient idle state.
*/
- next_state = cpuidle_select(drv, dev);
+ next_state = cpuidle_select(drv, dev, &duration_us);
entered_state = call_cpuidle(drv, dev, next_state);
/*
* Give the governor an opportunity to reflect on the outcome
next prev parent reply other threads:[~2018-03-04 22:27 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-04 22:21 [RFC/RFT][PATCH 0/7] sched/cpuidle: Idle loop rework Rafael J. Wysocki
2018-03-04 22:24 ` [RFC/RFT][PATCH 1/7] time: tick-sched: Reorganize idle tick management code Rafael J. Wysocki
2018-03-05 10:44 ` Peter Zijlstra
2018-03-05 11:26 ` Rafael J. Wysocki
2018-03-04 22:24 ` [RFC/RFT][PATCH 2/7] sched: idle: Do not stop the tick upfront in the idle loop Rafael J. Wysocki
2018-03-04 22:24 ` [RFC/RFT][PATCH 3/7] sched: idle: Do not stop the tick before cpuidle_idle_call() Rafael J. Wysocki
2018-03-04 22:26 ` [RFC/RFT][PATCH 4/7] cpuidle: menu: Split idle duration prediction from state selection Rafael J. Wysocki
2018-03-05 11:38 ` Peter Zijlstra
2018-03-05 11:47 ` Rafael J. Wysocki
2018-03-05 12:50 ` Peter Zijlstra
2018-03-05 13:05 ` Rafael J. Wysocki
2018-03-05 13:53 ` Peter Zijlstra
2018-03-06 2:15 ` Li, Aubrey
2018-03-06 8:45 ` Peter Zijlstra
2018-03-06 14:07 ` Li, Aubrey
2018-03-04 22:27 ` Rafael J. Wysocki [this message]
2018-03-04 22:28 ` [RFC/RFT][PATCH 6/7] sched: idle: Predict idle duration before stopping the tick Rafael J. Wysocki
2018-03-05 11:45 ` Peter Zijlstra
2018-03-05 11:50 ` Rafael J. Wysocki
2018-03-05 12:07 ` Rafael J. Wysocki
2018-03-05 12:42 ` Peter Zijlstra
2018-03-05 13:00 ` Rafael J. Wysocki
2018-03-05 12:35 ` Peter Zijlstra
2018-03-05 12:56 ` Rafael J. Wysocki
2018-03-05 13:19 ` Rik van Riel
2018-03-05 13:37 ` Peter Zijlstra
2018-03-05 13:46 ` Peter Zijlstra
2018-03-05 15:36 ` Thomas Ilsche
2018-03-05 16:50 ` Peter Zijlstra
2018-03-05 23:27 ` Rik van Riel
2018-03-06 8:18 ` Rafael J. Wysocki
2018-03-04 22:29 ` [RFC/RFT][PATCH 7/7] time: tick-sched: Avoid running the same code twice in a row 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=24524352.zYArR4Buth@aspire.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=aubrey.li@linux.intel.com \
--cc=dsmythies@telus.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgalbraith@suse.de \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=tglx@linutronix.de \
--cc=thomas.ilsche@tu-dresden.de \
/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