cputime: introduce cputime.
Subsystems (11)
PATCH 1/1 cputime: introduce cputime.
Hi Andrew,
after the three timer-header-cleanup patches have hit bitkeeper it's time for the next step: the cputime_t patch. We've been using this patch and the s/390 exploitation patch for micro-second based cpu time accounting for some time now and it seems rock solid. I didn't get a single bug report for it so far. Good for s/390, but now the question is what does the patch do to all the other architectures? 2.6.9 plus the cputime_t patch works fine on my thinkpad. Could you add this to -mm for broader testing please? The patch is cut against 2.6.10-rc1-mm1.
blue skies,
Martin
----
[patch] cputime: introduce cputime.
From: Martin Schwidefsky <[email protected]>
This patch introduces the concept of (virtual) cputime. Each architecture can define its method to measure cputime. The main idea is to define a cputime_t type and a set of operations on it (see asm-generic/cputime.h). Then use the type for utime, stime, cutime, cstime, it_virt_value, it_virt_incr, it_prof_value and it_prof_incr and use the cputime operations for each access to these variables. The default implementation is jiffies based and the effect of this patch for architectures which use the default implementation should be neglectible.
There is a second type cputime64_t which is necessary for the kernel_stat cpu statistics. The default cputime_t is 32 bit and based on HZ, this will overflow after 49.7 days. This is not enough for kernel_stat (ihmo not enough for a processes too), so it is necessary to have a 64 bit type.
The third thing that gets introduced by this patch is an additional field for the /proc/stat interface: cpu steal time. An architecture can account cpu steal time by calls to the account_stealtime function. The cpu which backs a virtual processor doesn't spent all of its time for the virtual cpu. To get meaningful cpu usage numbers this involuntary wait time needs to be accounted and exported to user space.
diffstat:
arch/parisc/kernel/binfmt_elf32.c | 6 - arch/ppc64/kernel/binfmt_elf32.c | 6 - arch/s390/kernel/binfmt_elf32.c | 6 - arch/sparc64/kernel/binfmt_elf32.c | 6 - fs/binfmt_elf.c | 12 +- fs/proc/proc_misc.c | 60 +++++++------ include/asm-alpha/cputime.h | 6 + include/asm-arm/cputime.h | 6 + include/asm-arm26/cputime.h | 6 + include/asm-cris/cputime.h | 6 + include/asm-generic/cputime.h | 64 ++++++++++++++ include/asm-h8300/cputime.h | 6 + include/asm-i386/cputime.h | 6 + include/asm-ia64/cputime.h | 6 + include/asm-m32r/cputime.h | 6 + include/asm-m68k/cputime.h | 6 + include/asm-m68knommu/cputime.h | 6 + include/asm-mips/cputime.h | 6 + include/asm-parisc/cputime.h | 6 + include/asm-ppc/cputime.h | 6 + include/asm-ppc64/cputime.h | 6 + include/asm-s390/cputime.h | 6 + include/asm-sh/cputime.h | 6 + include/asm-sh64/cputime.h | 6 + include/asm-sparc/cputime.h | 6 + include/asm-sparc64/cputime.h | 6 + include/asm-um/cputime.h | 6 + include/asm-v850/cputime.h | 6 + include/asm-x86_64/cputime.h | 6 + include/linux/kernel_stat.h | 20 ++-- include/linux/sched.h | 12 +- kernel/compat.c | 14 +-- kernel/cpu.c | 4 kernel/exit.c | 18 ++-- kernel/fork.c | 9 +- kernel/itimer.c | 55 ++++++------ kernel/sched.c | 166 +++++++++++++++++++++++++++++++------ kernel/signal.c | 14 +-- kernel/sys.c | 34 +++---- kernel/timer.c | 67 ++------------ mm/oom_kill.c | 3 41 files changed, 506 insertions(+), 202 deletions(-)
arch/parisc/kernel/binfmt_elf32.c +4 -2
@@ -92,10 +92,12 @@ current->thread.map_base =DEFAULT_MAP_BASE32 ; \ current->thread.task_size = DEFAULT_TASK_SIZE32 \ -#define jiffies_to_timeval jiffies_to_compat_timeval +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timevalstatic __inline__void -jiffies_to_compat_timeval (unsigned long jiffies,struct compat_timeval *value) +cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) { +unsigned long jiffies =cputime_to_jiffies (cputime); value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); value->tv_sec = jiffies /HZ ; }
arch/ppc64/kernel/binfmt_elf32.c +4 -2
@@ -60,10 +60,12 @@#include <linux/time.h> -#define jiffies_to_timeval jiffies_to_compat_timeval +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timevalstatic __inline__void -jiffies_to_compat_timeval (unsigned long jiffies,struct compat_timeval *value) +cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) { +unsigned long jiffies =cputime_to_jiffies (cputime); value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); value->tv_sec = jiffies /HZ ; }
arch/s390/kernel/binfmt_elf32.c +4 -2
@@ -173,10 +173,12 @@#undef MODULE_DESCRIPTION#undef MODULE_AUTHOR -#define jiffies_to_timeval jiffies_to_compat_timeval +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timevalstatic __inline__void -jiffies_to_compat_timeval (unsigned long jiffies,struct compat_timeval *value) +cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) { +unsigned long jiffies =cputime_to_jiffies (cputime); value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); value->tv_sec = jiffies /HZ ; }
arch/sparc64/kernel/binfmt_elf32.c +4 -2
@@ -132,10 +132,12 @@#include <linux/time.h> -#define jiffies_to_timeval jiffies_to_compat_timeval +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timevalstatic __inline__void -jiffies_to_compat_timeval (unsigned long jiffies,struct compat_timeval *value) +cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) { +unsigned long jiffies =cputime_to_jiffies (cputime); value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); value->tv_sec = jiffies /HZ ; }
fs/binfmt_elf.c +6 -6
@@ -1192,16 +1192,16 @@* this and each other thread to finish dying after the * core dump synchronization phase. */ -jiffies_to_timeval (p->utime + p->signal->utime, +cputime_to_timeval (cputime_add (p->utime, p->signal->utime), &prstatus->pr_utime); -jiffies_to_timeval (p->stime + p->signal->stime, +cputime_to_timeval (cputime_add (p->stime, p->signal->stime), &prstatus->pr_stime); }else { -jiffies_to_timeval (p->utime, &prstatus->pr_utime); -jiffies_to_timeval (p->stime, &prstatus->pr_stime); +cputime_to_timeval (p->utime, &prstatus->pr_utime); +cputime_to_timeval (p->stime, &prstatus->pr_stime); } -jiffies_to_timeval (p->signal->cutime, &prstatus->pr_cutime); -jiffies_to_timeval (p->signal->cstime, &prstatus->pr_cstime); +cputime_to_timeval (p->signal->cutime, &prstatus->pr_cutime); +cputime_to_timeval (p->signal->cstime, &prstatus->pr_cstime); } static void fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
fs/proc/proc_misc.c +33 -27
93 lines not on this page · raw message
include/asm-alpha/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __ALPHA_CPUTIME_H +#define __ALPHA_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __ALPHA_CPUTIME_H */
include/asm-arm/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __ARM_CPUTIME_H +#define __ARM_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __ARM_CPUTIME_H */
include/asm-arm26/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __ARM26_CPUTIME_H +#define __ARM26_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __ARM26_CPUTIME_H */
include/asm-cris/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __CRIS_CPUTIME_H +#define __CRIS_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __CRIS_CPUTIME_H */
include/asm-generic/cputime.h +64 -0
64 lines not on this page · raw message
include/asm-h8300/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __H8300_CPUTIME_H +#define __H8300_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __H8300_CPUTIME_H */
include/asm-i386/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __I386_CPUTIME_H +#define __I386_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __I386_CPUTIME_H */
include/asm-ia64/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __IA64_CPUTIME_H +#define __IA64_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __IA64_CPUTIME_H */
include/asm-m32r/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __M32R_CPUTIME_H +#define __M32R_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __M32R_CPUTIME_H */
include/asm-m68k/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __M68K_CPUTIME_H +#define __M68K_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __M68K_CPUTIME_H */
include/asm-m68knommu/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __M68KNOMMU_CPUTIME_H +#define __M68KNOMMU_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __M68KNOMMU_CPUTIME_H */
include/asm-mips/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __MIPS_CPUTIME_H +#define __MIPS_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __MIPS_CPUTIME_H */
include/asm-parisc/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __PARISC_CPUTIME_H +#define __PARISC_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __PARISC_CPUTIME_H */
include/asm-ppc/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __PPC_CPUTIME_H +#define __PPC_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __PPC_CPUTIME_H */
include/asm-ppc64/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __PPC_CPUTIME_H +#define __PPC_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __PPC_CPUTIME_H */
include/asm-s390/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __S390_CPUTIME_H +#define __S390_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __S390_CPUTIME_H */
include/asm-sh/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __SH_CPUTIME_H +#define __SH_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __SH_CPUTIME_H */
include/asm-sh64/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __SH64_CPUTIME_H +#define __SH64_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __SH64_CPUTIME_H */
include/asm-sparc/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __SPARC_CPUTIME_H +#define __SPARC_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __SPARC_CPUTIME_H */
include/asm-sparc64/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __SPARC64_CPUTIME_H +#define __SPARC64_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __SPARC64_CPUTIME_H */
include/asm-um/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __UM_CPUTIME_H +#define __UM_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __UM_CPUTIME_H */
include/asm-v850/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __V850_CPUTIME_H +#define __V850_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __V850_CPUTIME_H */
include/asm-x86_64/cputime.h +6 -0
@@ -0,0 +1,6 @@ +#ifndef __X86_64_CPUTIME_H +#define __X86_64_CPUTIME_H + +#include <asm-generic/cputime.h> + +#endif /* __X86_64_CPUTIME_H */
include/linux/kernel_stat.h +13 -7
@@ -6,6 +6,7 @@#include <linux/smp.h> #include <linux/threads.h> #include <linux/percpu.h> +#include <asm/cputime.h> /* * 'kernel_stat.h' contains the definitions needed for doing
@@ -14,13 +15,14 @@*/ struct cpu_usage_stat { -u64 user; -u64 nice; -u64 system; -u64 softirq; -u64 irq; -u64 idle; -u64 iowait; +cputime64_t user; +cputime64_t nice; +cputime64_t system; +cputime64_t softirq; +cputime64_t irq; +cputime64_t idle; +cputime64_t iowait; +cputime64_t steal; };struct kernel_stat {
@@ -50,4 +52,8 @@ return sum; } +extern void account_user_time (struct task_struct *,cputime_t ); +extern void account_system_time (struct task_struct *,int ,cputime_t ); +extern void account_steal_time (struct task_struct *,cputime_t ); +#endif /* _LINUX_KERNEL_STAT_H */
include/linux/sched.h +7 -5
@@ -20,6 +20,7 @@#include <asm/page.h> #include <asm/ptrace.h> #include <asm/mmu.h> +#include <asm/cputime.h> #include <linux/smp.h> #include <linux/sem.h>
@@ -170,7 +171,7 @@extern void cpu_init (void );extern void trap_init (void );extern void update_process_times (int user); -extern void scheduler_tick (int user_tick,int system); +extern void scheduler_tick (void );extern unsigned long cache_decay_ticks;/* Attach to any functions which should be ignored in wchan output. */
@@ -310,7 +311,7 @@* Live threads maintain their own counters and add to these * in __exit_signal, except for the group leader. */ -unsigned long utime, stime, cutime, cstime; +cputime_t utime, stime, cutime, cstime;unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
@@ -582,10 +583,11 @@int __user *clear_child_tid;/* CLONE_CHILD_CLEARTID */ unsigned long rt_priority; -unsigned long it_real_value, it_prof_value, it_virt_value; -unsigned long it_real_incr, it_prof_incr, it_virt_incr; +unsigned long it_real_value, it_real_incr; +cputime_t it_virt_value, it_virt_incr; +cputime_t it_prof_value, it_prof_incr;struct timer_list real_timer; -unsigned long utime, stime; +cputime_t utime, stime;unsigned long nvcsw, nivcsw;/* context switch counts */ struct timespec start_time;/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
kernel/compat.c +7 -7
@@ -162,15 +162,15 @@struct compat_tms tmp;struct task_struct *tsk = current;struct task_struct *t; -unsigned long utime, stime, cutime, cstime; +cputime_t utime, stime, cutime, cstime;read_lock (&tasklist_lock); utime = tsk->signal->utime; stime = tsk->signal->stime; t = tsk;do { - utime += t->utime; - stime += t->stime; + utime =cputime_add (utime, t->utime); + stime =cputime_add (stime, t->stime); t =next_thread (t); }while (t != tsk);
@@ -189,10 +189,10 @@spin_unlock_irq (&tsk->sighand->siglock);read_unlock (&tasklist_lock); - tmp.tms_utime =compat_jiffies_to_clock_t (utime); - tmp.tms_stime =compat_jiffies_to_clock_t (stime); - tmp.tms_cutime =compat_jiffies_to_clock_t (cutime); - tmp.tms_cstime =compat_jiffies_to_clock_t (cstime); + tmp.tms_utime =compat_jiffies_to_clock_t (cputime_to_jiffies (utime)); + tmp.tms_stime =compat_jiffies_to_clock_t (cputime_to_jiffies (stime)); + tmp.tms_cutime =compat_jiffies_to_clock_t (cputime_to_jiffies (cutime)); + tmp.tms_cstime =compat_jiffies_to_clock_t (cputime_to_jiffies (cstime));if (copy_to_user (tbuf, &tmp,sizeof (tmp)))return -EFAULT ; }
kernel/cpu.c +3 -1
@@ -49,7 +49,9 @@write_lock_irq (&tasklist_lock);for_each_process (p) { -if (task_cpu (p) == cpu && (p->utime !=0 || p->stime !=0 )) +if (task_cpu (p) == cpu && + (!cputime_eq (p->utime, cputime_zero) || + !cputime_eq (p->stime, cputime_zero)))printk (KERN_WARNING "Task %s (pid = %d) is on cpu %d\ (state = %ld, flags = %lx) \n" , p->comm, p->pid, cpu, p->state, p->flags);
kernel/exit.c +12 -6
@@ -763,8 +763,8 @@* Clear these here so that update_process_times() won't try to deliver * itimer, profile or rlimit signals to this task while it is in late exit. */ - tsk->it_virt_value =0 ; - tsk->it_prof_value =0 ; + tsk->it_virt_value = cputime_zero; + tsk->it_prof_value = cputime_zero;write_unlock_irq (&tasklist_lock);
@@ -1052,10 +1052,16 @@* here reaping other children at the same time. */ spin_lock_irq (&p->parent->sighand->siglock); - p->parent->signal->cutime += - p->utime + p->signal->utime + p->signal->cutime; - p->parent->signal->cstime += - p->stime + p->signal->stime + p->signal->cstime; + p->parent->signal->cutime = +cputime_add (p->parent->signal->cutime, +cputime_add (p->utime, +cputime_add (p->signal->utime, + p->signal->cutime))); + p->parent->signal->cstime = +cputime_add (p->parent->signal->cstime, +cputime_add (p->stime, +cputime_add (p->signal->stime, + p->signal->cstime))); p->parent->signal->cmin_flt += p->min_flt + p->signal->min_flt + p->signal->cmin_flt; p->parent->signal->cmaj_flt +=
kernel/fork.c +5 -4
@@ -748,7 +748,7 @@ sig->leader =0 ;/* session leadership doesn't inherit */ sig->tty_old_pgrp =0 ; - sig->utime = sig->stime = sig->cutime = sig->cstime =0 ; + sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw =0 ; sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt =0 ;
@@ -869,12 +869,13 @@clear_tsk_thread_flag (p,TIF_SIGPENDING );init_sigpending (&p->pending); - p->it_real_value = p->it_virt_value = p->it_prof_value =0 ; - p->it_real_incr = p->it_virt_incr = p->it_prof_incr =0 ; + p->it_real_value = p->it_real_incr =0 ; + p->it_virt_value = p->it_virt_incr = cputime_zero; + p->it_prof_value = p->it_prof_incr = cputime_zero;init_timer (&p->real_timer); p->real_timer.data = (unsigned long ) p; - p->utime = p->stime =0 ; + p->utime = p->stime = cputime_zero; p->lock_depth =-1 ;/* -1 = no lock */ do_posix_clock_monotonic_gettime (&p->start_time); p->security =NULL ;
kernel/itimer.c +29 -26
97 lines not on this page · raw message
kernel/sched.c +142 -24
197 lines not on this page · raw message
kernel/signal.c +8 -6
@@ -380,8 +380,8 @@* We won't ever get here for the group leader, since it * will have been the last reference on the signal_struct. */ - sig->utime += tsk->utime; - sig->stime += tsk->stime; + sig->utime =cputime_add (sig->utime, tsk->utime); + sig->stime =cputime_add (sig->stime, tsk->stime); sig->min_flt += tsk->min_flt; sig->maj_flt += tsk->maj_flt; sig->nvcsw += tsk->nvcsw;
@@ -1457,8 +1457,10 @@ info.si_uid = tsk->uid;/* FIXME: find out whether or not this is supposed to be c*time. */ - info.si_utime = tsk->utime + tsk->signal->utime; - info.si_stime = tsk->stime + tsk->signal->stime; + info.si_utime =cputime_to_jiffies (cputime_add (tsk->utime, + tsk->signal->utime)); + info.si_stime =cputime_to_jiffies (cputime_add (tsk->stime, + tsk->signal->stime)); info.si_status = tsk->exit_code &0x7f ;if (tsk->exit_code &0x80 )
@@ -1514,8 +1516,8 @@ info.si_uid = tsk->uid;/* FIXME: find out whether or not this is supposed to be c*time. */ - info.si_utime = tsk->utime; - info.si_stime = tsk->stime; + info.si_utime =cputime_to_jiffies (tsk->utime); + info.si_stime =cputime_to_jiffies (tsk->stime); info.si_code = why;switch (why) {
kernel/sys.c +17 -17
@@ -1000,15 +1000,15 @@struct tms tmp;struct task_struct *tsk = current;struct task_struct *t; -unsigned long utime, stime, cutime, cstime; +cputime_t utime, stime, cutime, cstime;read_lock (&tasklist_lock); utime = tsk->signal->utime; stime = tsk->signal->stime; t = tsk;do { - utime += t->utime; - stime += t->stime; + utime =cputime_add (utime, t->utime); + stime =cputime_add (stime, t->stime); t =next_thread (t); }while (t != tsk);
@@ -1027,10 +1027,10 @@spin_unlock_irq (&tsk->sighand->siglock);read_unlock (&tasklist_lock); - tmp.tms_utime =jiffies_to_clock_t (utime); - tmp.tms_stime =jiffies_to_clock_t (stime); - tmp.tms_cutime =jiffies_to_clock_t (cutime); - tmp.tms_cstime =jiffies_to_clock_t (cstime); + tmp.tms_utime =cputime_to_clock_t (utime); + tmp.tms_stime =cputime_to_clock_t (stime); + tmp.tms_cutime =cputime_to_clock_t (cutime); + tmp.tms_cstime =cputime_to_clock_t (cstime);if (copy_to_user (tbuf, &tmp,sizeof (struct tms )))return -EFAULT ; }
@@ -1633,7 +1633,7 @@ {struct task_struct *t;unsigned long flags; -unsigned long utime, stime; +cputime_t utime, stime;memset ((char *) r,0 ,sizeof *r);
@@ -1650,12 +1650,12 @@ r->ru_minflt = p->signal->cmin_flt; r->ru_majflt = p->signal->cmaj_flt;spin_unlock_irqrestore (&p->sighand->siglock, flags); -jiffies_to_timeval (utime, &r->ru_utime); -jiffies_to_timeval (stime, &r->ru_stime); +cputime_to_timeval (utime, &r->ru_utime); +cputime_to_timeval (stime, &r->ru_stime);break ;case RUSAGE_SELF :spin_lock_irqsave (&p->sighand->siglock, flags); - utime = stime =0 ; + utime = stime = cputime_zero; goto sum_group;case RUSAGE_BOTH :spin_lock_irqsave (&p->sighand->siglock, flags);
@@ -1666,16 +1666,16 @@ r->ru_minflt = p->signal->cmin_flt; r->ru_majflt = p->signal->cmaj_flt; sum_group: - utime += p->signal->utime; - stime += p->signal->stime; + utime =cputime_add (utime, p->signal->utime); + stime =cputime_add (stime, p->signal->stime); r->ru_nvcsw += p->signal->nvcsw; r->ru_nivcsw += p->signal->nivcsw; r->ru_minflt += p->signal->min_flt; r->ru_majflt += p->signal->maj_flt; t = p; do { - utime += t->utime; - stime += t->stime; + utime = cputime_add(utime, t->utime); + stime = cputime_add(stime, t->stime); r->ru_nvcsw += t->nvcsw; r->ru_nivcsw += t->nivcsw; r->ru_minflt += t->min_flt;
@@ -1683,8 +1683,8 @@ t =next_thread (t); }while (t != p);spin_unlock_irqrestore (&p->sighand->siglock, flags); -jiffies_to_timeval (utime, &r->ru_utime); -jiffies_to_timeval (stime, &r->ru_stime); +cputime_to_timeval (utime, &r->ru_utime); +cputime_to_timeval (stime, &r->ru_stime);break ;default :BUG ();
kernel/timer.c +10 -57
81 lines not on this page · raw message
mm/oom_kill.c +2 -1
@@ -61,7 +61,8 @@* of seconds. There is no particular reason for this other than * that it turned out to work very well in practice. */ - cpu_time = (p->utime + p->stime) >> (SHIFT_HZ +3 ); + cpu_time = (cputime_to_jiffies (p->utime) +cputime_to_jiffies (p->stime)) + >> (SHIFT_HZ +3 );if (uptime >= p->start_time.tv_sec) run_time = (uptime - p->start_time.tv_sec) >>10 ;
Quoted 6 lines · Martin Schwidefsky
The third thing that gets introduced by this patch is an additional field for the
/proc/statinterface: cpu steal time. An architecture can account cpu steal time by calls to theaccount_stealtimefunction. The cpu which backs a virtual processor doesn't spent all of its time for the virtual cpu. To get meaningful cpu usage numbers this involuntary wait time needs to be accounted and exported to user space.
This will be useful for User Mode Linux, Xen and iSeries too.
I suspect we'll also want to report hypervisor wait time in /proc/stat, so we can see how much time our guest is really getting...
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 2 lines · Martin Schwidefsky
This patch introduces the concept of (virtual) cputime.
I'm not sure that we need virtual cputime when we're only getting two second uptimes...
Unable to handle kernel NULL pointer dereference at virtual address 00000080 printing eip: c01185f6 *pde = 00000000 Oops: 0000 [#1] SMP Modules linked in: CPU: 1 EIP: 0060:[<c01185f6>] Not tainted VLI EFLAGS: 00010002 (2.6.10-rc1-mm2)
EIP is at account_system_time+0x4e/0x138
eax: 00000000 ebx: 00000001 ecx: 00c7cf60 edx: c058ed00
esi: c120bc60 edi: c19a6a20 ebp: c19a7ecc esp: c19a7ebc
ds: 007b es: 007b ss: 0068
Process khelper (pid: 352, threadinfo=c19a7000 task=c19a6a20)
Stack: 00000001 c058e48c 00000000 c120c020 c19a7ef0 c01256ee c19a6a20 00010000
00000001 00000004 c058e48c c058e488 c19a7f28 c19a7f28 c0112709 00000000
c19a6a20 c19a6a20 c19a6eec 00000160 00000000 00000000 00000000 00000000
Call Trace:
[<c0106b27>] show_stack+0x7b/0x88
[<c0106c66>] show_registers+0x112/0x188
[<c0106e4f>] die+0xe7/0x170
[<c011589b>] do_page_fault+0x413/0x57b
[<c01067a1>] error_code+0x2d/0x38
[<c01256ee>] update_process_times+0x36/0xf0
[<c0112709>] smp_apic_timer_interrupt+0xd1/0xe4
[<c0106726>] apic_timer_interrupt+0x1a/0x20
[<c011e080>] release_task+0xdc/0x138
[<c011f234>] exit_notify+0x6fc/0x710
[<c011f6e6>] do_exit+0x49e/0x4cc
[<c012baff>] ____call_usermodehelper+0xb3/0xb4
[<c010428d>] kernel_thread_helper+0x5/0xc
Code: c0 01 c8 89 45 fc 8b 45 10 ba 00 ed 58 c0 8b 9f 5c 01 00 00 03 87 60 01 00 00 89 87 60 01 00 00 01 c3 8b 87 7c - kernel threads may have null p->signal
- remove some deoptimising inlines
---
25-akpm/kernel/sched.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
kernel/sched.c renamed from kernel/sched.c~cputime-introduce-cputime-fix +6 -4
@@ -2275,7 +2275,7 @@ static inline void account_it_virt(struc* @p: the process that the cpu time gets accounted to * @cputime: the cpu time spent in user and kernel space since the last update */ -static inline void account_it_prof (struct task_struct *p,cputime_t cputime) +static void account_it_prof (struct task_struct *p,cputime_t cputime) {cputime_t it_prof = p->it_prof_value;
@@ -2296,7 +2296,7 @@ static inline void account_it_prof(struc* @p: the process that the cpu time gets accounted to * @cputime: the cpu time spent in user and kernel space since the last update */ -static inline void check_rlimit (struct task_struct *p,cputime_t cputime) +static void check_rlimit (struct task_struct *p,cputime_t cputime) {cputime_t total, tmp;
@@ -2328,7 +2328,8 @@ void account_user_time(struct task_struc p->utime =cputime_add (p->utime, cputime);/* Check for signals (SIGVTALRM, SIGPROF, SIGXCPU & SIGKILL). */ -check_rlimit (p, cputime); +if (likely (p->signal)) +check_rlimit (p, cputime);account_it_virt (p, cputime);account_it_prof (p, cputime);
@@ -2356,7 +2357,8 @@ void account_system_time(struct task_str p->stime =cputime_add (p->stime, cputime);/* Check for signals (SIGPROF, SIGXCPU & SIGKILL). */ -check_rlimit (p, cputime); +if (likely (p->signal)) +check_rlimit (p, cputime);account_it_prof (p, cputime);/* Add system time to cpustat. */
_
A message that is not in the archive (sent off-list or not yet received): OF35D2677F.494347CD-ON42256F3B.002DDBE5-42256F3B.002F22AE@de.ibm.com
Quoted 5 lines · Martin Schwidefsky
Quoted 3 lines
- kernel threads may have null
p->signal
- remove some deoptimising inlinesDoes it work with these two changes ?
Well it doesn't crash ;)
It compiles OK on a bunch of architectures, bloats the kernel by 2k and various system monitoring tools emit sensible-looking numbers. What should I be looking for?