All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Borislav Petkov <bp@alien8.de>,
	Li Zhong <zhong@linux.vnet.ibm.com>,
	Mike Galbraith <efault@gmx.de>
Subject: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
Date: Mon, 20 May 2013 18:01:50 +0200	[thread overview]
Message-ID: <1369065716-22801-3-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1369065716-22801-1-git-send-email-fweisbec@gmail.com>

While computing the cputime delta of dynticks CPUs,
we are mixing up clocks of differents natures:

* local_clock() which takes care of unstable clock
sources and fix these if needed.

* sched_clock() which is the weaker version of
local_clock(). It doesn't compute any fixup in case
of unstable source.

If the clock source is stable, those two clocks are the
same and we can safely compute the difference against
two random points.

Otherwise it results in random deltas as sched_clock()
can randomly drift away, back or forward, from local_clock().

As a consequence, some strange behaviour with unstable tsc
has been observed such as non progressing constant zero cputime.
(The 'top' command showing no load).

Fix this by only using local_clock(), or its irq safe/remote
equivalent, in vtime code.

Reported-by: Mike Galbraith <efault@gmx.de>
Suggested-by: Mike Galbraith <efault@gmx.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Li Zhong <zhong@linux.vnet.ibm.com>
Cc: Mike Galbraith <efault@gmx.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/linux/vtime.h  |    4 ++--
 kernel/sched/core.c    |    2 +-
 kernel/sched/cputime.c |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/vtime.h b/include/linux/vtime.h
index 71a5782..b1dd2db 100644
--- a/include/linux/vtime.h
+++ b/include/linux/vtime.h
@@ -34,7 +34,7 @@ static inline void vtime_user_exit(struct task_struct *tsk)
 }
 extern void vtime_guest_enter(struct task_struct *tsk);
 extern void vtime_guest_exit(struct task_struct *tsk);
-extern void vtime_init_idle(struct task_struct *tsk);
+extern void vtime_init_idle(struct task_struct *tsk, int cpu);
 #else
 static inline void vtime_account_irq_exit(struct task_struct *tsk)
 {
@@ -45,7 +45,7 @@ static inline void vtime_user_enter(struct task_struct *tsk) { }
 static inline void vtime_user_exit(struct task_struct *tsk) { }
 static inline void vtime_guest_enter(struct task_struct *tsk) { }
 static inline void vtime_guest_exit(struct task_struct *tsk) { }
-static inline void vtime_init_idle(struct task_struct *tsk) { }
+static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
 #endif
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 58453b8..e1a27f9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4745,7 +4745,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
 	 */
 	idle->sched_class = &idle_sched_class;
 	ftrace_graph_init_idle_task(idle, cpu);
-	vtime_init_idle(idle);
+	vtime_init_idle(idle, cpu);
 #if defined(CONFIG_SMP)
 	sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu);
 #endif
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index cc2dc3ee..b5ccba2 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -747,17 +747,17 @@ void arch_vtime_task_switch(struct task_struct *prev)
 
 	write_seqlock(&current->vtime_seqlock);
 	current->vtime_snap_whence = VTIME_SYS;
-	current->vtime_snap = sched_clock();
+	current->vtime_snap = sched_clock_cpu(smp_processor_id());
 	write_sequnlock(&current->vtime_seqlock);
 }
 
-void vtime_init_idle(struct task_struct *t)
+void vtime_init_idle(struct task_struct *t, int cpu)
 {
 	unsigned long flags;
 
 	write_seqlock_irqsave(&t->vtime_seqlock, flags);
 	t->vtime_snap_whence = VTIME_SYS;
-	t->vtime_snap = sched_clock();
+	t->vtime_snap = sched_clock_cpu(cpu);
 	write_sequnlock_irqrestore(&t->vtime_seqlock, flags);
 }
 
-- 
1.7.5.4


  parent reply	other threads:[~2013-05-20 16:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 16:01 [PATCH 0/8] nohz: Random fixes Frederic Weisbecker
2013-05-20 16:01 ` [PATCH 1/8] nohz: Warn if the machine can not perform nohz_full Frederic Weisbecker
2013-05-20 16:01 ` Frederic Weisbecker [this message]
2013-06-03  9:47   ` [PATCH 2/8] vtime: Use consistent clocks among nohz accounting Stefan Seyfried
2013-06-03 13:48     ` Steven Rostedt
2013-06-03 19:48     ` Frederic Weisbecker
2013-06-03 19:51       ` Stefan Seyfried
2013-06-03 20:12         ` Frederic Weisbecker
2013-05-20 16:01 ` [PATCH 3/8] watchdog: Boot-disable by default on full dynticks Frederic Weisbecker
2013-05-20 17:52   ` Don Zickus
2013-05-20 18:14     ` Frederic Weisbecker
2013-05-20 16:01 ` [PATCH 4/8] kvm: Move guest entry/exit APIs to context_tracking Frederic Weisbecker
2013-05-20 16:01 ` [PATCH 5/8] nohz: Fix notifier return val that enforce timekeeping Frederic Weisbecker
2013-05-20 16:01 ` [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks Frederic Weisbecker
2013-05-21  5:34   ` anish singh
2013-05-21  7:49     ` Srivatsa S. Bhat
2013-05-21  8:58       ` anish singh
2013-05-21  9:07         ` Srivatsa S. Bhat
2013-05-22 15:18         ` Frederic Weisbecker
2013-05-21  6:59   ` Srivatsa S. Bhat
2013-06-05 16:33     ` Frederic Weisbecker
2013-05-20 16:01 ` [RFC PATCH 7/8] watchdog: Rename confusing state variable Frederic Weisbecker
2013-05-20 17:53   ` Don Zickus
2013-05-20 16:01 ` [RFC PATCH 8/8] watchdog: Fix internal state with boot user disabled watchdog Frederic Weisbecker
2013-05-20 17:54   ` Don Zickus

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=1369065716-22801-3-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=bp@alien8.de \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=zhong@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.