Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Move rusage computation to a new getrusage1() function. ...
details: https://anonhg.NetBSD.org/src/rev/b88596674ac0
branches: trunk
changeset: 782471:b88596674ac0
user: njoly <njoly%NetBSD.org@localhost>
date: Sat Nov 03 23:22:21 2012 +0000
description:
Move rusage computation to a new getrusage1() function. Adjust all
compat/emulations to make use of it.
diffstat:
sys/compat/common/kern_time_50.c | 24 ++++++------------------
sys/compat/netbsd32/netbsd32_compat_50.c | 31 ++++++++++---------------------
sys/compat/netbsd32/netbsd32_wait.c | 31 ++++++++++---------------------
sys/compat/osf1/osf1_resource.c | 19 ++++++++++---------
sys/kern/kern_resource.c | 29 +++++++++++++++++++----------
sys/sys/resourcevar.h | 4 +++-
6 files changed, 58 insertions(+), 80 deletions(-)
diffs (297 lines):
diff -r adceb0e3fa0e -r b88596674ac0 sys/compat/common/kern_time_50.c
--- a/sys/compat/common/kern_time_50.c Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/compat/common/kern_time_50.c Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_time_50.c,v 1.23 2012/10/02 01:44:27 christos Exp $ */
+/* $NetBSD: kern_time_50.c,v 1.24 2012/11/03 23:22:21 njoly Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.23 2012/10/02 01:44:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.24 2012/11/03 23:22:21 njoly Exp $");
#ifdef _KERNEL_OPT
#include "opt_aio.h"
@@ -509,27 +509,15 @@
syscallarg(int) who;
syscallarg(struct rusage50 *) rusage;
} */
+ int error;
struct rusage ru;
struct rusage50 ru50;
struct proc *p = l->l_proc;
- switch (SCARG(uap, who)) {
- case RUSAGE_SELF:
- mutex_enter(p->p_lock);
- memcpy(&ru, &p->p_stats->p_ru, sizeof(ru));
- calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL);
- mutex_exit(p->p_lock);
- break;
+ error = getrusage1(p, SCARG(uap, who), &ru);
+ if (error != 0)
+ return error;
- case RUSAGE_CHILDREN:
- mutex_enter(p->p_lock);
- memcpy(&ru, &p->p_stats->p_cru, sizeof(ru));
- mutex_exit(p->p_lock);
- break;
-
- default:
- return EINVAL;
- }
rusage_to_rusage50(&ru, &ru50);
return copyout(&ru50, SCARG(uap, rusage), sizeof(ru50));
}
diff -r adceb0e3fa0e -r b88596674ac0 sys/compat/netbsd32/netbsd32_compat_50.c
--- a/sys/compat/netbsd32/netbsd32_compat_50.c Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_50.c Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_compat_50.c,v 1.21 2012/10/02 01:44:28 christos Exp $ */
+/* $NetBSD: netbsd32_compat_50.c,v 1.22 2012/11/03 23:22:22 njoly Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.21 2012/10/02 01:44:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.22 2012/11/03 23:22:22 njoly Exp $");
#if defined(_KERNEL_OPT)
#include "opt_sysv.h"
@@ -840,28 +840,17 @@
syscallarg(int) who;
syscallarg(netbsd32_rusage50p_t) rusage;
} */
+ int error;
struct proc *p = l->l_proc;
- struct rusage *rup;
- struct netbsd32_rusage50 ru;
-
- switch (SCARG(uap, who)) {
+ struct rusage ru;
+ struct netbsd32_rusage50 ru32;
- case RUSAGE_SELF:
- rup = &p->p_stats->p_ru;
- mutex_enter(p->p_lock);
- calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
- mutex_exit(p->p_lock);
- break;
+ error = getrusage1(p, SCARG(uap, who), &ru);
+ if (error != 0)
+ return error;
- case RUSAGE_CHILDREN:
- rup = &p->p_stats->p_cru;
- break;
-
- default:
- return (EINVAL);
- }
- netbsd32_from_rusage50(rup, &ru);
- return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
+ netbsd32_from_rusage50(&ru, &ru32);
+ return copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
}
int
diff -r adceb0e3fa0e -r b88596674ac0 sys/compat/netbsd32/netbsd32_wait.c
--- a/sys/compat/netbsd32/netbsd32_wait.c Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/compat/netbsd32/netbsd32_wait.c Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_wait.c,v 1.21 2009/11/04 21:23:03 rmind Exp $ */
+/* $NetBSD: netbsd32_wait.c,v 1.22 2012/11/03 23:22:22 njoly Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.21 2009/11/04 21:23:03 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.22 2012/11/03 23:22:22 njoly Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -86,26 +86,15 @@
syscallarg(int) who;
syscallarg(netbsd32_rusagep_t) rusage;
} */
+ int error;
struct proc *p = l->l_proc;
- struct rusage *rup;
- struct netbsd32_rusage ru;
-
- switch (SCARG(uap, who)) {
+ struct rusage ru;
+ struct netbsd32_rusage ru32;
- case RUSAGE_SELF:
- rup = &p->p_stats->p_ru;
- mutex_enter(p->p_lock);
- calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
- mutex_exit(p->p_lock);
- break;
+ error = getrusage1(p, SCARG(uap, who), &ru);
+ if (error != 0)
+ return error;
- case RUSAGE_CHILDREN:
- rup = &p->p_stats->p_cru;
- break;
-
- default:
- return (EINVAL);
- }
- netbsd32_from_rusage(rup, &ru);
- return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
+ netbsd32_from_rusage(&ru, &ru32);
+ return copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
}
diff -r adceb0e3fa0e -r b88596674ac0 sys/compat/osf1/osf1_resource.c
--- a/sys/compat/osf1/osf1_resource.c Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/compat/osf1/osf1_resource.c Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: osf1_resource.c,v 1.14 2009/03/29 01:02:50 mrg Exp $ */
+/* $NetBSD: osf1_resource.c,v 1.15 2012/11/03 23:22:22 njoly Exp $ */
/*
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: osf1_resource.c,v 1.14 2009/03/29 01:02:50 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: osf1_resource.c,v 1.15 2012/11/03 23:22:22 njoly Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -88,6 +88,7 @@
int
osf1_sys_getrusage(struct lwp *l, const struct osf1_sys_getrusage_args *uap, register_t *retval)
{
+ int error, who;
struct osf1_rusage osf1_rusage;
struct rusage ru;
struct proc *p = l->l_proc;
@@ -95,22 +96,22 @@
switch (SCARG(uap, who)) {
case OSF1_RUSAGE_SELF:
- mutex_enter(p->p_lock);
- ru = p->p_stats->p_ru;
- calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL);
- rulwps(p, &ru);
- mutex_exit(p->p_lock);
+ who = RUSAGE_SELF;
break;
case OSF1_RUSAGE_CHILDREN:
- ru = p->p_stats->p_cru;
+ who = RUSAGE_CHILDREN;
break;
case OSF1_RUSAGE_THREAD: /* XXX not supported */
default:
- return (EINVAL);
+ return EINVAL;
}
+ error = getrusage1(p, who, &ru);
+ if (error != 0)
+ return error;
+
osf1_cvt_rusage_from_native(&ru, &osf1_rusage);
return copyout(&osf1_rusage, SCARG(uap, rusage), sizeof osf1_rusage);
diff -r adceb0e3fa0e -r b88596674ac0 sys/kern/kern_resource.c
--- a/sys/kern/kern_resource.c Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/kern/kern_resource.c Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_resource.c,v 1.169 2012/06/09 02:31:15 christos Exp $ */
+/* $NetBSD: kern_resource.c,v 1.170 2012/11/03 23:22:22 njoly Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.169 2012/06/09 02:31:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.170 2012/11/03 23:22:22 njoly Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -558,29 +558,38 @@
syscallarg(int) who;
syscallarg(struct rusage *) rusage;
} */
+ int error;
struct rusage ru;
struct proc *p = l->l_proc;
- switch (SCARG(uap, who)) {
+ error = getrusage1(p, SCARG(uap, who), &ru);
+ if (error != 0)
+ return error;
+
+ return copyout(&ru, SCARG(uap, rusage), sizeof(ru));
+}
+
+int
+getrusage1(struct proc *p, int who, struct rusage *ru) {
+
+ switch (who) {
case RUSAGE_SELF:
mutex_enter(p->p_lock);
- memcpy(&ru, &p->p_stats->p_ru, sizeof(ru));
- calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL);
- rulwps(p, &ru);
+ memcpy(ru, &p->p_stats->p_ru, sizeof(*ru));
+ calcru(p, &ru->ru_utime, &ru->ru_stime, NULL, NULL);
+ rulwps(p, ru);
mutex_exit(p->p_lock);
break;
-
case RUSAGE_CHILDREN:
mutex_enter(p->p_lock);
- memcpy(&ru, &p->p_stats->p_cru, sizeof(ru));
+ memcpy(ru, &p->p_stats->p_cru, sizeof(*ru));
mutex_exit(p->p_lock);
break;
-
default:
return EINVAL;
}
- return copyout(&ru, SCARG(uap, rusage), sizeof(ru));
+ return 0;
}
void
diff -r adceb0e3fa0e -r b88596674ac0 sys/sys/resourcevar.h
--- a/sys/sys/resourcevar.h Sat Nov 03 19:39:21 2012 +0000
+++ b/sys/sys/resourcevar.h Sat Nov 03 23:22:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: resourcevar.h,v 1.53 2011/06/03 17:58:18 rmind Exp $ */
+/* $NetBSD: resourcevar.h,v 1.54 2012/11/03 23:22:22 njoly Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -120,6 +120,8 @@
extern rlim_t maxdmap;
extern rlim_t maxsmap;
+int getrusage1(struct proc *, int, struct rusage *);
+
#endif
#endif /* !_SYS_RESOURCEVAR_H_ */
Home |
Main Index |
Thread Index |
Old Index