Re: [PATCH 03/27] cputime: Allow dynamic switch between tick/virtual based cputime accounting
Hey Paul, 2013/1/4 Paul Gortmaker : > On 12-12-29 11:42 AM, Frederic Weisbecker wrote: >> Allow to dynamically switch between tick and virtual based cputime >> accounting. >> This way we can provide a kind of "on-demand" virtual based cputime >> accounting. In this mode, the kernel will rely on the user hooks >> subsystem to dynamically hook on kernel boundaries. >> >> This is in preparation for beeing able to stop the timer tick further >> idle. Doing so will depend on CONFIG_VIRT_CPU_ACCOUNTING which makes > > s/beeing/being/ -- also I know what you mean, but it may not be > 100% clear to everyone -- perhaps "...for being able to stop the > timer tick in more places than just the idle state." Thanks! Fixed for the next version! [...] >> +static inline bool vtime_accounting(void) { return false; } > > It wasn't 100% obvious what vtime_accounting() was doing until I > saw its definition below. I wonder if it should be something like > vtime_accounting_on() or vtime_accounting_enabled() instead? Agreed, I've renamed into vtime_accounting_enabled(). > >> #endif >> >> #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN >> diff --git a/init/Kconfig b/init/Kconfig >> index dad2b88..307bc35 100644 >> --- a/init/Kconfig >> +++ b/init/Kconfig >> @@ -342,6 +342,7 @@ config VIRT_CPU_ACCOUNTING >> bool "Deterministic task and CPU time accounting" >> depends on HAVE_VIRT_CPU_ACCOUNTING || HAVE_CONTEXT_TRACKING >> select VIRT_CPU_ACCOUNTING_GEN if !HAVE_VIRT_CPU_ACCOUNTING >> + select VIRT_CPU_ACCOUNTING_NATIVE if HAVE_VIRT_CPU_ACCOUNTING >> help >> Select this option to enable more accurate task and CPU time >> accounting. This is done by reading a CPU counter on each >> @@ -366,11 +367,16 @@ endchoice >> >> config VIRT_CPU_ACCOUNTING_GEN >> select CONTEXT_TRACKING >> + depends on VIRT_CPU_ACCOUNTING && HAVE_CONTEXT_TRACKING > > Should the 2nd half of this depends been already here, i.e. introduced > with the prev. patch that created VIRT_CPU_ACCOUNTING_GEN? Yeah, Li Zhong suggested that I turn *_GEN and *_NATIVE options into distinct choices for the user. So I moved that part to the previous patch. Thanks! -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 03/27] cputime: Allow dynamic switch between tick/virtual based cputime accounting
On 12-12-29 11:42 AM, Frederic Weisbecker wrote: > Allow to dynamically switch between tick and virtual based cputime accounting. > This way we can provide a kind of "on-demand" virtual based cputime > accounting. In this mode, the kernel will rely on the user hooks > subsystem to dynamically hook on kernel boundaries. > > This is in preparation for beeing able to stop the timer tick further > idle. Doing so will depend on CONFIG_VIRT_CPU_ACCOUNTING which makes s/beeing/being/ -- also I know what you mean, but it may not be 100% clear to everyone -- perhaps "...for being able to stop the timer tick in more places than just the idle state." > it possible to account the cputime without the tick by hooking on > kernel/user boundaries. > > Depending whether the tick is stopped or not, we can switch between > tick and vtime based accounting anytime in order to minimize the > overhead associated to user hooks. > > Signed-off-by: Frederic Weisbecker > Cc: Alessio Igor Bogani > Cc: Andrew Morton > Cc: Chris Metcalf > Cc: Christoph Lameter > Cc: Geoff Levand > Cc: Gilad Ben Yossef > Cc: Hakan Akkan > Cc: Ingo Molnar > Cc: Paul E. McKenney > Cc: Paul Gortmaker > Cc: Peter Zijlstra > Cc: Steven Rostedt > Cc: Thomas Gleixner > --- > include/linux/kernel_stat.h |2 +- > include/linux/sched.h |4 +- > include/linux/vtime.h |8 ++ > init/Kconfig|6 > kernel/fork.c |2 +- > kernel/sched/cputime.c | 58 +++--- > kernel/time/tick-sched.c|5 +++- > 7 files changed, 59 insertions(+), 26 deletions(-) > > diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h > index 66b7078..ed5f6ed 100644 > --- a/include/linux/kernel_stat.h > +++ b/include/linux/kernel_stat.h > @@ -127,7 +127,7 @@ 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 > +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE > static inline void account_process_tick(struct task_struct *tsk, int user) > { > vtime_account_user(tsk); > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 206bb08..66b2344 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -605,7 +605,7 @@ struct signal_struct { > cputime_t utime, stime, cutime, cstime; > cputime_t gtime; > cputime_t cgtime; > -#ifndef CONFIG_VIRT_CPU_ACCOUNTING > +#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE > struct cputime prev_cputime; > #endif > unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; > @@ -1365,7 +1365,7 @@ struct task_struct { > > cputime_t utime, stime, utimescaled, stimescaled; > cputime_t gtime; > -#ifndef CONFIG_VIRT_CPU_ACCOUNTING > +#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE > struct cputime prev_cputime; > #endif > unsigned long nvcsw, nivcsw; /* context switch counts */ > diff --git a/include/linux/vtime.h b/include/linux/vtime.h > index 1151960..e57020d 100644 > --- a/include/linux/vtime.h > +++ b/include/linux/vtime.h > @@ -10,12 +10,20 @@ 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); > + > +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN > +extern bool vtime_accounting(void); > #else > +static inline bool vtime_accounting(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_system_irqsafe(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 bool vtime_accounting(void) { return false; } It wasn't 100% obvious what vtime_accounting() was doing until I saw its definition below. I wonder if it should be something like vtime_accounting_on() or vtime_accounting_enabled() instead? > #endif > > #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN > diff --git a/init/Kconfig b/init/Kconfig > index dad2b88..307bc35 100644 > --- a/init/Kconfig > +++ b/init/Kconfig > @@ -342,6 +342,7 @@ config VIRT_CPU_ACCOUNTING > bool "Deterministic task and CPU time accounting" > depends on HAVE_VIRT_CPU_ACCOUNTING || HAVE_CONTEXT_TRACKING > select VIRT_CPU_ACCOUNTING_GEN if !HAVE_VIRT_CPU_ACCOUNTING > + select VIRT_CPU_ACCOUNTING_NATIVE if HAVE_VIRT_CPU_ACCOUNTING > help > Select this option to enable more accurate task and CPU time > accounting. This is done by reading a CPU counter on each > @@ -366,11 +367,16 @@ endchoice > > config VIRT_CPU_ACCOUNTING_GEN >
[PATCH 03/27] cputime: Allow dynamic switch between tick/virtual based cputime accounting
Allow to dynamically switch between tick and virtual based cputime accounting. This way we can provide a kind of "on-demand" virtual based cputime accounting. In this mode, the kernel will rely on the user hooks subsystem to dynamically hook on kernel boundaries. This is in preparation for beeing able to stop the timer tick further idle. Doing so will depend on CONFIG_VIRT_CPU_ACCOUNTING which makes it possible to account the cputime without the tick by hooking on kernel/user boundaries. Depending whether the tick is stopped or not, we can switch between tick and vtime based accounting anytime in order to minimize the overhead associated to user hooks. Signed-off-by: Frederic Weisbecker Cc: Alessio Igor Bogani Cc: Andrew Morton Cc: Chris Metcalf Cc: Christoph Lameter Cc: Geoff Levand Cc: Gilad Ben Yossef Cc: Hakan Akkan Cc: Ingo Molnar Cc: Paul E. McKenney Cc: Paul Gortmaker Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Thomas Gleixner --- include/linux/kernel_stat.h |2 +- include/linux/sched.h |4 +- include/linux/vtime.h |8 ++ init/Kconfig|6 kernel/fork.c |2 +- kernel/sched/cputime.c | 58 +++--- kernel/time/tick-sched.c|5 +++- 7 files changed, 59 insertions(+), 26 deletions(-) diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 66b7078..ed5f6ed 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -127,7 +127,7 @@ 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 +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE static inline void account_process_tick(struct task_struct *tsk, int user) { vtime_account_user(tsk); diff --git a/include/linux/sched.h b/include/linux/sched.h index 206bb08..66b2344 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -605,7 +605,7 @@ struct signal_struct { cputime_t utime, stime, cutime, cstime; cputime_t gtime; cputime_t cgtime; -#ifndef CONFIG_VIRT_CPU_ACCOUNTING +#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE struct cputime prev_cputime; #endif unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; @@ -1365,7 +1365,7 @@ struct task_struct { cputime_t utime, stime, utimescaled, stimescaled; cputime_t gtime; -#ifndef CONFIG_VIRT_CPU_ACCOUNTING +#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE struct cputime prev_cputime; #endif unsigned long nvcsw, nivcsw; /* context switch counts */ diff --git a/include/linux/vtime.h b/include/linux/vtime.h index 1151960..e57020d 100644 --- a/include/linux/vtime.h +++ b/include/linux/vtime.h @@ -10,12 +10,20 @@ 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); + +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN +extern bool vtime_accounting(void); #else +static inline bool vtime_accounting(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_system_irqsafe(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 bool vtime_accounting(void) { return false; } #endif #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN diff --git a/init/Kconfig b/init/Kconfig index dad2b88..307bc35 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -342,6 +342,7 @@ config VIRT_CPU_ACCOUNTING bool "Deterministic task and CPU time accounting" depends on HAVE_VIRT_CPU_ACCOUNTING || HAVE_CONTEXT_TRACKING select VIRT_CPU_ACCOUNTING_GEN if !HAVE_VIRT_CPU_ACCOUNTING + select VIRT_CPU_ACCOUNTING_NATIVE if HAVE_VIRT_CPU_ACCOUNTING help Select this option to enable more accurate task and CPU time accounting. This is done by reading a CPU counter on each @@ -366,11 +367,16 @@ endchoice config VIRT_CPU_ACCOUNTING_GEN select CONTEXT_TRACKING + depends on VIRT_CPU_ACCOUNTING && HAVE_CONTEXT_TRACKING bool help Implement a generic virtual based cputime accounting by using the context tracking subsystem. +config VIRT_CPU_ACCOUNTING_NATIVE + depends on VIRT_CPU_ACCOUNTING && HAVE_VIRT_CPU_ACCOUNTING + bool + config BSD_PROCESS_ACCT bool "BSD Process Accounting" help diff --git a/kernel/fork.c b/kernel/fork.c index a31b823..8e934d2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1222,7 +1222,7 @@ static struct task_struct *copy_process(unsigned long clone_flags