LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] RUSAGE_THREAD
@ 2008-02-05 5:55 Sripathi Kodi
2008-02-22 17:43 ` Michael Kerrisk
0 siblings, 1 reply; 8+ messages in thread
From: Sripathi Kodi @ 2008-02-05 5:55 UTC (permalink / raw)
To: Andrew Morton
Cc: Roland McGrath, linux-kernel, mtk.manpages, torvalds, vinay, drpeper
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);
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
2008-02-05 5:55 [PATCH] RUSAGE_THREAD Sripathi Kodi
@ 2008-02-22 17:43 ` Michael Kerrisk
2008-02-27 11:41 ` Sripathi Kodi
0 siblings, 1 reply; 8+ messages in thread
From: Michael Kerrisk @ 2008-02-22 17:43 UTC (permalink / raw)
To: Sripathi Kodi
Cc: Andrew Morton, Roland McGrath, linux-kernel, torvalds, vinay, drpeper
Sripathi Kodi wrote:
> 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.
Sripathi,
Could you write some small piece of text for the getrusage.2 man page that
describes the intended behavior of RUSAGE_THREAD?
Thanks,
Michael
--
Michael Kerrisk
Maintainer of the Linux man-pages project
http://www.kernel.org/doc/man-pages/
Want to report a man-pages bug? Look here:
http://www.kernel.org/doc/man-pages/reporting_bugs.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
2008-02-22 17:43 ` Michael Kerrisk
@ 2008-02-27 11:41 ` Sripathi Kodi
2008-03-10 15:33 ` Michael Kerrisk
0 siblings, 1 reply; 8+ messages in thread
From: Sripathi Kodi @ 2008-02-27 11:41 UTC (permalink / raw)
To: Michael Kerrisk
Cc: Andrew Morton, Roland McGrath, linux-kernel, torvalds, vinay, drepper
On Friday 22 February 2008 23:13, Michael Kerrisk wrote:
> Sripathi Kodi wrote:
> > 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.
>
> Sripathi,
>
> Could you write some small piece of text for the getrusage.2 man page
> that describes the intended behavior of RUSAGE_THREAD?
Michael,
Please take a look at the following patch to getrusage.2. This is the first
time I have edited a manpage, so I hope I have done it correctly!
Also, the RUSAGE_THREAD patch is currently in -mm, but not in mainline
yet. Hoping that it will make it, I have put a line in the patch that it is
supported from 2.6.25 onwards.
Thanks,
Sripathi.
PS: I fixed spelling error in Ulrich's mail id in the CC list.
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
--- getrusage.2.org 2008-02-27 17:00:57.000000000 +0530
+++ getrusage.2 2008-02-27 17:01:28.000000000 +0530
@@ -44,12 +44,22 @@ getrusage \- get resource usage
.PP
.BR getrusage ()
returns current resource usages, for a \fIwho\fP
-of either
+of
+.B RUSAGE_THREAD,
.B RUSAGE_SELF
or
.BR RUSAGE_CHILDREN .
-The former asks for resources used by the current process,
-the latter for resources used by those of its children
+.PP
+.B RUSAGE_THREAD
+asks for resources used by the calling thread.
+.PP
+.B RUSAGE_SELF
+asks for resources used by the current process,
+which is the sum of resources used by all threads
+in the process.
+.PP
+.B RUSAGE_CHILDREN
+asks for resources used by those of its children
that have terminated and have been waited for.
.PP
.in +0.5i
@@ -130,6 +140,9 @@ Since Linux 2.6,
and
.I ru_nivcsw
are also maintained.
+.PP
+.B RUSAGE_THREAD
+is supported only in Linux kernel versions 2.6.25 and above.
.SH "SEE ALSO"
.BR getrlimit (2),
.BR times (2),
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
2008-02-27 11:41 ` Sripathi Kodi
@ 2008-03-10 15:33 ` Michael Kerrisk
0 siblings, 0 replies; 8+ messages in thread
From: Michael Kerrisk @ 2008-03-10 15:33 UTC (permalink / raw)
To: Sripathi Kodi
Cc: Michael Kerrisk, Andrew Morton, Roland McGrath, linux-kernel,
torvalds, vinay, drepper
Sripathi Kodi wrote:
> On Friday 22 February 2008 23:13, Michael Kerrisk wrote:
>> Sripathi Kodi wrote:
>>> 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.
>> Sripathi,
>>
>> Could you write some small piece of text for the getrusage.2 man page
>> that describes the intended behavior of RUSAGE_THREAD?
>
> Michael,
>
> Please take a look at the following patch to getrusage.2. This is the first
> time I have edited a manpage, so I hope I have done it correctly!
>
> Also, the RUSAGE_THREAD patch is currently in -mm, but not in mainline
> yet. Hoping that it will make it, I have put a line in the patch that it is
> supported from 2.6.25 onwards.
Sripathi,
Thanks for the patch -- looks reasonable to me.
I see that RUSAGE_THREAD didin't make the cut for 2.6.25. If you remember,
could you ping me when it does hit mainline.
Cheers,
Michael
> PS: I fixed spelling error in Ulrich's mail id in the CC list.
>
> Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
>
> --- getrusage.2.org 2008-02-27 17:00:57.000000000 +0530
> +++ getrusage.2 2008-02-27 17:01:28.000000000 +0530
> @@ -44,12 +44,22 @@ getrusage \- get resource usage
> .PP
> .BR getrusage ()
> returns current resource usages, for a \fIwho\fP
> -of either
> +of
> +.B RUSAGE_THREAD,
> .B RUSAGE_SELF
> or
> .BR RUSAGE_CHILDREN .
> -The former asks for resources used by the current process,
> -the latter for resources used by those of its children
> +.PP
> +.B RUSAGE_THREAD
> +asks for resources used by the calling thread.
> +.PP
> +.B RUSAGE_SELF
> +asks for resources used by the current process,
> +which is the sum of resources used by all threads
> +in the process.
> +.PP
> +.B RUSAGE_CHILDREN
> +asks for resources used by those of its children
> that have terminated and have been waited for.
> .PP
> .in +0.5i
> @@ -130,6 +140,9 @@ Since Linux 2.6,
> and
> .I ru_nivcsw
> are also maintained.
> +.PP
> +.B RUSAGE_THREAD
> +is supported only in Linux kernel versions 2.6.25 and above.
> .SH "SEE ALSO"
> .BR getrlimit (2),
> .BR times (2),
>
--
Michael Kerrisk
Maintainer of the Linux man-pages project
http://www.kernel.org/doc/man-pages/
Want to report a man-pages bug? Look here:
http://www.kernel.org/doc/man-pages/reporting_bugs.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
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
2 siblings, 0 replies; 8+ messages in thread
From: Michael Kerrisk @ 2008-01-26 7:23 UTC (permalink / raw)
To: Roland McGrath
Cc: Linus Torvalds, Andrew Morton, Vinay Sridhar, Ulrich Drepper,
linux-kernel
On Jan 19, 2008 2:14 AM, Roland McGrath <roland@redhat.com> wrote:
>
> This adds the RUSAGE_THREAD option for the getrusage system call.
> Solaris calls this RUSAGE_LWP and uses the same value (1).
> That name is not a natural one for Linux, but we keep it as an alias.
Hey Roland,
Would you please CC at this address me on patches that change the
kernel-userland API.
Cheers,
Michael
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
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
2 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2008-01-21 9:55 UTC (permalink / raw)
To: Roland McGrath
Cc: Linus Torvalds, Andrew Morton, Vinay Sridhar, Ulrich Drepper,
linux-kernel
On Fri, Jan 18, 2008 at 05:14:18PM -0800, Roland McGrath wrote:
> +#define RUSAGE_LWP RUSAGE_THREAD /* Solaris name for same */
Please don't add this to the kernel header. If glibc really wants that
it can provide it in it's own headers.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] RUSAGE_THREAD
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
2 siblings, 0 replies; 8+ messages in thread
From: Ulrich Drepper @ 2008-01-19 6:21 UTC (permalink / raw)
To: Roland McGrath; +Cc: Linus Torvalds, Andrew Morton, Vinay Sridhar, linux-kernel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Roland McGrath wrote:
> +#define RUSAGE_LWP RUSAGE_THREAD /* Solaris name for same */
No need to clutter the kernel header with this, it'll be in the libc header.
Aside from that:
Acked-by: Ulrich Drepper <drpeper@redhat.com>
- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFHkZbk2ijCOnn/RHQRAtohAKCyWgJsm20LSqxTznvff3LI8zplvgCgwttu
16eJFNgQXWNEk76b141uZvo=
=DzhA
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] RUSAGE_THREAD
2008-01-17 8:27 [RFC] Per-thread getrusage Vinay Sridhar
@ 2008-01-19 1:14 ` Roland McGrath
2008-01-19 6:21 ` Ulrich Drepper
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Roland McGrath @ 2008-01-19 1:14 UTC (permalink / raw)
To: Linus Torvalds, Andrew Morton; +Cc: Vinay Sridhar, Ulrich Drepper, linux-kernel
This adds the RUSAGE_THREAD option for the getrusage system call.
Solaris calls this RUSAGE_LWP and uses the same value (1).
That name is not a natural one for Linux, but we keep it as an alias.
Signed-off-by: Roland McGrath <roland@redhat.com>
---
include/linux/resource.h | 2 ++
kernel/sys.c | 31 ++++++++++++++++++++++---------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/include/linux/resource.h b/include/linux/resource.h
index ae13db7..02b3377 100644
--- a/include/linux/resource.h
+++ b/include/linux/resource.h
@@ -19,6 +19,8 @@ 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 */
+#define RUSAGE_LWP RUSAGE_THREAD /* Solaris name for same */
struct rusage {
struct timeval ru_utime; /* user time used */
diff --git a/kernel/sys.c b/kernel/sys.c
index d1fe71e..6a62bc4 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -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_struct *p, int who, struct rusage *r)
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_struct *p, int who, struct rusage *r)
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_struct *p, int who, struct rusage *r)
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 who, struct rusage __user *ru)
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] 8+ messages in thread
end of thread, other threads:[~2008-03-10 15:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-05 5:55 [PATCH] RUSAGE_THREAD Sripathi Kodi
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
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).