Skip to content

Commit

Permalink
sched: fix prev_stime calculation
Browse files Browse the repository at this point in the history
Srivatsa Vaddagiri noticed occasionally incorrect CPU usage
values in top and tracked it down to stime going below 0 in
task_stime(). Negative values are possible there due to the
sampled nature of stime/utime.

Fix suggested by Balbir Singh.

Signed-off-by: Ingo Molnar <[email protected]>
Tested-by: Srivatsa Vaddagiri <[email protected]>
Reviewed-by: Balbir Singh <[email protected]>
  • Loading branch information
Ingo Molnar committed Nov 26, 2007
1 parent 5e8869b commit 08e4570
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/proc/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ 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));

p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime));
if (stime >= 0)
p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime));

return p->prev_stime;
}
#endif
Expand Down

0 comments on commit 08e4570

Please sign in to comment.