The patch titled
     add RUSAGE_THREAD
has been added to the -mm tree.  Its filename is
     add-rusage_thread.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: add RUSAGE_THREAD
From: Sripathi Kodi <[EMAIL PROTECTED]>

Add the RUSAGE_THREAD option for the getrusage system call.  This is
essentially Roland's patch from http://lkml.org/lkml/2008/1/18/589, but the
line about RUSAGE_LWP line has been removed, as suggested by Ulrich and
Christoph.

Signed-off-by: Roland McGrath <[EMAIL PROTECTED]>
Signed-off-by: Sripathi Kodi <[EMAIL PROTECTED]>
Cc: Ingo Molnar <[EMAIL PROTECTED]>
Cc: Michael Kerrisk <[EMAIL PROTECTED]>
Cc: Ulrich Drepper <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 include/linux/resource.h |    1 +
 kernel/sys.c             |   31 ++++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff -puN include/linux/resource.h~add-rusage_thread include/linux/resource.h
--- a/include/linux/resource.h~add-rusage_thread
+++ a/include/linux/resource.h
@@ -19,6 +19,7 @@ struct task_struct;
 #define        RUSAGE_SELF     0
 #define        RUSAGE_CHILDREN (-1)
 #define RUSAGE_BOTH    (-2)            /* sys_wait4() uses this */
+#define        RUSAGE_THREAD   1               /* only the calling thread */
 
 struct rusage {
        struct timeval ru_utime;        /* user time used */
diff -puN kernel/sys.c~add-rusage_thread kernel/sys.c
--- a/kernel/sys.c~add-rusage_thread
+++ a/kernel/sys.c
@@ -1539,6 +1539,19 @@ out:
  *
  */
 
+static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r,
+                                    cputime_t *utimep, cputime_t *stimep)
+{
+       *utimep = cputime_add(*utimep, t->utime);
+       *stimep = cputime_add(*stimep, t->stime);
+       r->ru_nvcsw += t->nvcsw;
+       r->ru_nivcsw += t->nivcsw;
+       r->ru_minflt += t->min_flt;
+       r->ru_majflt += t->maj_flt;
+       r->ru_inblock += task_io_get_inblock(t);
+       r->ru_oublock += task_io_get_oublock(t);
+}
+
 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
 {
        struct task_struct *t;
@@ -1548,6 +1561,11 @@ static void k_getrusage(struct task_stru
        memset((char *) r, 0, sizeof *r);
        utime = stime = cputime_zero;
 
+       if (who == RUSAGE_THREAD) {
+               accumulate_thread_rusage(p, r, &utime, &stime);
+               goto out;
+       }
+
        rcu_read_lock();
        if (!lock_task_sighand(p, &flags)) {
                rcu_read_unlock();
@@ -1580,14 +1598,7 @@ static void k_getrusage(struct task_stru
                        r->ru_oublock += p->signal->oublock;
                        t = p;
                        do {
-                               utime = cputime_add(utime, t->utime);
-                               stime = cputime_add(stime, t->stime);
-                               r->ru_nvcsw += t->nvcsw;
-                               r->ru_nivcsw += t->nivcsw;
-                               r->ru_minflt += t->min_flt;
-                               r->ru_majflt += t->maj_flt;
-                               r->ru_inblock += task_io_get_inblock(t);
-                               r->ru_oublock += task_io_get_oublock(t);
+                               accumulate_thread_rusage(t, r, &utime, &stime);
                                t = next_thread(t);
                        } while (t != p);
                        break;
@@ -1599,6 +1610,7 @@ static void k_getrusage(struct task_stru
        unlock_task_sighand(p, &flags);
        rcu_read_unlock();
 
+out:
        cputime_to_timeval(utime, &r->ru_utime);
        cputime_to_timeval(stime, &r->ru_stime);
 }
@@ -1612,7 +1624,8 @@ int getrusage(struct task_struct *p, int
 
 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
 {
-       if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
+       if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
+           who != RUSAGE_THREAD)
                return -EINVAL;
        return getrusage(current, who, ru);
 }
_

Patches currently in -mm which might be from [EMAIL PROTECTED] are

add-rusage_thread.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to