[PATCH] fix scaled & unscaled cputime accounting
authorMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 31 Dec 2008 14:11:37 +0000 (15:11 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 31 Dec 2008 14:11:46 +0000 (15:11 +0100)
The utimescaled / stimescaled fields in the task structure and the
global cpustat should be set on all architectures. On s390 the calls
to account_user_time_scaled and account_system_time_scaled never have
been added. In addition system time that is accounted as guest time
to the user time of a process is accounted to the scaled system time
instead of the scaled user time.
To fix the bugs and to prevent future forgetfulness this patch merges
account_system_time_scaled into account_system_time and
account_user_time_scaled into account_user_time.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Michael Neuling <mikey@neuling.org>
Acked-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/ia64/kernel/time.c
arch/powerpc/kernel/time.c
arch/s390/kernel/vtime.c
include/linux/kernel_stat.h
kernel/sched.c
kernel/time/tick-sched.c
kernel/timer.c

index 65c10a42c88f37fbb998012a8f293bd4003f1485..4ee367817049aba6fcc1572cdd57fe6258e82604 100644 (file)
@@ -93,13 +93,11 @@ void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
        now = ia64_get_itc();
 
        delta_stime = cycle_to_cputime(pi->ac_stime + (now - pi->ac_stamp));
-       account_system_time(prev, 0, delta_stime);
-       account_system_time_scaled(prev, delta_stime);
+       account_system_time(prev, 0, delta_stime, delta_stime);
 
        if (pi->ac_utime) {
                delta_utime = cycle_to_cputime(pi->ac_utime);
-               account_user_time(prev, delta_utime);
-               account_user_time_scaled(prev, delta_utime);
+               account_user_time(prev, delta_utime, delta_utime);
        }
 
        pi->ac_stamp = ni->ac_stamp = now;
@@ -122,8 +120,7 @@ void account_system_vtime(struct task_struct *tsk)
        now = ia64_get_itc();
 
        delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp));
-       account_system_time(tsk, 0, delta_stime);
-       account_system_time_scaled(tsk, delta_stime);
+       account_system_time(tsk, 0, delta_stime, delta_stime);
        ti->ac_stime = 0;
 
        ti->ac_stamp = now;
@@ -143,8 +140,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
 
        if (ti->ac_utime) {
                delta_utime = cycle_to_cputime(ti->ac_utime);
-               account_user_time(p, delta_utime);
-               account_user_time_scaled(p, delta_utime);
+               account_user_time(p, delta_utime, delta_utime);
                ti->ac_utime = 0;
        }
 }
index e1f3a51404292ee3c422295e47292da9b7c22256..92650ccad2e1c215645a0e535e471e9f3e2958a0 100644 (file)
@@ -256,8 +256,7 @@ void account_system_vtime(struct task_struct *tsk)
                delta += sys_time;
                get_paca()->system_time = 0;
        }
-       account_system_time(tsk, 0, delta);
-       account_system_time_scaled(tsk, deltascaled);
+       account_system_time(tsk, 0, delta, deltascaled);
        per_cpu(cputime_last_delta, smp_processor_id()) = delta;
        per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled;
        local_irq_restore(flags);
@@ -275,10 +274,8 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
 
        utime = get_paca()->user_time;
        get_paca()->user_time = 0;
-       account_user_time(tsk, utime);
-
        utimescaled = cputime_to_scaled(utime);
