Skip to content

Commit

Permalink
vtime: Make vtime_account_system() irqsafe
Browse files Browse the repository at this point in the history
vtime_account_system() currently has only one caller with
vtime_account() which is irq safe.

Now we are going to call it from other places like kvm where
irqs are not always disabled by the time we account the cputime.

So let's make it irqsafe. The arch implementation part is now
prefixed with "__".

vtime_account_idle() arch implementation is prefixed accordingly
to stay consistent.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
  • Loading branch information
Frederic Weisbecker committed Oct 29, 2012
1 parent dcbf832 commit 1111333
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
8 changes: 4 additions & 4 deletions arch/ia64/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void vtime_task_switch(struct task_struct *prev)
struct thread_info *ni = task_thread_info(current);

if (idle_task(smp_processor_id()) != prev)
vtime_account_system(prev);
__vtime_account_system(prev);
else
vtime_account_idle(prev);
__vtime_account_idle(prev);

vtime_account_user(prev);

Expand All @@ -135,14 +135,14 @@ static cputime_t vtime_delta(struct task_struct *tsk)
return delta_stime;
}

void vtime_account_system(struct task_struct *tsk)
void __vtime_account_system(struct task_struct *tsk)
{
cputime_t delta = vtime_delta(tsk);

account_system_time(tsk, 0, delta, delta);
}

void vtime_account_idle(struct task_struct *tsk)
void __vtime_account_idle(struct task_struct *tsk)
{
account_idle_time(vtime_delta(tsk));
}
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static u64 vtime_delta(struct task_struct *tsk,
return delta;
}

void vtime_account_system(struct task_struct *tsk)
void __vtime_account_system(struct task_struct *tsk)
{
u64 delta, sys_scaled, stolen;

Expand All @@ -346,7 +346,7 @@ void vtime_account_system(struct task_struct *tsk)
account_steal_time(stolen);
}

void vtime_account_idle(struct task_struct *tsk)
void __vtime_account_idle(struct task_struct *tsk)
{
u64 delta, sys_scaled, stolen;

Expand Down
4 changes: 4 additions & 0 deletions arch/s390/kernel/vtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ void vtime_account(struct task_struct *tsk)
}
EXPORT_SYMBOL_GPL(vtime_account);

void __vtime_account_system(struct task_struct *tsk)
__attribute__((alias("vtime_account")));
EXPORT_SYMBOL_GPL(__vtime_account_system);

void __kprobes vtime_stop_cpu(void)
{
struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
Expand Down
4 changes: 3 additions & 1 deletion include/linux/vtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ struct task_struct;

#ifdef CONFIG_VIRT_CPU_ACCOUNTING
extern void vtime_task_switch(struct task_struct *prev);
extern void __vtime_account_system(struct task_struct *tsk);
extern void vtime_account_system(struct task_struct *tsk);
extern void vtime_account_idle(struct task_struct *tsk);
extern void __vtime_account_idle(struct task_struct *tsk);
#else
static inline void vtime_task_switch(struct task_struct *prev) { }
static inline void vtime_account_system(struct task_struct *tsk) { }
#endif

#if !defined(CONFIG_VIRT_CPU_ACCOUNTING) && !defined(CONFIG_IRQ_TIME_ACCOUNTING)
Expand Down
16 changes: 13 additions & 3 deletions kernel/sched/cputime.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,20 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
*st = cputime.stime;
}

void vtime_account_system(struct task_struct *tsk)
{
unsigned long flags;

local_irq_save(flags);
__vtime_account_system(tsk);
local_irq_restore(flags);
}
EXPORT_SYMBOL_GPL(vtime_account_system);

/*
* Archs that account the whole time spent in the idle task
* (outside irq) as idle time can rely on this and just implement
* vtime_account_system() and vtime_account_idle(). Archs that
* __vtime_account_system() and __vtime_account_idle(). Archs that
* have other meaning of the idle time (s390 only includes the
* time spent by the CPU when it's in low power mode) must override
* vtime_account().
Expand All @@ -449,9 +459,9 @@ void vtime_account(struct task_struct *tsk)
local_irq_save(flags);

if (in_interrupt() || !is_idle_task(tsk))
vtime_account_system(tsk);
__vtime_account_system(tsk);
else
vtime_account_idle(tsk);
__vtime_account_idle(tsk);

local_irq_restore(flags);
}
Expand Down

0 comments on commit 1111333

Please sign in to comment.