cputime: Even more cleanups
cover cputime: Even more cleanups
Hi,
While working on full dynticks, I realized some more cleanups needed to be done. Here is it. If no comment arise, I'll send a pull request to Ingo in a week.
Thanks.
Frederic Weisbecker (4):
vtime: Remove the underscore prefix invasion
vtime: Explicitly account pending user time on process tick
vtime: Consolidate a bit the ctx switch code
vtime: No need to disable irqs on vtime_account()
arch/ia64/include/asm/cputime.h | 2 ++ arch/ia64/kernel/time.c | 24 ++++-------------------- arch/powerpc/include/asm/cputime.h | 2 ++ arch/powerpc/kernel/time.c | 22 ++++++++-------------- arch/s390/include/asm/cputime.h | 1 + arch/s390/kernel/vtime.c | 11 ++++++++--- include/linux/kernel_stat.h | 8 ++++++++ include/linux/kvm_host.h | 4 ++-- include/linux/vtime.h | 9 +++++---- kernel/sched/cputime.c | 31 +++++++++++++++++++------------ 10 files changed, 59 insertions(+), 55 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/4 vtime: Remove the underscore prefix invasion
Prepending irq-unsafe vtime APIs with underscores was actually a bad idea as the result is a big mess in the API namespace that is even waiting to be further extended. Also these helpers are always called from irq safe callers except kvm. Just provide a vtime_account_system_irqsafe() for this specific case so that we can remove the underscore prefix on other vtime functions.
--- arch/ia64/kernel/time.c | 8 ++++---- arch/powerpc/kernel/time.c | 4 ++-- arch/s390/kernel/vtime.c | 4 ++-- include/linux/kvm_host.h | 4 ++-- include/linux/vtime.h | 8 ++++---- kernel/sched/cputime.c | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-)
arch/ia64/kernel/time.c +4 -4
@@ -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);
@@ -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)); }
arch/powerpc/kernel/time.c +2 -2
@@ -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;
@@ -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;
arch/s390/kernel/vtime.c +2 -2
@@ -140,9 +140,9 @@ void vtime_account(struct task_struct *tsk) }EXPORT_SYMBOL_GPL (vtime_account); -void __vtime_account_system (struct task_struct *tsk) +void vtime_account_system (struct task_struct *tsk) __attribute__((alias ("vtime_account" ))); -EXPORT_SYMBOL_GPL (__vtime_account_system); +EXPORT_SYMBOL_GPL (vtime_account_system);void __kprobes vtime_stop_cpu (void ) {
include/linux/kvm_host.h +2 -2
@@ -741,7 +741,7 @@ static inline void kvm_guest_enter(void)* This is running in ioctl context so we can avoid * the call to vtime_account() with its unnecessary idle check. */ -vtime_account_system (current); +vtime_account_system_irqsafe (current); current->flags |=PF_VCPU ;/* KVM does not hold any references to rcu protected data when it * switches CPU into a guest mode. In fact switching to a guest mode
@@ -759,7 +759,7 @@ static inline void kvm_guest_exit(void)* This is running in ioctl context so we can avoid * the call to vtime_account() with its unnecessary idle check. */ -vtime_account_system (current); +vtime_account_system_irqsafe (current); current->flags &= ~PF_VCPU ; }
include/linux/vtime.h +4 -4
@@ -5,14 +5,14 @@ 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_system_irqsafe (struct task_struct *tsk); +extern void vtime_account_idle (struct task_struct *tsk);extern void vtime_account (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) { }static inline void vtime_account_system (struct task_struct *tsk) { } +static inline void vtime_account_system_irqsafe (struct task_struct *tsk) { }static inline void vtime_account (struct task_struct *tsk) { }#endif
@@ -40,7 +40,7 @@ static inline void vtime_account_irq_enter(struct task_struct *tsk)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); +vtime_account_system (tsk);irqtime_account_irq (tsk); }
kernel/sched/cputime.c +6 -6
@@ -433,20 +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) +void vtime_account_system_irqsafe (struct task_struct *tsk) {unsigned long flags;local_irq_save (flags); -__vtime_account_system (tsk); +vtime_account_system (tsk);local_irq_restore (flags); } -EXPORT_SYMBOL_GPL (vtime_account_system); +EXPORT_SYMBOL_GPL (vtime_account_system_irqsafe);/* * 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().
@@ -459,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); }
Signature · 1 line
1.7.5.4
Steven Rostedt
reviewerRe: [PATCH 1/4] vtime: Remove the underscore prefix invasion
Quoted 10 lines · Frederic Weisbecker
Prepending irq-unsafe vtime APIs with underscores was actually a bad idea as the result is a big mess in the API namespace that is even waiting to be further extended. Also these helpers are always called from irq safe callers except kvm. Just provide a
vtime_account_system_irqsafe()for this specific case so that we can remove the underscore prefix on other vtime functions.
arch/ia64/kernel/time.c static cputime_t vtime_delta(struct task_struct *tsk) · line 140
Quoted 4 lines
arch/ia64/kernel/time.c +1
-1-void __vtime_account_system (struct task_struct *tsk) +void vtime_account_system (struct task_struct *tsk) {cputime_t delta =vtime_delta (tsk);
Should we add a WARN_ON(!irqs_disabled()) check here?
-- Steve
Quoted 9 lines
arch/ia64/kernel/time.c +1
-1account_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)); }
Re: [PATCH 1/4] vtime: Remove the underscore prefix invasion
2012/11/14 Steven Rostedt <[email protected]>:
Quoted 11 lines · Frederic Weisbecker
Quoted 8 lines
Prepending irq-unsafe vtime APIs with underscores was actually a bad idea as the result is a big mess in the API namespace that is even waiting to be further extended. Also these helpers are always called from irq safe callers except kvm. Just provide a
vtime_account_system_irqsafe()for this specific case so that we can remove the underscore prefix on other vtime functions.
Quoted 6 lines
arch/ia64/kernel/time.c static cputime_t vtime_delta(struct task_struct *tsk) · line 140
Quoted 4 lines
arch/ia64/kernel/time.c +1
-1-void __vtime_account_system (struct task_struct *tsk) +void vtime_account_system (struct task_struct *tsk) {cputime_t delta =vtime_delta (tsk);Should we add a WARN_ON(!irqs_disabled()) check here?
Why not, I'll add one in vtime_delta().
Steven Rostedt
reviewerRe: [PATCH 1/4] vtime: Remove the underscore prefix invasion
Quoted 12 lines · Frederic Weisbecker
2012/11/14 Steven Rostedt <[email protected]>:
Quoted 11 lines · Frederic Weisbecker
Quoted 8 lines
Prepending irq-unsafe vtime APIs with underscores was actually a bad idea as the result is a big mess in the API namespace that is even waiting to be further extended. Also these helpers are always called from irq safe callers except kvm. Just provide a
vtime_account_system_irqsafe()for this specific case so that we can remove the underscore prefix on other vtime functions.
Quoted 8 lines
Quoted 6 lines
arch/ia64/kernel/time.c static cputime_t vtime_delta(struct task_struct *tsk) · line 140
Quoted 4 lines
arch/ia64/kernel/time.c +1
-1-void __vtime_account_system (struct task_struct *tsk) +void vtime_account_system (struct task_struct *tsk) {cputime_t delta =vtime_delta (tsk);Should we add a WARN_ON(!irqs_disabled()) check here?
Why not, I'll add one in
vtime_delta().
Probably make it a WARN_ON_ONCE() no need to spam the console.
-- Steve
PATCH 2/4 vtime: Explicitly account pending user time on process tick
In reply to Frederic WeisbeckerAll vtime implementations just flush the user time on process tick. Consolidate that in generic code by calling a user time accounting helper. This avoids an indirect call in ia64 and prepare to also consolidate vtime context switch code.
--- arch/ia64/kernel/time.c | 11 +---------- arch/powerpc/kernel/time.c | 14 +++++++------- arch/s390/kernel/vtime.c | 7 ++++++- include/linux/kernel_stat.h | 8 ++++++++ include/linux/vtime.h | 1 + 5 files changed, 23 insertions(+), 18 deletions(-)
arch/ia64/kernel/time.c +1 -10
@@ -83,7 +83,7 @@ static struct clocksource *itc_clocksource;extern cputime_t cycle_to_cputime (u64 cyc); -static void vtime_account_user (struct task_struct *tsk) +void vtime_account_user (struct task_struct *tsk) {cputime_t delta_utime;struct thread_info *ti =task_thread_info (tsk);
@@ -147,15 +147,6 @@ void vtime_account_idle(struct task_struct *tsk)account_idle_time (vtime_delta (tsk)); } -/* -* Called from the timer interrupt handler to charge accumulated user time -* to the current process. Must be called with interrupts disabled. -*/ -void account_process_tick (struct task_struct *p,int user_tick) -{ -vtime_account_user (p); -} -#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ static irqreturn_t
arch/powerpc/kernel/time.c +7 -7
@@ -355,15 +355,15 @@ void vtime_account_idle(struct task_struct *tsk) }/* -* Transfer the user and system times accumulated in the paca -* by the exception entry and exit code to the generic process -* user and system time records. +* Transfer the user time accumulated in the paca +* by the exception entry and exit code to the generic +* process user time records. * Must be called with interrupts disabled. -* Assumes that vtime_account() has been called recently -* (i.e. since the last entry from usermode) so that +* Assumes that vtime_account_system/idle() has been called +* recently (i.e. since the last entry from usermode) so that * get_paca()->user_time_scaled is up to date. */ -void account_process_tick (struct task_struct *tsk,int user_tick) +void vtime_account_user (struct task_struct *tsk) {cputime_t utime, utimescaled;
@@ -378,7 +378,7 @@ void account_process_tick(struct task_struct *tsk, int user_tick)void vtime_task_switch (struct task_struct *prev) {vtime_account (prev); -account_process_tick (prev,0 ); +vtime_account_user (prev); }#else /* ! CONFIG_VIRT_CPU_ACCOUNTING */
arch/s390/kernel/vtime.c +6 -1
@@ -112,7 +112,12 @@ void vtime_task_switch(struct task_struct *prev) S390_lowcore.system_timer = ti->system_timer; } -void account_process_tick (struct task_struct *tsk,int user_tick) +/* +* In s390, accounting pending user time also implies +* accounting system time in order to correctly compute +* the stolen time accounting. +*/ +void vtime_account_user (struct task_struct *tsk) {if (do_account_vtime (tsk,HARDIRQ_OFFSET ))virt_timer_expire ();
include/linux/kernel_stat.h +8 -0
@@ -127,7 +127,15 @@ extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t)extern void account_steal_time (cputime_t );extern void account_idle_time (cputime_t ); +#ifdef CONFIG_VIRT_CPU_ACCOUNTING +static inline void account_process_tick (struct task_struct *tsk,int user) +{ +vtime_account_user (tsk); +} +#else extern void account_process_tick (struct task_struct *,int user); +#endif +extern void account_steal_ticks (unsigned long ticks);extern void account_idle_ticks (unsigned long ticks);
include/linux/vtime.h +1 -0
@@ -8,6 +8,7 @@ extern void vtime_task_switch(struct task_struct *prev);extern void vtime_account_system (struct task_struct *tsk);extern void vtime_account_system_irqsafe (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);#else static inline void vtime_task_switch (struct task_struct *prev) { }
Signature · 1 line
1.7.5.4
PATCH 3/4 vtime: Consolidate a bit the ctx switch code
In reply to Frederic WeisbeckerOn ia64 and powerpc, vtime context switch only consists in flushing system and user pending time, plus a few arch housekeeping.
Consolidate that into a generic implementation. s390 is
a special case because pending user and system time accounting there is hard to dissociate. So it's keeping its own implementation.
--- arch/ia64/include/asm/cputime.h | 2 ++ arch/ia64/kernel/time.c | 9 +-------- arch/powerpc/include/asm/cputime.h | 2 ++ arch/powerpc/kernel/time.c | 6 ------ arch/s390/include/asm/cputime.h | 1 + kernel/sched/cputime.c | 13 +++++++++++++ 6 files changed, 19 insertions(+), 14 deletions(-)
arch/ia64/include/asm/cputime.h +2 -0
@@ -103,5 +103,7 @@ static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)#define cputime64_to_clock_t (__ct) \ cputime_to_clock_t((__force cputime_t)__ct) +extern void arch_vtime_task_switch (struct task_struct *tsk); +#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ #endif /* __IA64_CPUTIME_H */
arch/ia64/kernel/time.c +1 -8
@@ -100,18 +100,11 @@ void vtime_account_user(struct task_struct *tsk)* accumulated times to the current process, and to prepare accounting on * the next process. */ -void vtime_task_switch (struct task_struct *prev) +void arch_vtime_task_switch (struct task_struct *prev) {struct thread_info *pi =task_thread_info (prev);struct thread_info *ni =task_thread_info (current); -if (idle_task (smp_processor_id ()) != prev) -vtime_account_system (prev); -else -vtime_account_idle (prev); - -vtime_account_user (prev); - pi->ac_stamp = ni->ac_stamp; ni->ac_stime = ni->ac_utime =0 ; }
arch/powerpc/include/asm/cputime.h +2 -0
@@ -228,6 +228,8 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)#define cputime64_to_clock_t (ct) cputime_to_clock_t((cputime_t)(ct)) +static inline void arch_vtime_task_switch (struct task_struct *tsk) { } +#endif /* __KERNEL__ */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING */ #endif /* __POWERPC_CPUTIME_H */
arch/powerpc/kernel/time.c +0 -6
@@ -375,12 +375,6 @@ void vtime_account_user(struct task_struct *tsk) account_user_time(tsk, utime, utimescaled); } -void vtime_task_switch (struct task_struct *prev) -{ -vtime_account (prev); -vtime_account_user (prev); -} -#else /* ! CONFIG_VIRT_CPU_ACCOUNTING */ #define calc_cputime_factors ()#endif
arch/s390/include/asm/cputime.h +1 -0
@@ -14,6 +14,7 @@#define __ARCH_HAS_VTIME_ACCOUNT +#define __ARCH_HAS_VTIME_TASK_SWITCH/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
kernel/sched/cputime.c +13 -0
@@ -443,6 +443,19 @@ void vtime_account_system_irqsafe(struct task_struct *tsk) }EXPORT_SYMBOL_GPL (vtime_account_system_irqsafe); +#ifndef __ARCH_HAS_VTIME_TASK_SWITCH +void vtime_task_switch (struct task_struct *prev) +{ +if (is_idle_task (prev)) +vtime_account_idle (prev); +else +vtime_account_system (prev); + +vtime_account_user (prev); +arch_vtime_task_switch (prev); +} +#endif +/* * Archs that account the whole time spent in the idle task * (outside irq) as idle time can rely on this and just implement
Signature · 1 line
1.7.5.4
Steven Rostedt
reviewerRe: [PATCH 3/4] vtime: Consolidate a bit the ctx switch code
from the subject: vtime: Consolidate a bit the ctx switch code
I read that line several times and it just keeps sounding like some chant done by the strikers in Greece over the austerity measures...
"Consolidate a bit! The context switch code!"
"Consolidate a bit! The context switch code!"
"Consolidate a bit! The context switch code!"
"Consolidate a bit! The context switch code!"
I guess because it just sounds Greek to me.
-- Steve
PATCH 4/4 vtime: No need to disable irqs on vtime_account()
In reply to Frederic Weisbeckervtime_account() is only called from irq entry. irqs are always disabled at this point so we can safely remove the irq disabling guards on that function.
--- kernel/sched/cputime.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
kernel/sched/cputime.c +0 -6
@@ -467,16 +467,10 @@ void vtime_task_switch(struct task_struct *prev)#ifndef __ARCH_HAS_VTIME_ACCOUNTvoid vtime_account (struct task_struct *tsk) { -unsigned long flags; - -local_irq_save (flags); -if (in_interrupt () || !is_idle_task (tsk))vtime_account_system (tsk);else vtime_account_idle (tsk); - -local_irq_restore (flags); }EXPORT_SYMBOL_GPL (vtime_account);#endif /* __ARCH_HAS_VTIME_ACCOUNT */
Signature · 1 line
1.7.5.4
Steven Rostedt
reviewerRe: [PATCH 4/4] vtime: No need to disable irqs on vtime_account()
Quoted 25 lines · Frederic Weisbecker
vtime_account()is only called from irq entry. irqs are always disabled at this point so we can safely remove the irq disabling guards on that function.Signed-off-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul Gortmaker <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Heiko Carstens <[email protected]>--- kernel/sched/cputime.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)kernel/sched/cputime.c +0
-0
kernel/sched/cputime.c void vtime_task_switch(struct task_struct *prev) · line 473
Quoted 7 lines
kernel/sched/cputime.c +0
-4@@ -467,16 +467,10 @@ void vtime_task_switch(struct task_struct *prev)#ifndef __ARCH_HAS_VTIME_ACCOUNTvoid vtime_account (struct task_struct *tsk) { -unsigned long flags; - -local_irq_save (flags); -
I'd add a WARN_ON_ONCE(!irqs_disabled()) again here, or is this also covered by the vtime_delta()?
-- Steve
Quoted 9 lines
kernel/sched/cputime.c +0
-2if (in_interrupt () || !is_idle_task (tsk))vtime_account_system (tsk);else vtime_account_idle(tsk); - - local_irq_restore(flags); }EXPORT_SYMBOL_GPL (vtime_account);#endif /* __ARCH_HAS_VTIME_ACCOUNT */
Re: [PATCH 4/4] vtime: No need to disable irqs on vtime_account()
2012/11/14 Steven Rostedt <[email protected]>:
Quoted 21 lines · Frederic Weisbecker
Quoted 20 lines
vtime_account()is only called from irq entry. irqs are always disabled at this point so we can safely remove the irq disabling guards on that function.Signed-off-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul Gortmaker <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Heiko Carstens <[email protected]>--- kernel/sched/cputime.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
Quoted 15 lines
kernel/sched/cputime.c void vtime_task_switch(struct task_struct *prev) · line 473
Quoted 12 lines
kernel/sched/cputime.c +0
-4@@ -467,16 +467,10 @@ void vtime_task_switch(struct task_struct *prev)#ifndef __ARCH_HAS_VTIME_ACCOUNTvoid vtime_account (struct task_struct *tsk) { -unsigned long flags; - -local_irq_save (flags); -I'd add a WARN_ON_ONCE(!irqs_disabled()) again here, or is this also covered by the
vtime_delta()?
Yeah it's the ending point for both vtime_account_system() and vtime_account_idle()
Quoted 6 lines · Frederic Weisbecker
Hi,
While working on full dynticks, I realized some more cleanups needed to be done. Here is it. If no comment arise, I'll send a pull request to Ingo in a week.
Other than what I've already commented on...
-- Steve
Quoted 20 lines
Thanks.
Frederic Weisbecker (4):
vtime: Remove the underscore prefix invasion
vtime: Explicitly account pending user time on process tick
vtime: Consolidate a bit the ctx switch code
vtime: No need to disable irqs onvtime_account()arch/ia64/include/asm/cputime.h | 2 ++ arch/ia64/kernel/time.c | 24 ++++-------------------- arch/powerpc/include/asm/cputime.h | 2 ++ arch/powerpc/kernel/time.c | 22 ++++++++-------------- arch/s390/include/asm/cputime.h | 1 + arch/s390/kernel/vtime.c | 11 ++++++++--- include/linux/kernel_stat.h | 8 ++++++++ include/linux/kvm_host.h | 4 ++-- include/linux/vtime.h | 9 +++++---- kernel/sched/cputime.c | 31 +++++++++++++++++++------------ 10 files changed, 59 insertions(+), 55 deletions(-)