-       account_user_time_scaled(tsk, utimescaled);
+       account_user_time(tsk, utime, utimescaled);
 }
 
 /*
index 75a6e62ea9737e09471fcfd57d13b0c8fcfbed01..07283aea2e56359a88e5291336207def99084400 100644 (file)
@@ -50,12 +50,12 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
        rcu_user_flag = cputime != 0;
        S390_lowcore.user_timer -= cputime << 12;
        S390_lowcore.steal_clock -= cputime << 12;
-       account_user_time(tsk, cputime);
+       account_user_time(tsk, cputime, cputime);
 
        cputime =  S390_lowcore.system_timer >> 12;
        S390_lowcore.system_timer -= cputime << 12;
        S390_lowcore.steal_clock -= cputime << 12;
-       account_system_time(tsk, HARDIRQ_OFFSET, cputime);
+       account_system_time(tsk, HARDIRQ_OFFSET, cputime, cputime);
 
        cputime = S390_lowcore.steal_clock;
        if ((__s64) cputime > 0) {
@@ -82,12 +82,12 @@ void account_vtime(struct task_struct *tsk)
        cputime = S390_lowcore.user_timer >> 12;
        S390_lowcore.user_timer -= cputime << 12;
        S390_lowcore.steal_clock -= cputime << 12;
-       account_user_time(tsk, cputime);
+       account_user_time(tsk, cputime, cputime);
 
        cputime =  S390_lowcore.system_timer >> 12;
        S390_lowcore.system_timer -= cputime << 12;
        S390_lowcore.steal_clock -= cputime << 12;
-       account_system_time(tsk, 0, cputime);
+       account_system_time(tsk, 0, cputime, cputime);
 }
 
 /*
@@ -107,7 +107,7 @@ void account_system_vtime(struct task_struct *tsk)
        cputime =  S390_lowcore.system_timer >> 12;
        S390_lowcore.system_timer -= cputime << 12;
        S390_lowcore.steal_clock -= cputime << 12;
-       account_system_time(tsk, 0, cputime);
+       account_system_time(tsk, 0, cputime, cputime);
 }
 EXPORT_SYMBOL_GPL(account_system_vtime);
 
index 4ee4b3d2316ffc78495e7bfa0dd3017f220c05c9..c78a459662a62c5d711c754876092ef9fa852986 100644 (file)
@@ -79,10 +79,8 @@ static inline unsigned int kstat_irqs(unsigned int irq)
 }
 
 extern unsigned long long task_delta_exec(struct task_struct *);
-extern void account_user_time(struct task_struct *, cputime_t);
-extern void account_user_time_scaled(struct task_struct *, cputime_t);
-extern void account_system_time(struct task_struct *, int, cputime_t);
-extern void account_system_time_scaled(struct task_struct *, cputime_t);
+extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
+extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
 extern void account_steal_time(struct task_struct *, cputime_t);
 
 #endif /* _LINUX_KERNEL_STAT_H */
index fff1c4a20b6538966a0cf2b97a012c045d52b84d..5b03679ff712930027c11ad9eda5ebbccd7cb691 100644 (file)
@@ -4080,13 +4080,17 @@ unsigned long long task_delta_exec(struct task_struct *p)
  * Account user cpu time to a process.
  * @p: the process that the cpu time gets accounted to
  * @cputime: the cpu time spent in user space since the last update
+ * @cputime_scaled: cputime scaled by cpu frequency
  */
