From: Aubrey Li <aubrey.li@intel.com>
To: tglx@linutronix.de, peterz@infradead.org, rjw@rjwysocki.net,
len.brown@intel.com, ak@linux.intel.com,
tim.c.chen@linux.intel.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Aubrey Li <aubrey.li@intel.com>,
Aubrey Li <aubrey.li@linux.intel.com>
Subject: [RFC PATCH v2 2/8] cpuidle: record the overhead of idle entry
Date: Sat, 30 Sep 2017 15:20:28 +0800 [thread overview]
Message-ID: <1506756034-6340-3-git-send-email-aubrey.li@intel.com> (raw)
In-Reply-To: <1506756034-6340-1-git-send-email-aubrey.li@intel.com>
Record the overhead of idle entry in micro-second
Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
---
drivers/cpuidle/cpuidle.c | 33 +++++++++++++++++++++++++++++++++
include/linux/cpuidle.h | 14 ++++++++++++++
kernel/sched/idle.c | 8 +++++++-
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 60bb64f..4066308 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -302,6 +302,39 @@ void cpuidle_reflect(struct cpuidle_device *dev, int index)
cpuidle_curr_governor->reflect(dev, index);
}
+/* cpuidle_entry_start - record idle entry start */
+void cpuidle_entry_start(void)
+{
+ struct cpuidle_device *dev = cpuidle_get_device();
+
+ if (dev)
+ dev->idle_stat.entry_start = local_clock();
+}
+
+/*
+ * cpuidle_entry_end - record idle entry end, and maintain
+ * the entry overhead average in micro-second
+ */
+void cpuidle_entry_end(void)
+{
+ struct cpuidle_device *dev = cpuidle_get_device();
+ u64 overhead;
+ s64 diff;
+
+ if (dev) {
+ dev->idle_stat.entry_end = local_clock();
+ overhead = div_u64(dev->idle_stat.entry_end -
+ dev->idle_stat.entry_start, NSEC_PER_USEC);
+ diff = overhead - dev->idle_stat.overhead;
+ dev->idle_stat.overhead += diff >> 3;
+ /*
+ * limit overhead to 1us
+ */
+ if (dev->idle_stat.overhead == 0)
+ dev->idle_stat.overhead = 1;
+ }
+}
+
/**
* cpuidle_install_idle_handler - installs the cpuidle idle loop handler
*/
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index fc1e5d7..cad9b71 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -72,6 +72,15 @@ struct cpuidle_device_kobj;
struct cpuidle_state_kobj;
struct cpuidle_driver_kobj;
+struct cpuidle_stat {
+ u64 entry_start; /* nanosecond */
+ u64 entry_end; /* nanosecond */
+ u64 overhead; /* nanosecond */
+ unsigned int predicted_us; /* microsecond */
+ bool predicted; /* ever predicted? */
+ bool fast_idle; /* fast idle? */
+};
+
struct cpuidle_device {
unsigned int registered:1;
unsigned int enabled:1;
@@ -89,6 +98,7 @@ struct cpuidle_device {
cpumask_t coupled_cpus;
struct cpuidle_coupled *coupled;
#endif
+ struct cpuidle_stat idle_stat;
};
DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
@@ -131,6 +141,8 @@ extern bool cpuidle_not_available(struct cpuidle_driver *drv,
extern int cpuidle_select(struct cpuidle_driver *drv,
struct cpuidle_device *dev);
+extern void cpuidle_entry_start(void);
+extern void cpuidle_entry_end(void);
extern int cpuidle_enter(struct cpuidle_driver *drv,
struct cpuidle_device *dev, int index);
extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
@@ -164,6 +176,8 @@ static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
static inline int cpuidle_select(struct cpuidle_driver *drv,
struct cpuidle_device *dev)
{return -ENODEV; }
+static inline void cpuidle_entry_start(void) { }
+static inline void cpuidle_entry_end(void) { }
static inline int cpuidle_enter(struct cpuidle_driver *drv,
struct cpuidle_device *dev, int index)
{return -ENODEV; }
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 6c23e30..0951dac 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -210,6 +210,12 @@ static void cpuidle_idle_call(void)
static void do_idle(void)
{
/*
+ * we record idle entry overhead now, so any deferrable items
+ * in idle entry path need to be placed between cpuidle_entry_start()
+ * and cpuidle_entry_end()
+ */
+ cpuidle_entry_start();
+ /*
* If the arch has a polling bit, we maintain an invariant:
*
* Our polling bit is clear if we're not scheduled (i.e. if rq->curr !=
@@ -217,10 +223,10 @@ static void do_idle(void)
* then setting need_resched is guaranteed to cause the CPU to
* reschedule.
*/
-
__current_set_polling();
quiet_vmstat();
tick_nohz_idle_enter();
+ cpuidle_entry_end();
while (!need_resched()) {
check_pgt_cache();
--
2.7.4
next prev parent reply other threads:[~2017-09-30 7:21 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-30 7:20 [RFC PATCH v2 0/8] Introduct cpu idle prediction functionality Aubrey Li
2017-09-30 7:20 ` [RFC PATCH v2 1/8] cpuidle: menu: extract " Aubrey Li
2017-10-14 0:26 ` Rafael J. Wysocki
2017-10-16 2:46 ` Li, Aubrey
2017-09-30 7:20 ` Aubrey Li [this message]
2017-10-14 0:35 ` [RFC PATCH v2 2/8] cpuidle: record the overhead of idle entry Rafael J. Wysocki
2017-10-16 3:11 ` Li, Aubrey
2017-10-17 0:05 ` Rafael J. Wysocki
2017-10-17 7:04 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 3/8] cpuidle: add a new predict interface Aubrey Li
2017-10-14 0:45 ` Rafael J. Wysocki
2017-10-16 8:04 ` Li, Aubrey
2017-10-14 1:27 ` Rafael J. Wysocki
2017-10-16 9:52 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 4/8] tick/nohz: keep tick on for a fast idle Aubrey Li
2017-10-14 0:51 ` Rafael J. Wysocki
2017-10-16 3:26 ` Li, Aubrey
2017-10-16 4:45 ` Mike Galbraith
2017-10-16 5:34 ` Li, Aubrey
2017-10-16 6:25 ` Mike Galbraith
2017-10-16 6:31 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 5/8] timers: keep sleep length updated as needed Aubrey Li
2017-10-14 0:56 ` Rafael J. Wysocki
2017-10-16 6:46 ` Li, Aubrey
2017-10-16 23:58 ` Rafael J. Wysocki
2017-10-17 6:10 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 6/8] cpuidle: make fast idle threshold tunable Aubrey Li
2017-10-14 0:59 ` Rafael J. Wysocki
2017-10-16 6:00 ` Li, Aubrey
2017-10-17 0:01 ` Rafael J. Wysocki
2017-10-17 6:12 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 7/8] cpuidle: introduce irq timing to make idle prediction Aubrey Li
2017-10-14 1:01 ` Rafael J. Wysocki
2017-10-16 6:03 ` Li, Aubrey
2017-09-30 7:20 ` [RFC PATCH v2 8/8] cpuidle: introduce run queue average idle " Aubrey Li
2017-10-14 1:02 ` Rafael J. Wysocki
2017-10-14 1:14 ` [RFC PATCH v2 0/8] Introduct cpu idle prediction functionality Rafael J. Wysocki
2017-10-16 7:44 ` Li, Aubrey
2017-10-17 0:07 ` Rafael J. Wysocki
2017-10-17 7:32 ` Li, Aubrey
2017-11-30 1:00 ` Li, Aubrey
2017-11-30 1:37 ` 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=1506756034-6340-3-git-send-email-aubrey.li@intel.com \
--to=aubrey.li@intel.com \
--cc=ak@linux.intel.com \
--cc=aubrey.li@linux.intel.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®