Module Name: src
Committed By: kre
Date: Wed May 9 19:55:35 UTC 2018
Modified Files:
src/sys/kern: kern_resource.c
src/sys/sys: param.h proc.h
Log Message:
Cause a process's user and system times to become non-decreasing.
This alters the invented values (ie: statistically calculated)
that are returned - for small values, the values are likely going to
be different than they were, but that's largely nonsense anyway
(except that the sum of utime & stime does equal cpu time consumed
by the process). Once the values get large enough to be meaningful
the difference made by this change will be in the noise, and irrelevant.
This needs a couple of additions to struct proc, so we are now into 8.99.17
To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.561 -r1.562 src/sys/sys/param.h
cvs rdiff -u -r1.347 -r1.348 src/sys/sys/proc.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/kern_resource.c
diff -u src/sys/kern/kern_resource.c:1.179 src/sys/kern/kern_resource.c:1.180
--- src/sys/kern/kern_resource.c:1.179 Tue May 8 19:34:54 2018
+++ src/sys/kern/kern_resource.c Wed May 9 19:55:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_resource.c,v 1.179 2018/05/08 19:34:54 christos Exp $ */
+/* $NetBSD: kern_resource.c,v 1.180 2018/05/09 19:55:35 kre Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.179 2018/05/08 19:34:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.180 2018/05/09 19:55:35 kre Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -533,16 +533,41 @@ calcru(struct proc *p, struct timeval *u
st = (u * st) / tot;
ut = (u * ut) / tot;
}
+
+ /*
+ * Try to avoid lying to the users (too much)
+ *
+ * Of course, user/sys time are based on sampling (ie: statistics)
+ * so that would be impossible, but convincing the mark
+ * that we have used less ?time this call than we had
+ * last time, is beyond reasonable... (the con fails!)
+ *
+ * Note that since actual used time cannot decrease, either
+ * utime or stime (or both) must be greater now than last time
+ * (or both the same) - if one seems to have decreased, hold
+ * it constant and steal the necessary bump from the other
+ * which must have increased.
+ */
+ if (p->p_xutime > ut) {
+ st -= p->p_xutime - ut;
+ ut = p->p_xutime;
+ } else if (p->p_xstime > st) {
+ ut -= p->p_xstime - st;
+ st = p->p_xstime;
+ }
+
if (sp != NULL) {
+ p->p_xstime = st;
sp->tv_sec = st / 1000000;
sp->tv_usec = st % 1000000;
}
if (up != NULL) {
+ p->p_xutime = ut;
up->tv_sec = ut / 1000000;
up->tv_usec = ut % 1000000;
}
if (ip != NULL) {
- if (it != 0)
+ if (it != 0) /* it != 0 --> tot != 0 */
it = (u * it) / tot;
ip->tv_sec = it / 1000000;
ip->tv_usec = it % 1000000;
Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.561 src/sys/sys/param.h:1.562
--- src/sys/sys/param.h:1.561 Sun May 6 13:40:52 2018
+++ src/sys/sys/param.h Wed May 9 19:55:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.561 2018/05/06 13:40:52 kamil Exp $ */
+/* $NetBSD: param.h,v 1.562 2018/05/09 19:55:35 kre Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
* 2.99.9 (299000900)
*/
-#define __NetBSD_Version__ 899001600 /* NetBSD 8.99.16 */
+#define __NetBSD_Version__ 899001700 /* NetBSD 8.99.17 */
#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
(m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
Index: src/sys/sys/proc.h
diff -u src/sys/sys/proc.h:1.347 src/sys/sys/proc.h:1.348
--- src/sys/sys/proc.h:1.347 Sun May 6 13:40:52 2018
+++ src/sys/sys/proc.h Wed May 9 19:55:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.347 2018/05/06 13:40:52 kamil Exp $ */
+/* $NetBSD: proc.h,v 1.348 2018/05/09 19:55:35 kre Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -293,6 +293,8 @@ struct proc {
u_quad_t p_uticks; /* t: Statclock hits in user mode */
u_quad_t p_sticks; /* t: Statclock hits in system mode */
u_quad_t p_iticks; /* t: Statclock hits processing intr */
+ uint64_t p_xutime; /* p: utime exposed to userspace */
+ uint64_t p_xstime; /* p: stime exposed to userspace */
int p_traceflag; /* k: Kernel trace points */
void *p_tracep; /* k: Trace private data */