Module Name:    src
Committed By:   pooka
Date:           Sun Apr 28 13:37:52 UTC 2013

Modified Files:
        src/lib/librumpuser: rumpuser_pth.c
        src/sys/rump/librump/rumpkern: locks.c locks_up.c ltsleep.c

Log Message:
Change rumpuser_cv_timedwait() from absolute time to relative time.
It's then the hypervisor's problem to translate it accordingly.
Now we no longer have to worry about the kernel having to know the
hypervisor's time and vice versa.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/librumpuser/rumpuser_pth.c
cvs rdiff -u -r1.57 -r1.58 src/sys/rump/librump/rumpkern/locks.c
cvs rdiff -u -r1.7 -r1.8 src/sys/rump/librump/rumpkern/locks_up.c
cvs rdiff -u -r1.30 -r1.31 src/sys/rump/librump/rumpkern/ltsleep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser_pth.c
diff -u src/lib/librumpuser/rumpuser_pth.c:1.15 src/lib/librumpuser/rumpuser_pth.c:1.16
--- src/lib/librumpuser/rumpuser_pth.c:1.15	Sat Apr 27 16:32:58 2013
+++ src/lib/librumpuser/rumpuser_pth.c	Sun Apr 28 13:37:51 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser_pth.c,v 1.15 2013/04/27 16:32:58 pooka Exp $	*/
+/*	$NetBSD: rumpuser_pth.c,v 1.16 2013/04/28 13:37:51 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.15 2013/04/27 16:32:58 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.16 2013/04/28 13:37:51 pooka Exp $");
 #endif /* !lint */
 
 #include <assert.h>
@@ -489,12 +489,25 @@ rumpuser_cv_timedwait(struct rumpuser_cv
 	struct timespec ts;
 	int rv, nlocks;
 
-	/* LINTED */
-	ts.tv_sec = sec; ts.tv_nsec = nsec;
+	/*
+	 * Get clock already here, just in case we will be put to sleep
+	 * after releasing the kernel context.
+	 *
+	 * The condition variables should use CLOCK_MONOTONIC, but since
+	 * that's not available everywhere, leave it for another day.
+	 */
+	clock_gettime(CLOCK_REALTIME, &ts);
 
 	cv->nwaiters++;
 	rumpuser__unschedule(0, &nlocks, mtx);
 	mtxexit(mtx);
+
+	ts.tv_sec += sec;
+	ts.tv_nsec += nsec;
+	if (ts.tv_nsec >= 1000*1000*1000) {
+		ts.tv_sec++;
+		ts.tv_nsec -= 1000*1000*1000;
+	}
 	rv = pthread_cond_timedwait(&cv->pthcv, &mtx->pthmtx, &ts);
 	mtxenter(mtx);
 	rumpuser__reschedule(nlocks, mtx);

Index: src/sys/rump/librump/rumpkern/locks.c
diff -u src/sys/rump/librump/rumpkern/locks.c:1.57 src/sys/rump/librump/rumpkern/locks.c:1.58
--- src/sys/rump/librump/rumpkern/locks.c:1.57	Sat Apr 27 16:32:57 2013
+++ src/sys/rump/librump/rumpkern/locks.c	Sun Apr 28 13:37:52 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: locks.c,v 1.57 2013/04/27 16:32:57 pooka Exp $	*/
+/*	$NetBSD: locks.c,v 1.58 2013/04/28 13:37:52 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.57 2013/04/27 16:32:57 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.58 2013/04/28 13:37:52 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -382,22 +382,15 @@ cv_wait_sig(kcondvar_t *cv, kmutex_t *mt
 int
 cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int ticks)
 {
-	struct timespec ts, tick;
+	struct timespec ts;
 	extern int hz;
 	int rv;
 
 	if (ticks == 0) {
 		rv = cv_wait_sig(cv, mtx);
 	} else {
-		/*
-		 * XXX: this fetches rump kernel time, but
-		 * rumpuser_cv_timedwait uses host time.
-		 */
-		nanotime(&ts);
-		tick.tv_sec = ticks / hz;
-		tick.tv_nsec = (ticks % hz) * (1000000000/hz);
-		timespecadd(&ts, &tick, &ts);
-
+		ts.tv_sec = ticks / hz;
+		ts.tv_nsec = (ticks % hz) * (1000000000/hz);
 		rv = docvwait(cv, mtx, &ts);
 	}
 

