Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Change rumpuser_cv_timedwait() from absolute time to relativ...



details:   https://anonhg.NetBSD.org/src/rev/faadaf06411f
branches:  trunk
changeset: 786438:faadaf06411f
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Apr 28 13:37:51 2013 +0000

description:
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.

diffstat:

 lib/librumpuser/rumpuser_pth.c       |  21 +++++++++++++++++----
 sys/rump/librump/rumpkern/locks.c    |  17 +++++------------
 sys/rump/librump/rumpkern/locks_up.c |  16 +++++-----------
 sys/rump/librump/rumpkern/ltsleep.c  |  15 +++++----------
 4 files changed, 32 insertions(+), 37 deletions(-)

diffs (177 lines):

diff -r 566d42fa93b6 -r faadaf06411f lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c    Sun Apr 28 13:35:23 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth.c    Sun Apr 28 13:37:51 2013 +0000
@@ -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 @@
        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);
diff -r 566d42fa93b6 -r faadaf06411f sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Sun Apr 28 13:35:23 2013 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Sun Apr 28 13:37:51 2013 +0000
@@ -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 @@
 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);
        }
 
diff -r 566d42fa93b6 -r faadaf06411f sys/rump/librump/rumpkern/locks_up.c
--- a/sys/rump/librump/rumpkern/locks_up.c      Sun Apr 28 13:35:23 2013 +0000
+++ b/sys/rump/librump/rumpkern/locks_up.c      Sun Apr 28 13:37:51 2013 +0000
@@ -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 @@
 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);
diff -r 566d42fa93b6 -r faadaf06411f sys/rump/librump/rumpkern/ltsleep.c
--- a/sys/rump/librump/rumpkern/ltsleep.c       Sun Apr 28 13:35:23 2013 +0000
+++ b/sys/rump/librump/rumpkern/ltsleep.c       Sun Apr 28 13:37:51 2013 +0000
@@ -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 @@
 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 @@
                } 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);
                }



Home | Main Index | Thread Index | Old Index