Skip to content

Commit 45eacc6

Browse files
fweisbecingomolnar
authored andcommitted
vtime: Use consistent clocks among nohz accounting
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> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 67dd331 commit 45eacc6

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎include/linux/vtime.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static inline void vtime_user_exit(struct task_struct *tsk)
3434
}
3535
extern void vtime_guest_enter(struct task_struct *tsk);
3636
extern void vtime_guest_exit(struct task_struct *tsk);
37-
extern void vtime_init_idle(struct task_struct *tsk);
37+
extern void vtime_init_idle(struct task_struct *tsk, int cpu);
3838
#else
3939
static inline void vtime_account_irq_exit(struct task_struct *tsk)
4040
{
@@ -45,7 +45,7 @@ static inline void vtime_user_enter(struct task_struct *tsk) { }
4545
static inline void vtime_user_exit(struct task_struct *tsk) { }
4646
static inline void vtime_guest_enter(struct task_struct *tsk) { }
4747
static inline void vtime_guest_exit(struct task_struct *tsk) { }
48-
static inline void vtime_init_idle(struct task_struct *tsk) { }
48+
static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
4949
#endif
5050

5151
#ifdef CONFIG_IRQ_TIME_ACCOUNTING

‎kernel/sched/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4745,7 +4745,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
47454745
*/
47464746
idle->sched_class = &idle_sched_class;
47474747
ftrace_graph_init_idle_task(idle, cpu);
4748-
vtime_init_idle(idle);
4748+
vtime_init_idle(idle, cpu);
47494749
#if defined(CONFIG_SMP)
47504750
sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu);
47514751
#endif

‎kernel/sched/cputime.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,17 +747,17 @@ void arch_vtime_task_switch(struct task_struct *prev)
747747

748748
write_seqlock(&current->vtime_seqlock);
749749
current->vtime_snap_whence = VTIME_SYS;
750-
current->vtime_snap = sched_clock();
750+
current->vtime_snap = sched_clock_cpu(smp_processor_id());
751751
write_sequnlock(&current->vtime_seqlock);
752752
}
753753

754-
void vtime_init_idle(struct task_struct *t)
754+
void vtime_init_idle(struct task_struct *t, int cpu)
755755
{
756756
unsigned long flags;
757757

758758
write_seqlock_irqsave(&t->vtime_seqlock, flags);
759759
t->vtime_snap_whence = VTIME_SYS;
760-
t->vtime_snap = sched_clock();
760+
t->vtime_snap = sched_clock_cpu(cpu);
761761
write_sequnlock_irqrestore(&t->vtime_seqlock, flags);
762762
}
763763

0 commit comments

Comments
 (0)