Commit 9a349eb7 authored by Lev Makhlis's avatar Lev Makhlis Committed by Linus Torvalds

[PATCH] show aggregate per-process counters in /proc/PID/stat 2

Add up resource usage counters for live and dead threads to show aggregate
per-process usage in /proc/<pid>/stat.  This mirrors the new getrusage()
semantics.  /proc/<pid>/task/<tid>/stat still has the per-thread usage.

After moving the counter aggregation loop inside a task->sighand lock to
avoid nasty race conditions, it has survived stress-testing with '(while
true; do sleep 1 & done) & top -d 0.1'
Signed-off-by: default avatarLev Makhlis <mlev@despammed.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent bf719d26
...@@ -315,6 +315,7 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole) ...@@ -315,6 +315,7 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
unsigned long cmin_flt = 0, cmaj_flt = 0, cutime = 0, cstime = 0; unsigned long cmin_flt = 0, cmaj_flt = 0, cutime = 0, cstime = 0;
unsigned long min_flt = 0, maj_flt = 0, utime = 0, stime = 0; unsigned long min_flt = 0, maj_flt = 0, utime = 0, stime = 0;
unsigned long rsslim = 0; unsigned long rsslim = 0;
struct task_struct *t;
char tcomm[sizeof(task->comm)]; char tcomm[sizeof(task->comm)];
state = *get_task_state(task); state = *get_task_state(task);
...@@ -335,6 +336,19 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole) ...@@ -335,6 +336,19 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
spin_lock_irq(&task->sighand->siglock); spin_lock_irq(&task->sighand->siglock);
num_threads = atomic_read(&task->signal->count); num_threads = atomic_read(&task->signal->count);
collect_sigign_sigcatch(task, &sigign, &sigcatch); collect_sigign_sigcatch(task, &sigign, &sigcatch);
/* add up live thread stats at the group level */
if (whole) {
t = task;
do {
min_flt += t->min_flt;
maj_flt += t->maj_flt;
utime += t->utime;
stime += t->stime;
t = next_thread(t);
} while (t != task);
}
spin_unlock_irq(&task->sighand->siglock); spin_unlock_irq(&task->sighand->siglock);
} }
if (task->signal) { if (task->signal) {
...@@ -350,10 +364,10 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole) ...@@ -350,10 +364,10 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
cstime = task->signal->cstime; cstime = task->signal->cstime;
rsslim = task->signal->rlim[RLIMIT_RSS].rlim_cur; rsslim = task->signal->rlim[RLIMIT_RSS].rlim_cur;
if (whole) { if (whole) {
min_flt = task->signal->min_flt; min_flt += task->signal->min_flt;
maj_flt = task->signal->maj_flt; maj_flt += task->signal->maj_flt;
utime = task->signal->utime; utime += task->signal->utime;
stime = task->signal->stime; stime += task->signal->stime;
} }
} }
ppid = task->pid ? task->real_parent->pid : 0; ppid = task->pid ? task->real_parent->pid : 0;
......
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