Index: src/sys/rump/librump/rumpkern/locks_up.c
diff -u src/sys/rump/librump/rumpkern/locks_up.c:1.7 src/sys/rump/librump/rumpkern/locks_up.c:1.8
--- src/sys/rump/librump/rumpkern/locks_up.c:1.7	Sat Apr 27 13:59:46 2013
+++ src/sys/rump/librump/rumpkern/locks_up.c	Sun Apr 28 13:37:52 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: locks_up.c,v 1.7 2013/04/27 13:59:46 pooka Exp $	*/
+/*	$NetBSD: locks_up.c,v 1.8 2013/04/28 13:37:52 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.7 2013/04/27 13:59:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.8 2013/04/28 13:37:52 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -375,21 +375,15 @@ cv_wait_sig(kcondvar_t *cv, kmutex_t *mt
 int
 cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int ticks)
 {
-	struct timespec ts, tstick;
+	struct timespec ts;
 
 #ifdef DIAGNOSTIC
 	UPMTX(mtx);
 	KASSERT(upm->upm_owner == curlwp);
 #endif
 
-	/*
-	 * XXX: this fetches rump kernel time, but rumpuser_cv_timedwait
-	 * uses host time.
-	 */
-	nanotime(&ts);
-	tstick.tv_sec = ticks / hz;
-	tstick.tv_nsec = (ticks % hz) * (1000000000/hz);
-	timespecadd(&ts, &tstick, &ts);
+	ts.tv_sec = ticks / hz;
+	ts.tv_nsec = (ticks % hz) * (1000000000/hz);
 
 	if (ticks == 0) {
 		cv_wait(cv, mtx);

Index: src/sys/rump/librump/rumpkern/ltsleep.c
diff -u src/sys/rump/librump/rumpkern/ltsleep.c:1.30 src/sys/rump/librump/rumpkern/ltsleep.c:1.31
--- src/sys/rump/librump/rumpkern/ltsleep.c:1.30	Sat Apr 27 16:32:57 2013
+++ src/sys/rump/librump/rumpkern/ltsleep.c	Sun Apr 28 13:37:52 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ltsleep.c,v 1.30 2013/04/27 16:32:57 pooka Exp $	*/
+/*	$NetBSD: ltsleep.c,v 1.31 2013/04/28 13:37:52 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ltsleep.c,v 1.30 2013/04/27 16:32:57 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ltsleep.c,v 1.31 2013/04/28 13:37:52 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -64,7 +64,7 @@ static int
 sleeper(wchan_t ident, int timo, kmutex_t *kinterlock)
 {
 	struct ltsleeper lts;
-	struct timespec ts, ticks;
+	struct timespec ts;
 	int rv;
 
 	lts.id = ident;
@@ -86,14 +86,9 @@ sleeper(wchan_t ident, int timo, kmutex_
 		} else {
 			/*
 			 * Calculate wakeup-time.
-			 * XXX: should assert nanotime() does not block,
-			 * i.e. yield the cpu and/or biglock.
 			 */
-			ticks.tv_sec = timo / hz;
-			ticks.tv_nsec = (timo % hz) * (1000000000/hz);
-			nanotime(&ts);
-			timespecadd(&ts, &ticks, &ts);
-
+			ts.tv_sec = timo / hz;
+			ts.tv_nsec = (timo % hz) * (1000000000/hz);
 			rv = rumpuser_cv_timedwait(lts.ucv, rump_giantlock,
 			    ts.tv_sec, ts.tv_nsec);
 		}

Reply via email to