public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
To: linux-kernel@vger.kernel.org
Cc: Fernando Luis Vazquez Cao <fernando_b1@lab.ntt.co.jp>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Preeti U Murthy <preeti@linux.vnet.ibm.com>,
	Denys Vlasenko <vda.linux@googlemail.com>
Subject: [PATCH 7/8] cputime: generic iowait accounting for VIRT_CPU_ACCOUNTING
Date: Thu, 26 Jun 2014 18:16:04 +0900	[thread overview]
Message-ID: <53ABE4D4.1020308@jp.fujitsu.com> (raw)
In-Reply-To: <53ABE28F.6010402@jp.fujitsu.com>

Get iowait's timestamp for accounting w/ VIRT_CPU_ACCOUNTING_GEN.
(currently arm is only user of this?)

At last of this series of changes, introduce common function
vtime_iowait_exit to replace all arch_record_iowait_exit.

Not-tested-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
 arch/ia64/include/asm/cputime.h    |    2 --
 arch/ia64/kernel/time.c            |    2 +-
 arch/powerpc/include/asm/cputime.h |    3 ---
 arch/powerpc/kernel/time.c         |    2 +-
 arch/s390/include/asm/cputime.h    |    2 --
 arch/s390/kernel/vtime.c           |    2 +-
 include/linux/vtime.h              |    3 +++
 kernel/sched/core.c                |    4 +---
 kernel/sched/cputime.c             |   25 +++++++++++++++++++++++--
 9 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/arch/ia64/include/asm/cputime.h b/arch/ia64/include/asm/cputime.h
index 6089cbd..e2d3f5b 100644
--- a/arch/ia64/include/asm/cputime.h
+++ b/arch/ia64/include/asm/cputime.h
@@ -24,8 +24,6 @@
 # include <asm/processor.h>
 # include <asm-generic/cputime_nsecs.h>
 extern void arch_vtime_task_switch(struct task_struct *tsk);
-extern void ia64_record_iowait_exit(int cpu);
-# define arch_record_iowait_exit(cpu) ia64_record_iowait_exit(cpu)
 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
 
 #endif /* __IA64_CPUTIME_H */
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 37c907d..4b34346 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -143,7 +143,7 @@ EXPORT_SYMBOL_GPL(vtime_account_system);
  */
 DEFINE_PER_CPU(u64, ia64_iowait_exit);
 
-void ia64_record_iowait_exit(int cpu)
+void vtime_iowait_exit(int cpu)
 {
 	/* FIXME: ITC might not synchronized between cpus/sockets */
         per_cpu(ia64_iowait_exit, cpu) = ia64_get_itc();
diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index f33a801..607559a 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -230,9 +230,6 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)
 
 static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
 
-void ppc_record_iowait_exit(int cpu);
-#define arch_record_iowait_exit(cpu) ppc_record_iowait_exit(cpu)
-
 #endif /* __KERNEL__ */
 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
 #endif /* __POWERPC_CPUTIME_H */
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 879d97a..7afddc1 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -355,7 +355,7 @@ EXPORT_SYMBOL_GPL(vtime_account_system);
 
 DEFINE_PER_CPU(u64, vtime_iowait_exit);
 
-void ppc_record_iowait_exit(int cpu)
+void vtime_iowait_exit(int cpu)
 {
 	per_cpu(vtime_iowait_exit, cpu) = mftb();
 }
diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h
index f4f882d..e136328 100644
--- a/arch/s390/include/asm/cputime.h
+++ b/arch/s390/include/asm/cputime.h
@@ -180,10 +180,8 @@ struct s390_idle_data {
 DECLARE_PER_CPU(struct s390_idle_data, s390_idle);
 
 void s390_get_idle_and_iowait(int cpu, cputime64_t reti, cputime64_t retw);
-void s390_record_iowait_exit(int cpu);
 
 #define arch_idle_and_iowait(cpu, i, w) s390_get_idle_and_iowait(cpu, i, w)
-#define arch_record_iowait_exit(cpu) s390_save_iowait_exit(cpu)
 
 static inline int s390_nohz_delay(int cpu)
 {
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index f945cbd..123fa74 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -214,7 +214,7 @@ void s390_get_idle_and_iowait(int cpu, cputime64_t *reti, cputime64_t *retw)
 	}
 }
 
