diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2006-01-08 04:05:15 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:14:09 -0500 |
commit | 0f59cc4a35dbbc45c972daad0f1b063380cd9ea4 (patch) | |
tree | 03cb2e69303e2ea3cca0f7eca6c7eb6c5a352e40 | |
parent | 86f91d36c2aac910b7cf7e5d047019b10a9a627e (diff) |
[PATCH] simplify k_getrusage()
Factor out common code for different RUSAGE_xxx cases.
Don't take ->sighand->siglock in RUSAGE_SELF case, suggested by Ravikiran G
Thirumalai <kiran@scalex86.org>.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | kernel/sys.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 218937e837dc..b6941e06d5d5 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -1692,7 +1692,10 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1692 | if (unlikely(!p->signal)) | 1692 | if (unlikely(!p->signal)) |
1693 | return; | 1693 | return; |
1694 | 1694 | ||
1695 | utime = stime = cputime_zero; | ||
1696 | |||
1695 | switch (who) { | 1697 | switch (who) { |
1698 | case RUSAGE_BOTH: | ||
1696 | case RUSAGE_CHILDREN: | 1699 | case RUSAGE_CHILDREN: |
1697 | spin_lock_irqsave(&p->sighand->siglock, flags); | 1700 | spin_lock_irqsave(&p->sighand->siglock, flags); |
1698 | utime = p->signal->cutime; | 1701 | utime = p->signal->cutime; |
@@ -1702,22 +1705,11 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1702 | r->ru_minflt = p->signal->cmin_flt; | 1705 | r->ru_minflt = p->signal->cmin_flt; |
1703 | r->ru_majflt = p->signal->cmaj_flt; | 1706 | r->ru_majflt = p->signal->cmaj_flt; |
1704 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 1707 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
1705 | cputime_to_timeval(utime, &r->ru_utime); | 1708 | |
1706 | cputime_to_timeval(stime, &r->ru_stime); | 1709 | if (who == RUSAGE_CHILDREN) |
1707 | break; | 1710 | break; |
1711 | |||
1708 | case RUSAGE_SELF: | 1712 | case RUSAGE_SELF: |
1709 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
1710 | utime = stime = cputime_zero; | ||
1711 | goto sum_group; | ||
1712 | case RUSAGE_BOTH: | ||
1713 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
1714 | utime = p->signal->cutime; | ||
1715 | stime = p->signal->cstime; | ||
1716 | r->ru_nvcsw = p->signal->cnvcsw; | ||
1717 | r->ru_nivcsw = p->signal->cnivcsw; | ||
1718 | r->ru_minflt = p->signal->cmin_flt; | ||
1719 | r->ru_majflt = p->signal->cmaj_flt; | ||
1720 | sum_group: | ||
1721 | utime = cputime_add(utime, p->signal->utime); | 1713 | utime = cputime_add(utime, p->signal->utime); |
1722 | stime = cputime_add(stime, p->signal->stime); | 1714 | stime = cputime_add(stime, p->signal->stime); |
1723 | r->ru_nvcsw += p->signal->nvcsw; | 1715 | r->ru_nvcsw += p->signal->nvcsw; |
@@ -1734,13 +1726,14 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1734 | r->ru_majflt += t->maj_flt; | 1726 | r->ru_majflt += t->maj_flt; |
1735 | t = next_thread(t); | 1727 | t = next_thread(t); |
1736 | } while (t != p); | 1728 | } while (t != p); |
1737 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
1738 | cputime_to_timeval(utime, &r->ru_utime); | ||
1739 | cputime_to_timeval(stime, &r->ru_stime); | ||
1740 | break; | 1729 | break; |
1730 | |||
1741 | default: | 1731 | default: |
1742 | BUG(); | 1732 | BUG(); |
1743 | } | 1733 | } |
1734 | |||
1735 | cputime_to_timeval(utime, &r->ru_utime); | ||
1736 | cputime_to_timeval(stime, &r->ru_stime); | ||
1744 | } | 1737 | } |
1745 | 1738 | ||
1746 | int getrusage(struct task_struct *p, int who, struct rusage __user *ru) | 1739 | int getrusage(struct task_struct *p, int who, struct rusage __user *ru) |