Skip to content

Commit

Permalink
sched: keep utime/stime monotonic
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Oct 29, 2007
1 parent f7402e0 commit 73a2bcb
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/proc/array.c
Original file line number Diff line number Diff line change
@@ -358,7 +358,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)
1 change: 1 addition & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
@@ -1009,6 +1009,7 @@ struct task_struct {
unsigned int rt_priority;
cputime_t utime, stime, utimescaled, stimescaled;
cputime_t gtime;
cputime_t prev_utime;
unsigned long nvcsw, nivcsw; /* context switch counts */
struct timespec start_time; /* monotonic time */
struct timespec real_start_time; /* boot based time */
1 change: 1 addition & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
@@ -1056,6 +1056,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
p->gtime = cputime_zero;
p->utimescaled = cputime_zero;
p->stimescaled = cputime_zero;
p->prev_utime = cputime_zero;

#ifdef CONFIG_TASK_XACCT
p->rchar = 0; /* I/O counter: bytes read */

0 comments on commit 73a2bcb

Please sign in to comment.