Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

add RUSAGE_THREAD

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 <roland@redhat.com>
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: Ulrich Drepper <drepper@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Sripathi Kodi and committed by
Linus Torvalds
679c9cd4 e5949050

+23 -9
+1
include/linux/resource.h
··· 19 19 #define RUSAGE_SELF 0 20 20 #define RUSAGE_CHILDREN (-1) 21 21 #define RUSAGE_BOTH (-2) /* sys_wait4() uses this */ 22 + #define RUSAGE_THREAD 1 /* only the calling thread */ 22 23 23 24 struct rusage { 24 25 struct timeval ru_utime; /* user time used */
+22 -9
kernel/sys.c
··· 1545 1545 * 1546 1546 */ 1547 1547 1548 + static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r, 1549 + cputime_t *utimep, cputime_t *stimep) 1550 + { 1551 + *utimep = cputime_add(*utimep, t->utime); 1552 + *stimep = cputime_add(*stimep, t->stime); 1553 + r->ru_nvcsw += t->nvcsw; 1554 + r->ru_nivcsw += t->nivcsw; 1555 + r->ru_minflt += t->min_flt; 1556 + r->ru_majflt += t->maj_flt; 1557 + r->ru_inblock += task_io_get_inblock(t); 1558 + r->ru_oublock += task_io_get_oublock(t); 1559 + } 1560 + 1548 1561 static void k_getrusage(struct task_struct *p, int who, struct rusage *r) 1549 1562 { 1550 1563 struct task_struct *t; ··· 1566 1553 1567 1554 memset((char *) r, 0, sizeof *r); 1568 1555 utime = stime = cputime_zero; 1556 + 1557 + if (who == RUSAGE_THREAD) { 1558 + accumulate_thread_rusage(p, r, &utime, &stime); 1559 + goto out; 1560 + } 1569 1561 1570 1562 rcu_read_lock(); 1571 1563 if (!lock_task_sighand(p, &flags)) { ··· 1604 1586 r->ru_oublock += p->signal->oublock; 1605 1587 t = p; 1606 1588 do { 1607 - utime = cputime_add(utime, t->utime); 1608 - stime = cputime_add(stime, t->stime); 1609 - r->ru_nvcsw += t->nvcsw; 1610 - r->ru_nivcsw += t->nivcsw; 1611 - r->ru_minflt += t->min_flt; 1612 - r->ru_majflt += t->maj_flt; 1613 - r->ru_inblock += task_io_get_inblock(t); 1614 - r->ru_oublock += task_io_get_oublock(t); 1589 + accumulate_thread_rusage(t, r, &utime, &stime); 1615 1590 t = next_thread(t); 1616 1591 } while (t != p); 1617 1592 break; ··· 1616 1605 unlock_task_sighand(p, &flags); 1617 1606 rcu_read_unlock(); 1618 1607 1608 + out: 1619 1609 cputime_to_timeval(utime, &r->ru_utime); 1620 1610 cputime_to_timeval(stime, &r->ru_stime); 1621 1611 } ··· 1630 1618 1631 1619 asmlinkage long sys_getrusage(int who, struct rusage __user *ru) 1632 1620 { 1633 - if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN) 1621 + if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN && 1622 + who != RUSAGE_THREAD) 1634 1623 return -EINVAL; 1635 1624 return getrusage(current, who, ru); 1636 1625 }