LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sripathi Kodi <sripathik@in.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Roland McGrath <roland@redhat.com>,
	linux-kernel@vger.kernel.org, mtk.manpages@gmail.com,
	torvalds@linux-foundation.org, vinay@linux.vnet.ibm.com,
	drpeper@redhat.com
Subject: [PATCH] RUSAGE_THREAD
Date: Tue, 5 Feb 2008 11:25:50 +0530	[thread overview]
Message-ID: <200802051125.50423.sripathik@in.ibm.com> (raw)

Hi Andrew,

This adds 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.

Thanks,
Sripathi.

This adds the RUSAGE_THREAD option for the getrusage system call.

Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
 include/linux/resource.h |    1 +
 kernel/sys.c             |   31 ++++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff -uprN linux-2.6.24_org/include/linux/resource.h linux-2.6.24/include/linux/resource.h
--- linux-2.6.24_org/include/linux/resource.h	2008-02-05 10:13:04.000000000 +0530
+++ linux-2.6.24/include/linux/resource.h	2008-02-05 10:14:59.000000000 +0530
@@ -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 -uprN linux-2.6.24_org/kernel/sys.c linux-2.6.24/kernel/sys.c
--- linux-2.6.24_org/kernel/sys.c	2008-02-05 10:13:02.000000000 +0530
+++ linux-2.6.24/kernel/sys.c	2008-02-05 10:13:21.000000000 +0530
@@ -1554,6 +1554,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;
@@ -1563,6 +1576,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();
@@ -1595,14 +1613,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;
@@ -1614,6 +1625,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);
 }
@@ -1627,7 +1639,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);
 }

             reply	other threads:[~2008-02-05  5:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-05  5:55 Sripathi Kodi [this message]
2008-02-22 17:43 ` Michael Kerrisk
2008-02-27 11:41   ` Sripathi Kodi
2008-03-10 15:33     ` Michael Kerrisk
  -- strict thread matches above, loose matches on Subject: below --
2008-01-17  8:27 [RFC] Per-thread getrusage Vinay Sridhar
2008-01-19  1:14 ` [PATCH] RUSAGE_THREAD Roland McGrath
2008-01-19  6:21   ` Ulrich Drepper
2008-01-21  9:55   ` Christoph Hellwig
2008-01-26  7:23   ` Michael Kerrisk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802051125.50423.sripathik@in.ibm.com \
    --to=sripathik@in.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=drpeper@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=roland@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vinay@linux.vnet.ibm.com \
    --subject='Re: [PATCH] RUSAGE_THREAD' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).