summaryrefslogtreecommitdiff
path: root/sys/kern/kern_resource.c
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-07-08 20:02:10 +0000
committerriastradh <riastradh@NetBSD.org>2023-07-08 20:02:10 +0000
commitd731d091e3765a540a7260d6d7f07f517d16f37b (patch)
tree5fd56ff6b7d60bb6f79fb0a8ed4c50614a9b7de9 /sys/kern/kern_resource.c
parent08308a482718716e6a2b2021ec1a01465d36be96 (diff)
clock_gettime(2): Fix CLOCK_PROCESS/THREAD_CPUTIME_ID.
Use same calculation as getrusage, not some ad-hoc arithmetic of internal scheduler parameters that are periodically rewound. PR kern/57512 XXX pullup-8 XXX pullup-9 XXX pullup-10
Diffstat (limited to 'sys/kern/kern_resource.c')
-rw-r--r--sys/kern/kern_resource.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index d4669640d27..05aca1807ff 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_resource.c,v 1.190 2023/07/08 11:42:03 riastradh Exp $ */
+/* $NetBSD: kern_resource.c,v 1.191 2023/07/08 20:02:10 riastradh Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.190 2023/07/08 11:42:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.191 2023/07/08 20:02:10 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -478,6 +478,30 @@ sys_getrlimit(struct lwp *l, const struct sys_getrlimit_args *uap,
return copyout(&rl, SCARG(uap, rlp), sizeof(rl));
}
+void
+addrulwp(struct lwp *l, struct bintime *tm)
+{
+
+ lwp_lock(l);
+ bintime_add(tm, &l->l_rtime);
+ if ((l->l_pflag & LP_RUNNING) != 0 &&
+ (l->l_pflag & (LP_INTR | LP_TIMEINTR)) != LP_INTR) {
+ struct bintime diff;
+ /*
+ * Adjust for the current time slice. This is
+ * actually fairly important since the error
+ * here is on the order of a time quantum,
+ * which is much greater than the sampling
+ * error.
+ */
+ binuptime(&diff);
+ membar_consumer(); /* for softint_dispatch() */
+ bintime_sub(&diff, &l->l_stime);
+ bintime_add(tm, &diff);
+ }
+ lwp_unlock(l);
+}
+
/*
* Transform the running time and tick information in proc p into user,
* system, and interrupt time usage.
@@ -504,24 +528,7 @@ calcru(struct proc *p, struct timeval *up, struct timeval *sp,
tm = p->p_rtime;
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
- lwp_lock(l);
- bintime_add(&tm, &l->l_rtime);
- if ((l->l_pflag & LP_RUNNING) != 0 &&
- (l->l_pflag & (LP_INTR | LP_TIMEINTR)) != LP_INTR) {
- struct bintime diff;
- /*
- * Adjust for the current time slice. This is
- * actually fairly important since the error
- * here is on the order of a time quantum,
- * which is much greater than the sampling
- * error.
- */
- binuptime(&diff);
- membar_consumer(); /* for softint_dispatch() */
- bintime_sub(&diff, &l->l_stime);
- bintime_add(&tm, &diff);
- }
- lwp_unlock(l);
+ addrulwp(l, &tm);
}
tot = st + ut + it;