per-thread rusage

From: William Lee Irwin III
Date: Wed Apr 04 2007 - 13:29:35 EST


It is not now possible for a thread to retrieve its own rusage in
isolation. Its rusage is nowhere exposed without being intermixed with
that of its sibling threads. This patch adds support for an
RUSAGE_THREAD who argument that returns rusage for only the desired
thread.

Untested.


-- wli


Index: anon/include/linux/resource.h
===================================================================
--- anon.orig/include/linux/resource.h 2007-04-04 09:57:41.239118534 -0700
+++ anon/include/linux/resource.h 2007-04-04 09:57:59.840178548 -0700
@@ -18,7 +18,8 @@
*/
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN (-1)
-#define RUSAGE_BOTH (-2) /* sys_wait4() uses this */
+#define RUSAGE_THREAD (-2)
+#define RUSAGE_BOTH (-3) /* sys_wait4() uses this */

struct rusage {
struct timeval ru_utime; /* user time used */
Index: anon/kernel/sys.c
===================================================================
--- anon.orig/kernel/sys.c 2007-04-04 09:58:03.964413575 -0700
+++ anon/kernel/sys.c 2007-04-04 10:11:22.417914846 -0700
@@ -2013,6 +2013,14 @@
}

switch (who) {
+ case RUSAGE_THREAD:
+ utime = p->utime;
+ stime = p->stime;
+ r->ru_nvcsw = p->nvcsw;
+ r->ru_nivcsw = p->nivcsw;
+ r->ru_minflt = p->min_flt;
+ r->ru_majflt = p->maj_flt;
+ break;
case RUSAGE_BOTH:
case RUSAGE_CHILDREN:
utime = p->signal->cutime;
@@ -2064,7 +2072,8 @@

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);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/