sched/cputime: Simplify task_cputime()
authorStanislaw Gruszka <sgruszka@redhat.com>
Tue, 15 Nov 2016 02:06:52 +0000 (03:06 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 15 Nov 2016 08:51:05 +0000 (09:51 +0100)
Now since fetch_task_cputime() has no other users than task_cputime(),
its code could be used directly in task_cputime().

Moreover since only 2 task_cputime() calls of 17 use a NULL argument,
we can add dummy variables to those calls and remove NULL checks from
task_cputimes().

Also remove NULL checks from task_cputimes_scaled().

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Neuling <mikey@neuling.org>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1479175612-14718-5-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/apm_32.c
include/linux/sched.h
kernel/sched/cputime.c
kernel/time/posix-cpu-timers.c

index c7364bd633e1d8c1a346c69534ded295bc2ba48d..d90749b883f5eb896f9bdfe96f7f3cc47d7acd11 100644 (file)
@@ -906,14 +906,14 @@ static int apm_cpu_idle(struct cpuidle_device *dev,
        static int use_apm_idle; /* = 0 */
        static unsigned int last_jiffies; /* = 0 */
        static unsigned int last_stime; /* = 0 */
-       cputime_t stime;
+       cputime_t stime, utime;
 
        int apm_idle_done = 0;
        unsigned int jiffies_since_last_check = jiffies - last_jiffies;
        unsigned int bucket;
 
 recalc:
-       task_cputime(current, NULL, &stime);
+       task_cputime(current, &utime, &stime);
        if (jiffies_since_last_check > IDLE_CALC_LIMIT) {
                use_apm_idle = 0;
        } else if (jiffies_since_last_check > idle_period) {
index f72e81395dac3261ef3a8b5ff9445168f97a580f..fe3ce46cfd0305c769260c8e1ffdb4fc670dc8b7 100644 (file)
@@ -2248,10 +2248,8 @@ extern cputime_t task_gtime(struct task_struct *t);
 static inline void task_cputime(struct task_struct *t,
                                cputime_t *utime, cputime_t *stime)
 {
-       if (utime)
-               *utime = t->utime;
-       if (stime)
-               *stime = t->stime;
+       *utime = t->utime;
+       *stime = t->stime;
 }
 
 static inline cputime_t task_gtime(struct task_struct *t)
@@ -2265,10 +2263,8 @@ static inline void task_cputime_scaled(struct task_struct *t,
                                       cputime_t *utimescaled,
                                       cputime_t *stimescaled)
 {
-       if (utimescaled)
-               *utimescaled = t->utimescaled;
-       if (stimescaled)
-               *stimescaled = t->stimescaled;
+       *utimescaled = t->utimescaled;
+       *stimescaled = t->stimescaled;
 }
 #else
 static inline void task_cputime_scaled(struct task_struct *t,
index ba55ebf77f9a1e9cba2b83e3330d9b60a1fac4c2..7700a9cba335059d7234649bbbf35dd113307698 100644 (file)
@@ -851,29 +851,25 @@ cputime_t task_gtime(struct task_struct *t)
  * add up the pending nohz execution time since the last
  * cputime snapshot.
  */
-static void
-fetch_task_cputime(struct task_struct *t,
-                  cputime_t *u_dst, cputime_t *s_dst,
-                  cputime_t *u_src, cputime_t *s_src,
-                  cputime_t *udelta, cputime_t *sdelta)
+void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
 {
+       cputime_t delta;
        unsigned int seq;
-       unsigned long long delta;
 
-       do {
-               *udelta = 0;
-               *sdelta = 0;
+       if (!vtime_accounting_enabled()) {
+               *utime = t->utime;
+               *stime = t->stime;
+               return;
+       }
 
+       do {
                seq = read_seqcount_begin(&t->vtime_seqcount);
 
-               if (u_dst)
-                       *u_dst = *u_src;
-               if (s_dst)
-                       *s_dst = *s_src;
+               *utime = t->utime;
+               *stime = t->stime;
 
                /* Task is sleeping, nothing to add */
-               if (t->vtime_snap_whence == VTIME_INACTIVE ||
-                   is_idle_task(t))
+               if (t->vtime_snap_whence == VTIME_INACTIVE || is_idle_task(t))
                        continue;
 
                delta = vtime_delta(t);
@@ -882,33 +878,10 @@ fetch_task_cputime(struct task_struct *t,
                 * Task runs either in user or kernel space, add pending nohz time to
                 * the right place.
                 */
-               if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU) {
-                       *udelta = delta;
-               } else {
-                       if (t->vtime_snap_whence == VTIME_SYS)
-                               *sdelta = delta;
-               }
+               if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU)
+                       *utime += delta;
+               else if (t->vtime_snap_whence == VTIME_SYS)
+                       *stime += delta;
        } while (read_seqcount_retry(&t->vtime_seqcount, seq));
 }
-
-
-void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
-{
-       cputime_t udelta, sdelta;
-
-       if (!vtime_accounting_enabled()) {
-               if (utime)
-                       *utime = t->utime;
-               if (stime)
-                       *stime = t->stime;
-               return;
-       }
-
-       fetch_task_cputime(t, utime, stime, &t->utime,
-                          &t->stime, &udelta, &sdelta);
-       if (utime)
-               *utime += udelta;
-       if (stime)
-               *stime += sdelta;
-}
 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
index 39008d78927acb4f9a62f582cb7baba3f27620ee..e887ffc8eef39124f85b93342e97d5361c9d1353 100644 (file)
@@ -133,9 +133,9 @@ static inline unsigned long long prof_ticks(struct task_struct *p)
 }
 static inline unsigned long long virt_ticks(struct task_struct *p)
 {
-       cputime_t utime;
+       cputime_t utime, stime;
 
-       task_cputime(p, &utime, NULL);
+       task_cputime(p, &utime, &stime);
 
        return cputime_to_expires(utime);
 }