summaryrefslogtreecommitdiff
path: root/fs/proc/array.c
diff options
context:
space:
mode:
authorLev Makhlis <lev_makhlis@bmc.com>2004-10-18 08:54:26 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-10-18 08:54:26 -0700
commit9a349eb78cdd466f57d963c78b0265d026588a88 (patch)
treea80f8f61b90cd8dda4c5ad2818c370baf443d96a /fs/proc/array.c
parentbf719d26a5c1ebe5ceed46f47bebefa4beae1f34 (diff)
[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: Lev Makhlis <mlev@despammed.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/proc/array.c')
-rw-r--r--fs/proc/array.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 1b4e86c62487..d05dab0697d3 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -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 min_flt = 0, maj_flt = 0, utime = 0, stime = 0;
unsigned long rsslim = 0;
+ struct task_struct *t;
char tcomm[sizeof(task->comm)];
state = *get_task_state(task);
@@ -335,6 +336,19 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
spin_lock_irq(&task->sighand->siglock);
num_threads = atomic_read(&task->signal->count);
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);
}
if (task->signal) {
@@ -350,10 +364,10 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
cstime = task->signal->cstime;
rsslim = task->signal->rlim[RLIMIT_RSS].rlim_cur;
if (whole) {
- min_flt = task->signal->min_flt;
- maj_flt = task->signal->maj_flt;
- utime = task->signal->utime;
- stime = task->signal->stime;
+ min_flt += task->signal->min_flt;
+ maj_flt += task->signal->maj_flt;
+ utime += task->signal->utime;
+ stime += task->signal->stime;
}
}
ppid = task->pid ? task->real_parent->pid : 0;