summaryrefslogtreecommitdiff
path: root/sys/kern/kern_synch.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-12-19 04:51:45 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-12-19 04:51:45 +0000
commit444010fc08231b08f764bbe79bf1a42e7c2a4517 (patch)
tree9dbc6eade6108e3d2406cdb4f83aecba2250f69d /sys/kern/kern_synch.c
parent564595dcb6c33ba572061596a9318239fed8a976 (diff)
Add a check for time not flowing monotonically and just don't change
p->p_rtime in this case instead of zeroing it; based on an idea from nordin@. Also add a printf about microtime() not being monotonic for this case (from miod@) #ifdef DIAGNOSTIC. This version OK otto@
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r--sys/kern/kern_synch.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index bcadf821ec2..2cd8c537ba1 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.50 2003/12/15 22:03:41 millert Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.51 2003/12/19 04:51:44 millert Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -706,10 +706,15 @@ mi_switch()
* process was running, and add that to its total so far.
*/
microtime(&tv);
- timersub(&tv, &runtime, &tv);
- timeradd(&p->p_rtime, &tv, &p->p_rtime);
- if (p->p_rtime.tv_sec < 0)
- p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
+ if (timercmp(&tv, &runtime, <)) {
+#ifdef DIAGNOSTIC
+ printf("time is not monotonic! tv=%ld.%ld, runtime=%ld.%ld\n",
+ tv.tv_sec, tv.tv_usec, runtime.tv_sec, runtime.tv_usec);
+#endif
+ } else {
+ timersub(&tv, &runtime, &tv);
+ timeradd(&p->p_rtime, &tv, &p->p_rtime);
+ }
/*
* Check if the process exceeds its cpu resource allocation.