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 4/7] cpuidle: menu: Split idle duration prediction from state selection
Date: Sun, 04 Mar 2018 23:26:24 +0100 [thread overview]
Message-ID: <2332986.m9oRvTSu8E@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, prepare the
menu governor code for reordering with respect to the timekeeping
code that stops the tick.
Use the observation that menu_select() can be split into two
functions, one predicting the idle duration and one selecting the
idle state, and rework it accordingly.
Introduce menu_predict() to predict the idle duration and (for now)
call it from menu_select(). The next set of changes will use
menu_predict() as a new governor callback.
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/governors/menu.c | 68 +++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 30 deletions(-)
Index: linux-pm/drivers/cpuidle/governors/menu.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/menu.c
+++ linux-pm/drivers/cpuidle/governors/menu.c
@@ -130,6 +130,7 @@ struct menu_device {
unsigned int correction_factor[BUCKETS];
unsigned int intervals[INTERVALS];
int interval_ptr;
+ int latency_req;
};
@@ -275,36 +276,30 @@ again:
goto again;
}
-/**
- * menu_select - selects the next idle state to enter
- * @drv: cpuidle driver containing state data
- * @dev: the CPU
- */
-static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
+static void 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);
- int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
- int i;
- int first_idx;
- int idx;
+ int resume_latency = dev_pm_qos_raw_read_value(device);
unsigned int interactivity_req;
unsigned int expected_interval;
unsigned long nr_iowaiters, cpu_load;
- int resume_latency = dev_pm_qos_raw_read_value(device);
if (data->needs_update) {
menu_update(drv, dev);
data->needs_update = 0;
}
- if (resume_latency < latency_req &&
+ data->latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
+ if (resume_latency < data->latency_req &&
resume_latency != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
- latency_req = resume_latency;
+ data->latency_req = resume_latency;
/* Special case when user has set very strict latency requirement */
- if (unlikely(latency_req == 0))
- return 0;
+ if (unlikely(data->latency_req == 0)) {
+ data->predicted_us = 0;
+ return;
+ }
/* determine the expected residency time, round up */
data->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length());
@@ -324,6 +319,32 @@ static int menu_select(struct cpuidle_dr
expected_interval = get_typical_interval(data);
expected_interval = min(expected_interval, data->next_timer_us);
+ /*
+ * Use the lowest expected idle interval to pick the idle state.
+ */
+ data->predicted_us = min(data->predicted_us, expected_interval);
+
+ /*
+ * Use the performance multiplier and the user-configurable
+ * latency_req to determine the maximum exit latency.
+ */
+ interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load);
+ if (data->latency_req > interactivity_req)
+ data->latency_req = interactivity_req;
+}
+
+/**
+ * menu_select - selects the next idle state to enter
+ * @drv: cpuidle driver containing state data
+ * @dev: the CPU
+ */
+static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
+{
+ 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];
@@ -336,25 +357,12 @@ static int menu_select(struct cpuidle_dr
*/
polling_threshold = max_t(unsigned int, 20, s->target_residency);
if (data->next_timer_us > polling_threshold &&
- latency_req > s->exit_latency && !s->disabled &&
+ data->latency_req > s->exit_latency && !s->disabled &&
!dev->states_usage[1].disable)
first_idx = 1;
}
/*
- * Use the lowest expected idle interval to pick the idle state.
- */
- data->predicted_us = min(data->predicted_us, expected_interval);
-
- /*
- * Use the performance multiplier and the user-configurable
- * latency_req to determine the maximum exit latency.
- */
- interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load);
- if (latency_req > interactivity_req)
- latency_req = interactivity_req;
-
- /*
* Find the idle state with the lowest power while satisfying
* our constraints.
*/
@@ -369,7 +377,7 @@ static int menu_select(struct cpuidle_dr
idx = i; /* first enabled state */
if (s->target_residency > data->predicted_us)
break;
- if (s->exit_latency > latency_req)
+ if (s->exit_latency > data->latency_req)
break;
idx = i;
next prev parent reply other threads:[~2018-03-04 22:26 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 ` Rafael J. Wysocki [this message]
2018-03-05 11:38 ` [RFC/RFT][PATCH 4/7] cpuidle: menu: Split idle duration prediction from state selection 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 ` [RFC/RFT][PATCH 5/7] cpuidle: New governor callback for predicting idle duration Rafael J. Wysocki
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=2332986.m9oRvTSu8E@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