-void s390_record_iowait_exit(int cpu)
+void vtime_iowait_exit(int cpu)
 {
 	struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
 
diff --git a/include/linux/vtime.h b/include/linux/vtime.h
index c5165fd..7f4632a 100644
--- a/include/linux/vtime.h
+++ b/include/linux/vtime.h
@@ -49,6 +49,7 @@ static inline void vtime_task_switch(struct task_struct *prev)
 }
 #endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
 
+extern void vtime_iowait_exit(int cpu);
 extern void vtime_account_system(struct task_struct *tsk);
 extern void vtime_account_idle(struct task_struct *tsk);
 extern void vtime_account_user(struct task_struct *tsk);
@@ -66,8 +67,10 @@ static inline void vtime_account_irq_enter(struct task_struct *tsk)
 
 #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
 
+static inline void vtime_iowait_exit(int cpu) { }
 static inline void vtime_task_switch(struct task_struct *prev) { }
 static inline void vtime_account_system(struct task_struct *tsk) { }
+static inline void vtime_account_idle(struct task_struct *tsk) { }
 static inline void vtime_account_user(struct task_struct *tsk) { }
 static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
 #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 52abf79..f8eec61 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4345,9 +4345,7 @@ static inline void iowait_stop(struct rq *rq)
 	raw_spin_lock(&rq->iowait_lock);
 	rq->nr_iowait--;
 	if (!rq->nr_iowait && rq != this_rq()) {
-#ifdef arch_record_iowait_exit
-		arch_record_iowait_exit(rq->cpu);
-#endif
+		vtime_iowait_exit(rq->cpu);
 		rq->last_iowait = ktime_get();
 	}
 	raw_spin_unlock(&rq->iowait_lock);
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 283e011..866a3ff 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -741,11 +741,32 @@ void vtime_guest_exit(struct task_struct *tsk)
 }
 EXPORT_SYMBOL_GPL(vtime_guest_exit);
 
+DEFINE_PER_CPU(unsigned long long, vtime_exit_iowait);
+
+void vtime_iowait_exit(int cpu)
+{
+	/* FIXME: don't compare local clock on different cpus */
+	per_cpu(vtime_exit_iowait, cpu) = local_clock();
+}
+
 void vtime_account_idle(struct task_struct *tsk)
 {
-	cputime_t delta_cpu = get_vtime_delta(tsk);
+	unsigned long long now, delta;
+	cputime_t delta_cpu, idle_cpu;
+
+	now = local_clock();
+	if (now < tsk->vtime_snap)
+		return;
+
+	delta = now - tsk->vtime_snap;
+
+	WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_SLEEPING);
+	tsk->vtime_snap += delta;
+
+	delta_cpu = nsecs_to_cputime(delta);
+	idle_cpu = nsecs_to_cputime(now - per_cpu_var(vtime_exit_iowait));
 
-	account_idle_time(delta_cpu);
+	account_idle_and_iowait(0, delta_cpu - idle_cpu, delta_cpu);
 }
 
 void arch_vtime_task_switch(struct task_struct *prev)
-- 
1.7.1



  parent reply	other threads:[~2014-06-26  9:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26  9:06 [RFC PATCH 0/8] rework iowait accounting Hidetoshi Seto
2014-06-26  9:08 ` [PATCH 1/8] cputime, sched: record last_iowait Hidetoshi Seto
2014-06-26  9:09 ` [PATCH 2/8] cputime, nohz: handle last_iowait for nohz Hidetoshi Seto
2014-06-26  9:10 ` [PATCH 3/8] cputime: introduce account_idle_and_iowait Hidetoshi Seto
2014-06-26  9:12 ` [PATCH 4/8] cputime, s390: introduce s390_get_idle_and_iowait Hidetoshi Seto
2014-06-26  9:13 ` [PATCH 5/8] cputime, ia64: update iowait accounting Hidetoshi Seto
2014-06-26  9:14 ` [PATCH 6/8] cputime, ppc: " Hidetoshi Seto
2014-06-26  9:16 ` Hidetoshi Seto [this message]
2014-06-26  9:17 ` [PATCH 8/8] cputime: iowait aware idle tick accounting Hidetoshi Seto
2014-07-07  9:30 ` [RFC PATCH 0/8] rework iowait accounting Peter Zijlstra

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=53ABE4D4.1020308@jp.fujitsu.com \
    --to=seto.hidetoshi@jp.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@linux.intel.com \
    --cc=fernando_b1@lab.ntt.co.jp \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=peterz@infradead.org \
    --cc=preeti@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=vda.linux@googlemail.com \
    /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