-void account_user_time(struct task_struct *p, cputime_t cputime)
+void account_user_time(struct task_struct *p, cputime_t cputime,
+                      cputime_t cputime_scaled)
 {
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
        cputime64_t tmp;
 
+       /* Add user time to process. */
        p->utime = cputime_add(p->utime, cputime);
+       p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
        account_group_user_time(p, cputime);
 
        /* Add user time to cpustat. */
@@ -4103,51 +4107,49 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
  * Account guest cpu time to a process.
  * @p: the process that the cpu time gets accounted to
  * @cputime: the cpu time spent in virtual machine since the last update
+ * @cputime_scaled: cputime scaled by cpu frequency
  */
-static void account_guest_time(struct task_struct *p, cputime_t cputime)
+static void account_guest_time(struct task_struct *p, cputime_t cputime,
+                              cputime_t cputime_scaled)
 {
        cputime64_t tmp;
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
 
        tmp = cputime_to_cputime64(cputime);
 
+       /* Add guest time to process. */
        p->utime = cputime_add(p->utime, cputime);
+       p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
        account_group_user_time(p, cputime);
        p->gtime = cputime_add(p->gtime, cputime);
 
+       /* Add guest time to cpustat. */
        cpustat->user = cputime64_add(cpustat->user, tmp);
        cpustat->guest = cputime64_add(cpustat->guest, tmp);
 }
 
-/*
- * Account scaled user cpu time to a process.
- * @p: the process that the cpu time gets accounted to
- * @cputime: the cpu time spent in user space since the last update
- */
-void account_user_time_scaled(struct task_struct *p, cputime_t cputime)
-{
-       p->utimescaled = cputime_add(p->utimescaled, cputime);
-}
-
 /*
  * Account system cpu time to a process.
  * @p: the process that the cpu time gets accounted to
  * @hardirq_offset: the offset to subtract from hardirq_count()
  * @cputime: the cpu time spent in kernel space since the last update
+ * @cputime_scaled: cputime scaled by cpu frequency
  */
 void account_system_time(struct task_struct *p, int hardirq_offset,
-                        cputime_t cputime)
+                        cputime_t cputime, cputime_t cputime_scaled)
 {
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
        struct rq *rq = this_rq();
        cputime64_t tmp;
 
        if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
-               account_guest_time(p, cputime);
+               account_guest_time(p, cputime, cputime_scaled);
                return;
        }
 
+       /* Add system time to process. */
        p->stime = cputime_add(p->stime, cputime);
+       p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
        account_group_system_time(p, cputime);
 
        /* Add system time to cpustat. */
@@ -4166,17 +4168,6 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
        acct_update_integrals(p);
 }
 
-/*
- * Account scaled system cpu time to a process.
- * @p: the process that the cpu time gets accounted to
- * @hardirq_offset: the offset to subtract from hardirq_count()
- * @cputime: the cpu time spent in kernel space since the last update
- */
-void account_system_time_scaled(struct task_struct *p, cputime_t cputime)
-{
-       p->stimescaled = cputime_add(p->stimescaled, cputime);
-}
-
 /*
  * Account for involuntary wait time.
  * @p: the process from which the cpu time has been stolen
index 8f3fc2582d38b7073927e9dc004ef38e16909ab0..1f2fce2479fef78cc6ce8113d15d07ee71377e6e 100644 (file)
@@ -420,6 +420,7 @@ void tick_nohz_restart_sched_tick(void)
        int cpu = smp_processor_id();
        struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
        unsigned long ticks;
+       cputime_t cputime;
        ktime_t now;
 
        local_irq_disable();
@@ -452,8 +453,8 @@ void tick_nohz_restart_sched_tick(void)
         */
        if (ticks && ticks < LONG_MAX) {
                add_preempt_count(HARDIRQ_OFFSET);
-               account_system_time(current, HARDIRQ_OFFSET,
-                                   jiffies_to_cputime(ticks));
+               cputime = jiffies_to_cputime(ticks);
+               account_system_time(current, HARDIRQ_OFFSET, cputime, cputime);
                sub_preempt_count(HARDIRQ_OFFSET);
        }
 
index 566257d1dc10327818f787e5ca04559c05bd2566..b5efb528aa1dcd1aaa878a1b81aff597e60b0f9c 100644 (file)
@@ -1023,13 +1023,11 @@ void account_process_tick(struct task_struct *p, int user_tick)
 {
        cputime_t one_jiffy = jiffies_to_cputime(1);
 
-       if (user_tick) {
-               account_user_time(p, one_jiffy);
-               account_user_time_scaled(p, cputime_to_scaled(one_jiffy));
-       } else {
-               account_system_time(p, HARDIRQ_OFFSET, one_jiffy);
-               account_system_time_scaled(p, cputime_to_scaled(one_jiffy));
-       }
+       if (user_tick)
+               account_user_time(p, one_jiffy, cputime_to_scaled(one_jiffy));
+       else
+               account_system_time(p, HARDIRQ_OFFSET, one_jiffy,
+                                   cputime_to_scaled(one_jiffy));
 }
 #endif
 
This page took 0.033312 seconds and 5 git commands to generate.