Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169911
b: refs/heads/master
c: d180c5b
h: refs/heads/master
i:
  169909: 480acd7
  169907: 027c108
  169903: 2ba3f49
v: v3
  • Loading branch information
Hidetoshi Seto authored and Ingo Molnar committed Nov 26, 2009
1 parent 145a24d commit 66874cf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 16bc67edeb49b531940b2ba6c183780a1b5c472d
refs/heads/master: d180c5bccec02612256fd8076ff3c1fac3429553
3 changes: 1 addition & 2 deletions trunk/fs/proc/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
if (!whole) {
min_flt = task->min_flt;
maj_flt = task->maj_flt;
utime = task_utime(task);
stime = task_stime(task);
task_times(task, &utime, &stime);
gtime = task_gtime(task);
}

Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ static inline void put_task_struct(struct task_struct *t)
extern cputime_t task_utime(struct task_struct *p);
extern cputime_t task_stime(struct task_struct *p);
extern cputime_t task_gtime(struct task_struct *p);
extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st);

/*
* Per process flags
Expand Down
7 changes: 5 additions & 2 deletions trunk/kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ static void __exit_signal(struct task_struct *tsk)
if (atomic_dec_and_test(&sig->count))
posix_cpu_timers_exit_group(tsk);
else {
cputime_t utime, stime;

/*
* If there is any task waiting for the group exit
* then notify it:
Expand All @@ -110,8 +112,9 @@ static void __exit_signal(struct task_struct *tsk)
* We won't ever get here for the group leader, since it
* will have been the last reference on the signal_struct.
*/
sig->utime = cputime_add(sig->utime, task_utime(tsk));
sig->stime = cputime_add(sig->stime, task_stime(tsk));
task_times(tsk, &utime, &stime);
sig->utime = cputime_add(sig->utime, utime);
sig->stime = cputime_add(sig->stime, stime);
sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
sig->min_flt += tsk->min_flt;
sig->maj_flt += tsk->maj_flt;
Expand Down
55 changes: 35 additions & 20 deletions trunk/kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -5191,48 +5191,63 @@ cputime_t task_stime(struct task_struct *p)
{
return p->stime;
}

void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
{
if (ut)
*ut = task_utime(p);
if (st)
*st = task_stime(p);
}
#else

#ifndef nsecs_to_cputime
# define nsecs_to_cputime(__nsecs) \
msecs_to_cputime(div_u64((__nsecs), NSEC_PER_MSEC))
#endif

cputime_t task_utime(struct task_struct *p)
void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
{
cputime_t utime = p->utime, total = utime + p->stime;
u64 temp;
cputime_t rtime, utime = p->utime, total = utime + p->stime;

/*
* Use CFS's precise accounting:
*/
temp = (u64)nsecs_to_cputime(p->se.sum_exec_runtime);
rtime = nsecs_to_cputime(p->se.sum_exec_runtime);

if (total) {
temp *= utime;
u64 temp;

temp = (u64)(rtime * utime);
do_div(temp, total);
}
utime = (cputime_t)temp;
utime = (cputime_t)temp;
} else
utime = rtime;

/*
* Compare with previous values, to keep monotonicity:
*/
p->prev_utime = max(p->prev_utime, utime);
return p->prev_utime;
p->prev_stime = max(p->prev_stime, rtime - p->prev_utime);

if (ut)
*ut = p->prev_utime;
if (st)
*st = p->prev_stime;
}

cputime_t task_utime(struct task_struct *p)
{
cputime_t utime;
task_times(p, &utime, NULL);
return utime;
}

cputime_t task_stime(struct task_struct *p)
{
cputime_t stime;

/*
* Use CFS's precise accounting. (we subtract utime from
* the total, to make sure the total observed by userspace
* grows monotonically - apps rely on that):
*/
stime = nsecs_to_cputime(p->se.sum_exec_runtime) - task_utime(p);

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

return p->prev_stime;
task_times(p, NULL, &stime);
return stime;
}
#endif

Expand Down
3 changes: 1 addition & 2 deletions trunk/kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
utime = stime = cputime_zero;

if (who == RUSAGE_THREAD) {
utime = task_utime(current);
stime = task_stime(current);
task_times(current, &utime, &stime);
accumulate_thread_rusage(p, r);
maxrss = p->signal->maxrss;
goto out;
Expand Down

0 comments on commit 66874cf

Please sign in to comment.