public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* per-thread rusage
@ 2007-04-04 17:29 William Lee Irwin III
  2007-04-04 17:48 ` Eric Dumazet
  2007-04-04 22:36 ` Valdis.Kletnieks
  0 siblings, 2 replies; 24+ messages in thread
From: William Lee Irwin III @ 2007-04-04 17:29 UTC (permalink / raw)
  To: linux-kernel

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);
 }

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: per-thread rusage
@ 2007-04-10 20:10 Oleg Nesterov
  0 siblings, 0 replies; 24+ messages in thread
From: Oleg Nesterov @ 2007-04-10 20:10 UTC (permalink / raw)
  To: wli; +Cc: Eric Dumazet, Andrew Morton, linux-kernel

William Lee Irwin III <wli@holomorphy.com> wrote:
>
>  	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;
> +			r->ru_inblock = task_io_get_inblock(p);
> +			r->ru_oublock = task_io_get_oublock(p);
> +			break;

Minor nit. Perhaps it makes sense to introduce

	static void rusage_self(struct rusage *r, struct task_struct *p);

for that. Could be re-used by "do {} while ()" below. Of course, we need
s/=/+=/.

Or, if we think the kernel code is too much clean,

	--- kernel/sys.c~	2007-04-05 12:20:35.000000000 +0400
	+++ kernel/sys.c	2007-04-11 00:08:53.000000000 +0400
	@@ -2097,6 +2097,7 @@ static void k_getrusage(struct task_stru
				r->ru_majflt += p->signal->maj_flt;
				r->ru_inblock += p->signal->inblock;
				r->ru_oublock += p->signal->oublock;
	+		case RUSAGE_THREAD:
				t = p;
				do {
					utime = cputime_add(utime, t->utime);
	@@ -2107,7 +2108,9 @@ static void k_getrusage(struct task_stru
					r->ru_majflt += t->maj_flt;
					r->ru_inblock += task_io_get_inblock(t);
					r->ru_oublock += task_io_get_oublock(t);
	-				t = next_thread(t);
	+
	+				if (who != RUSAGE_THREAD)
	+					t = next_thread(t);
				} while (t != p);
				break;
	 

Oleg.


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2007-05-02  5:05 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-04 17:29 per-thread rusage William Lee Irwin III
2007-04-04 17:48 ` Eric Dumazet
2007-04-04 18:10   ` William Lee Irwin III
2007-04-09 23:53     ` Andrew Morton
2007-04-10  0:42       ` William Lee Irwin III
2007-04-10  0:53         ` Andrew Morton
2007-04-10  1:12           ` William Lee Irwin III
2007-04-10  1:18             ` Andrew Morton
2007-05-01 17:29         ` Bill Irwin
2007-05-01 18:39           ` Ulrich Drepper
2007-05-01 20:24             ` Bill Irwin
2007-05-01 22:10               ` Ulrich Drepper
2007-05-01 22:27                 ` Theodore Tso
2007-05-01 22:34                   ` Bill Irwin
2007-05-01 23:04                     ` Alan Cox
2007-05-01 23:17                       ` Bill Irwin
2007-05-02  5:05                       ` Balbir Singh
2007-05-02  0:17                   ` Ulrich Drepper
2007-05-02  4:31                     ` Theodore Tso
2007-05-02  4:57                       ` Ulrich Drepper
2007-05-01 22:29                 ` Bill Irwin
2007-04-04 22:36 ` Valdis.Kletnieks
2007-04-05  4:09   ` William Lee Irwin III
  -- strict thread matches above, loose matches on Subject: below --
2007-04-10 20:10 Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox