[PATCH 3/8] cputime: introduce account_idle_and_iowait

From: Hidetoshi Seto
Date: Thu Jun 26 2014 - 05:11:15 EST


The current account_idle_time() cannot process mixed cputime which
contain both of idle cputime and iowait cputime.

So introduce new account_idle_and_iowait() to do paranoid work.
Following patches will add users of this new function.

Not-Tested-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
kernel/sched/cputime.c | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index a028604..283e011 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -240,14 +240,36 @@ void account_steal_time(cputime_t cputime)
}

/*
+ * Account for idle and iowait time in a dulation.
+ * @idle_enter: time stamp at idle entry
+ * @iowait_exit: time stamp when nr_iowait dropped to 0
+ * @idle_exit: time stamp at idle exit
+ */
+void account_idle_and_iowait(cputime_t idle_enter, cputime_t iowait_exit, cputime_t idle_exit)
+{
+ u64 *cpustat = kcpustat_this_cpu->cpustat;
+ struct rq *rq = this_rq();
+
+ if (rq->nr_iowait > 0 || iowait_exit > idle_exit) {
+ cpustat[CPUTIME_IOWAIT] += (__force u64) idle_exit - idle_enter;
+ } else if (iowait_exit > idle_enter) {
+ cpustat[CPUTIME_IOWAIT] += (__force u64) iowait_exit - idle_enter;
+ cpustat[CPUTIME_IDLE] += (__force u64) idle_exit - iowait_exit;
+ } else {
+ cpustat[CPUTIME_IDLE] += (__force u64) idle_exit - idle_enter;
+ }
+}
+
+/*
* Account for idle time.
- * @cputime: the cpu time spent in idle wait
+ * @cputime: the cpu time spent in idle wait (sometimes include iowait time)
*/
void account_idle_time(cputime_t cputime)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;
struct rq *rq = this_rq();

+ /* FIXME */
if (rq->nr_iowait > 0)
cpustat[CPUTIME_IOWAIT] += (__force u64) cputime;
else
--
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/