sched, cputime: Cleanups related to task_times()
authorHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Wed, 2 Dec 2009 08:26:47 +0000 (17:26 +0900)
committerIngo Molnar <mingo@elte.hu>
Wed, 2 Dec 2009 16:32:39 +0000 (17:32 +0100)
- Remove if({u,s}t)s because no one call it with NULL now.
- Use cputime_{add,sub}().
- Add ifndef-endif for prev_{u,s}time since they are used
  only when !VIRT_CPU_ACCOUNTING.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Spencer Candland <spencer@bluehost.com>
Cc: Americo Wang <xiyou.wangcong@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
LKML-Reference: <4B1624C7.7040302@jp.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/sched.h
kernel/fork.c
kernel/sched.c

index 0395b0f4df3ae7bf973ca54e9eefc775b429e658..dff85e58264e92c1589b7302e5bd9c6c4d0546ae 100644 (file)
@@ -1331,7 +1331,9 @@ struct task_struct {
 
        cputime_t utime, stime, utimescaled, stimescaled;
        cputime_t gtime;
+#ifndef CONFIG_VIRT_CPU_ACCOUNTING
        cputime_t prev_utime, prev_stime;
+#endif
        unsigned long nvcsw, nivcsw; /* context switch counts */
        struct timespec start_time;             /* monotonic time */
        struct timespec real_start_time;        /* boot based time */
index 166b8c49257c589750f0b67479011ba7bac97038..ad7cb6d1193c60a1ab3b840fa4d4a83a0d7a38a6 100644 (file)
@@ -1066,8 +1066,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
        p->gtime = cputime_zero;
        p->utimescaled = cputime_zero;
        p->stimescaled = cputime_zero;
+#ifndef CONFIG_VIRT_CPU_ACCOUNTING
        p->prev_utime = cputime_zero;
        p->prev_stime = cputime_zero;
+#endif
 
        p->default_timer_slack_ns = current->timer_slack_ns;
 
index 4883fee99314b82e8914905b72523eeb53d92575..17e2c1db2bde9e624e776f1d170fc018af86a650 100644 (file)
@@ -5184,10 +5184,8 @@ void account_idle_ticks(unsigned long ticks)
 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
 void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
 {
-       if (ut)
-               *ut = p->utime;
-       if (st)
-               *st = p->stime;
+       *ut = p->utime;
+       *st = p->stime;
 }
 #else
 
@@ -5197,7 +5195,7 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
 
 void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
 {
-       cputime_t rtime, utime = p->utime, total = utime + p->stime;
+       cputime_t rtime, utime = p->utime, total = cputime_add(utime, p->stime);
 
        /*
         * Use CFS's precise accounting:
@@ -5217,12 +5215,10 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
         * Compare with previous values, to keep monotonicity:
         */
        p->prev_utime = max(p->prev_utime, utime);
-       p->prev_stime = max(p->prev_stime, rtime - p->prev_utime);
+       p->prev_stime = max(p->prev_stime, cputime_sub(rtime, p->prev_utime));
 
-       if (ut)
-               *ut = p->prev_utime;
-       if (st)
-               *st = p->prev_stime;
+       *ut = p->prev_utime;
+       *st = p->prev_stime;
 }
 #endif