Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Cause a process's user and system times to become non-de...
details: https://anonhg.NetBSD.org/src/rev/b3966c4d6656
branches: trunk
changeset: 361739:b3966c4d6656
user: kre <kre%NetBSD.org@localhost>
date: Wed May 09 19:55:35 2018 +0000
description:
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
diffstat:
sys/kern/kern_resource.c | 31 ++++++++++++++++++++++++++++---
sys/sys/param.h | 4 ++--
sys/sys/proc.h | 4 +++-
3 files changed, 33 insertions(+), 6 deletions(-)
diffs (97 lines):
diff -r eb11bd47aa3f -r b3966c4d6656 sys/kern/kern_resource.c
--- a/sys/kern/kern_resource.c Wed May 09 19:38:46 2018 +0000
+++ b/sys/kern/kern_resource.c Wed May 09 19:55:35 2018 +0000
@@ -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 @@
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;
diff -r eb11bd47aa3f -r b3966c4d6656 sys/sys/param.h
--- a/sys/sys/param.h Wed May 09 19:38:46 2018 +0000
+++ b/sys/sys/param.h Wed May 09 19:55:35 2018 +0000
@@ -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__)
diff -r eb11bd47aa3f -r b3966c4d6656 sys/sys/proc.h
--- a/sys/sys/proc.h Wed May 09 19:38:46 2018 +0000
+++ b/sys/sys/proc.h Wed May 09 19:55:35 2018 +0000
@@ -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 @@
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 */
Home |
Main Index |
Thread Index |
Old Index