Commit 353c50eb authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by Ingo Molnar

sched/cputime: Simplify task_cputime()

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: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: default avatarFrederic 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 40565b5a
...@@ -906,14 +906,14 @@ static int apm_cpu_idle(struct cpuidle_device *dev, ...@@ -906,14 +906,14 @@ static int apm_cpu_idle(struct cpuidle_device *dev,
static int use_apm_idle; /* = 0 */ static int use_apm_idle; /* = 0 */
static unsigned int last_jiffies; /* = 0 */ static unsigned int last_jiffies; /* = 0 */
static unsigned int last_stime; /* = 0 */ static unsigned int last_stime; /* = 0 */
cputime_t stime; cputime_t stime, utime;
int apm_idle_done = 0; int apm_idle_done = 0;
unsigned int jiffies_since_last_check = jiffies - last_jiffies; unsigned int jiffies_since_last_check = jiffies - last_jiffies;
unsigned int bucket; unsigned int bucket;
recalc: recalc:
task_cputime(current, NULL, &stime); task_cputime(current, &utime, &stime);
if (jiffies_since_last_check > IDLE_CALC_LIMIT) { if (jiffies_since_last_check > IDLE_CALC_LIMIT) {
use_apm_idle = 0; use_apm_idle = 0;
} else if (jiffies_since_last_check > idle_period) { } else if (jiffies_since_last_check > idle_period) {
......
...@@ -2248,9 +2248,7 @@ extern cputime_t task_gtime(struct task_struct *t); ...@@ -2248,9 +2248,7 @@ extern cputime_t task_gtime(struct task_struct *t);
static inline void task_cputime(struct task_struct *t, static inline void task_cputime(struct task_struct *t,
cputime_t *utime, cputime_t *stime) cputime_t *utime, cputime_t *stime)
{ {
if (utime)
*utime = t->utime; *utime = t->utime;
if (stime)
*stime = t->stime; *stime = t->stime;
} }
...@@ -2265,9 +2263,7 @@ static inline void task_cputime_scaled(struct task_struct *t, ...@@ -2265,9 +2263,7 @@ static inline void task_cputime_scaled(struct task_struct *t,
cputime_t *utimescaled, cputime_t *utimescaled,
cputime_t *stimescaled) cputime_t *stimescaled)
{ {
if (utimescaled)
*utimescaled = t->utimescaled; *utimescaled = t->utimescaled;
if (stimescaled)
*stimescaled = t->stimescaled; *stimescaled = t->stimescaled;
} }
#else #else
......
...@@ -851,29 +851,25 @@ cputime_t task_gtime(struct task_struct *t) ...@@ -851,29 +851,25 @@ cputime_t task_gtime(struct task_struct *t)
* add up the pending nohz execution time since the last * add up the pending nohz execution time since the last
* cputime snapshot. * cputime snapshot.
*/ */
static void void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
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)
{ {
cputime_t delta;
unsigned int seq; unsigned int seq;
unsigned long long delta;
do { if (!vtime_accounting_enabled()) {
*udelta = 0; *utime = t->utime;
*sdelta = 0; *stime = t->stime;
return;
}
do {
seq = read_seqcount_begin(&t->vtime_seqcount); seq = read_seqcount_begin(&t->vtime_seqcount);
if (u_dst) *utime = t->utime;
*u_dst = *u_src; *stime = t->stime;
if (s_dst)
*s_dst = *s_src;
/* Task is sleeping, nothing to add */ /* Task is sleeping, nothing to add */
if (t->vtime_snap_whence == VTIME_INACTIVE || if (t->vtime_snap_whence == VTIME_INACTIVE || is_idle_task(t))
is_idle_task(t))
continue; continue;
delta = vtime_delta(t); delta = vtime_delta(t);
...@@ -882,33 +878,10 @@ fetch_task_cputime(struct task_struct *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 * Task runs either in user or kernel space, add pending nohz time to
* the right place. * the right place.
*/ */
if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU) { if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU)
*udelta = delta; *utime += delta;
} else { else if (t->vtime_snap_whence == VTIME_SYS)
if (t->vtime_snap_whence == VTIME_SYS) *stime += delta;
*sdelta = delta;
}
} while (read_seqcount_retry(&t->vtime_seqcount, seq)); } 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 */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
...@@ -133,9 +133,9 @@ static inline unsigned long long prof_ticks(struct task_struct *p) ...@@ -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) 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); return cputime_to_expires(utime);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment