cputime: Safely read cputime of full dynticks CPUs
While remotely reading the cputime of a task running in a full dynticks CPU, the values stored in utime/stime fields of struct task_struct may be stale. Its values may be those of the last kernel <-> user transition time snapshot and we need to add the tickless time spent since this snapshot. To fix this, flush the cputime of the dynticks CPUs on kernel <-> user transition and record the time / context where we did this. Then on top of this snapshot and the current time, perform the fixup on the reader side from task_times() accessors. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> [fixed kvm module related build errors] Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
This commit is contained in:
@@ -8,35 +8,44 @@ extern void vtime_task_switch(struct task_struct *prev);
|
||||
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);
|
||||
extern void vtime_account(struct task_struct *tsk);
|
||||
extern void vtime_account_irq_enter(struct task_struct *tsk);
|
||||
|
||||
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
|
||||
extern bool vtime_accounting_enabled(void);
|
||||
#else
|
||||
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
|
||||
static inline bool vtime_accounting_enabled(void) { return true; }
|
||||
#endif
|
||||
|
||||
#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
|
||||
|
||||
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_user(struct task_struct *tsk) { }
|
||||
static inline void vtime_account(struct task_struct *tsk) { }
|
||||
static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
|
||||
static inline bool vtime_accounting_enabled(void) { return false; }
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
|
||||
static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
|
||||
static inline void vtime_user_enter(struct task_struct *tsk)
|
||||
{
|
||||
vtime_account_system(tsk);
|
||||
}
|
||||
extern void arch_vtime_task_switch(struct task_struct *tsk);
|
||||
extern void vtime_account_irq_exit(struct task_struct *tsk);
|
||||
extern bool vtime_accounting_enabled(void);
|
||||
extern void vtime_user_enter(struct task_struct *tsk);
|
||||
static inline void vtime_user_exit(struct task_struct *tsk)
|
||||
{
|
||||
vtime_account_user(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);
|
||||
#else
|
||||
static inline void vtime_account_irq_exit(struct task_struct *tsk)
|
||||
{
|
||||
/* On hard|softirq exit we always account to hard|softirq cputime */
|
||||
vtime_account_system(tsk);
|
||||
}
|
||||
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) { }
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
|
||||
@@ -45,25 +54,15 @@ extern void irqtime_account_irq(struct task_struct *tsk);
|
||||
static inline void irqtime_account_irq(struct task_struct *tsk) { }
|
||||
#endif
|
||||
|
||||
static inline void vtime_account_irq_enter(struct task_struct *tsk)
|
||||
static inline void account_irq_enter_time(struct task_struct *tsk)
|
||||
{
|
||||
/*
|
||||
* Hardirq can interrupt idle task anytime. So we need vtime_account()
|
||||
* that performs the idle check in CONFIG_VIRT_CPU_ACCOUNTING.
|
||||
* Softirq can also interrupt idle task directly if it calls
|
||||
* local_bh_enable(). Such case probably don't exist but we never know.
|
||||
* Ksoftirqd is not concerned because idle time is flushed on context
|
||||
* switch. Softirqs in the end of hardirqs are also not a problem because
|
||||
* the idle time is flushed on hardirq time already.
|
||||
*/
|
||||
vtime_account(tsk);
|
||||
vtime_account_irq_enter(tsk);
|
||||
irqtime_account_irq(tsk);
|
||||
}
|
||||
|
||||
static inline void vtime_account_irq_exit(struct task_struct *tsk)
|
||||
static inline void account_irq_exit_time(struct task_struct *tsk)
|
||||
{
|
||||
/* On hard|softirq exit we always account to hard|softirq cputime */
|
||||
vtime_account_system(tsk);
|
||||
vtime_account_irq_exit(tsk);
|
||||
irqtime_account_irq(tsk);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user