]> git.hungrycats.org Git - linux/commitdiff
[PATCH] show aggregate per-process counters in /proc/PID/stat 2
authorLev Makhlis <lev_makhlis@bmc.com>
Mon, 18 Oct 2004 15:54:26 +0000 (08:54 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 18 Oct 2004 15:54:26 +0000 (08:54 -0700)
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>
fs/proc/array.c

index 1b4e86c62487f6108eba5ed3edd2130c458c6480..d05dab0697d318f6c34b8ab0fbd9ac1d564e9ae8 100644 (file)
@@ -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;