From: Frans Pop Date: Wed, 14 Nov 2007 00:18:19 +0000 (+0100) Subject: sched: keep utime/stime monotonic X-Git-Tag: v2.6.23.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e823c33c6f670beba3c14f4a451fd2b34c3eb40c;p=thirdparty%2Fkernel%2Fstable.git sched: keep utime/stime monotonic sched: keep utime/stime monotonic cpustats use utime/stime as a ratio against sum_exec_runtime, as a consequence it can happen - when the ratio changes faster than time accumulates - that either can be appear to go backwards. Combined backport for 2.6.23 of the following patches from mainline: commit 73a2bcb0edb9ffb0b007b3546b430e2c6e415eee Author: Peter Zijlstra sched: keep utime/stime monotonic commit 9301899be75b464ef097f0b5af7af6d9bd8f68a7 Author: Balbir Singh sched: fix /proc//stat stime/utime monotonicity, part 2 Signed-off-by: Frans Pop CC: Peter Zijlstra CC: Balbir Singh Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/proc/array.c b/fs/proc/array.c index ee4814dd98f9c..20d7ae4582e26 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -351,7 +351,8 @@ static cputime_t task_utime(struct task_struct *p) } utime = (clock_t)temp; - return clock_t_to_cputime(utime); + p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime)); + return p->prev_utime; } static cputime_t task_stime(struct task_struct *p) @@ -366,7 +367,8 @@ static cputime_t task_stime(struct task_struct *p) stime = nsec_to_clock_t(p->se.sum_exec_runtime) - cputime_to_clock_t(task_utime(p)); - return clock_t_to_cputime(stime); + p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime)); + return p->prev_stime; } #endif diff --git a/include/linux/sched.h b/include/linux/sched.h index 313c6b6e774f8..f509fbd97df97 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1022,6 +1022,7 @@ struct task_struct { unsigned int rt_priority; cputime_t utime, stime; + cputime_t prev_utime, prev_stime; unsigned long nvcsw, nivcsw; /* context switch counts */ struct timespec start_time; /* monotonic time */ struct timespec real_start_time; /* boot based time */ diff --git a/kernel/fork.c b/kernel/fork.c index 33f12f48684a0..f299d4522a2d1 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1045,6 +1045,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, p->utime = cputime_zero; p->stime = cputime_zero; + p->prev_utime = cputime_zero; + p->prev_stime = cputime_zero; #ifdef CONFIG_TASK_XACCT p->rchar = 0; /* I/O counter: bytes read */