Source-Changes-HG archive

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

[src/trunk]: src Improve the time-related hypercalls so that's it's possible to



details:   https://anonhg.NetBSD.org/src/rev/8ace8da78447
branches:  trunk
changeset: 786436:8ace8da78447
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Apr 28 13:17:24 2013 +0000

description:
Improve the time-related hypercalls so that's it's possible to
sleep until an absolute time on the host's monotonic clock (should
something like that be supported).

diffstat:

 lib/librumpuser/rumpuser.c           |  118 +++++++++++++++++++++++++---------
 lib/librumpuser/rumpuser_port.h      |   11 ++-
 sys/rump/include/rump/rumpuser.h     |   10 +-
 sys/rump/librump/rumpkern/emul.c     |   17 ++--
 sys/rump/librump/rumpkern/intr.c     |   37 +++-------
 sys/rump/librump/rumpkern/rump.c     |   15 +--
 sys/rump/librump/rumpkern/vm.c       |   10 +--
 sys/rump/net/lib/libshmif/if_shmem.c |   13 +--
 8 files changed, 134 insertions(+), 97 deletions(-)

diffs (truncated from 459 to 300 lines):

diff -r 12f0b6a6ae72 -r 8ace8da78447 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Sun Apr 28 12:54:39 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Sun Apr 28 13:17:24 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.35 2013/04/28 10:43:45 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.36 2013/04/28 13:17:25 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.c,v 1.35 2013/04/28 10:43:45 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.36 2013/04/28 13:17:25 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -218,27 +218,6 @@
        return rv;
 }
 
-int
-rumpuser_nanosleep(uint64_t *sec, uint64_t *nsec, int *error)
-{
-       struct timespec rqt, rmt;
-       int rv;
-
-       /*LINTED*/
-       rqt.tv_sec = *sec;
-       /*LINTED*/
-       rqt.tv_nsec = *nsec;
-
-       KLOCK_WRAP(rv = nanosleep(&rqt, &rmt));
-       if (rv == -1)
-               seterror(errno);
-
-       *sec = rmt.tv_sec;
-       *nsec = rmt.tv_nsec;
-
-       return rv;
-}
-
 void *
 rumpuser_malloc(size_t howmuch, int alignment)
 {
@@ -536,21 +515,94 @@
 }
 
 int
-rumpuser_gettime(uint64_t *sec, uint64_t *nsec, int *error)
+rumpuser_clock_gettime(uint64_t *sec, uint64_t *nsec, enum rumpclock rclk)
 {
-       struct timeval tv;
+       struct timespec ts;
+       clockid_t clk;
+       int rv;
+
+       switch (rclk) {
+       case RUMPUSER_CLOCK_RELWALL:
+               clk = CLOCK_REALTIME;
+               break;
+       case RUMPUSER_CLOCK_ABSMONO:
+#ifdef HAVE_CLOCK_NANOSLEEP
+               clk = CLOCK_MONOTONIC;
+#else
+               clk = CLOCK_REALTIME;
+#endif
+               break;
+       default:
+               abort();
+       }
+
+       rv = clock_gettime(clk, &ts);
+       if (rv == -1) {
+               return errno;
+       }
+       *sec = ts.tv_sec;
+       *nsec = ts.tv_nsec;
+
+       return 0;
+}
+
+int
+rumpuser_clock_sleep(uint64_t sec, uint64_t nsec, enum rumpclock clk)
+{
+       struct timespec rqt, rmt;
+       int nlocks;
        int rv;
 
-       rv = gettimeofday(&tv, NULL);
-       if (rv == -1) {
-               seterror(errno);
-               return rv;
+       rumpuser__unschedule(0, &nlocks, NULL);
+
+       /*LINTED*/
+       rqt.tv_sec = sec;
+       /*LINTED*/
+       rqt.tv_nsec = nsec;
+
+       switch (clk) {
+       case RUMPUSER_CLOCK_RELWALL:
+               do {
+                       rv = nanosleep(&rqt, &rmt);
+                       rqt = rmt;
+               } while (rv == -1 && errno == EINTR);
+               if (rv == -1) {
+                       rv = errno;
+               }
+               break;
+       case RUMPUSER_CLOCK_ABSMONO:
+               do {
+#ifdef HAVE_CLOCK_NANOSLEEP
+                       rv = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
+                           &rqt, NULL);
+#else
+                       /* le/la/der/die/das sigh. timevalspec tailspin */
+                       struct timespec ts, tsr;
+                       clock_gettime(CLOCK_REALTIME, &ts);
+                       if (ts.tv_sec == rqt.tv_sec ?
+                           ts.tv_nsec > rqt.tv_nsec : ts.tv_sec > rqt.tv_sec) {
+                               rv = 0;
+                       } else {
+                               tsr.tv_sec = rqt.tv_sec - ts.tv_sec;
+                               tsr.tv_nsec = rqt.tv_nsec - ts.tv_nsec;
+                               if (tsr.tv_nsec < 0) {
+                                       tsr.tv_sec--;
+                                       tsr.tv_nsec += 1000*1000*1000;
+                               }
+                               rv = nanosleep(&tsr, NULL);
+                       }
+#endif
+               } while (rv == -1 && errno == EINTR);
+               if (rv == -1) {
+                       rv = errno;
+               }
+               break;
+       default:
+               abort();
        }
 
-       *sec = tv.tv_sec;
-       *nsec = tv.tv_usec * 1000;
-
-       return 0;
+       rumpuser__reschedule(nlocks, NULL);
+       return rv;
 }
 
 int
diff -r 12f0b6a6ae72 -r 8ace8da78447 lib/librumpuser/rumpuser_port.h
--- a/lib/librumpuser/rumpuser_port.h   Sun Apr 28 12:54:39 2013 +0000
+++ b/lib/librumpuser/rumpuser_port.h   Sun Apr 28 13:17:24 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_port.h,v 1.17 2013/04/27 16:56:29 pooka Exp $ */
+/*     $NetBSD: rumpuser_port.h,v 1.18 2013/04/28 13:17:26 pooka Exp $ */
 
 /*
  * Portability header for non-NetBSD platforms.
@@ -31,11 +31,20 @@
 #define PLATFORM_HAS_NBQUOTA
 #endif
 
+#if __NetBSD_Prereq__(6,99,16)
+#define HAVE_CLOCK_NANOSLEEP
+#endif
+
 /*
  * This includes also statvfs1() and fstatvfs1().  They could be
  * reasonably easily emulated on other platforms.
  */
 #define PLATFORM_HAS_NBVFSSTAT
+#endif /* __NetBSD__ */
+
+/* might not be 100% accurate, maybe need to revisit later */
+#if defined(__linux__) || defined(__sun__)
+#define HAVE_CLOCK_NANOSLEEP
 #endif
 
 #ifdef __linux__
diff -r 12f0b6a6ae72 -r 8ace8da78447 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Sun Apr 28 12:54:39 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Sun Apr 28 13:17:24 2013 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: rumpuser.h,v 1.87 2013/04/28 10:43:45 pooka Exp $      */
+/*     $NetBSD: rumpuser.h,v 1.88 2013/04/28 13:17:24 pooka Exp $      */
 
 /*
- * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
+ * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -52,7 +52,6 @@
 #define RUMPUSER_FT_REG 2
 #define RUMPUSER_FT_BLK 3
 #define RUMPUSER_FT_CHR 4
-int rumpuser_nanosleep(uint64_t *, uint64_t *, int *);
 
 void *rumpuser_malloc(size_t, int);
 void rumpuser_free(void *, size_t);
@@ -99,7 +98,10 @@
 ssize_t rumpuser_readv(int, const struct rumpuser_iovec *, int, int *);
 ssize_t rumpuser_writev(int, const struct rumpuser_iovec *, int, int *);
 
-int rumpuser_gettime(uint64_t *, uint64_t *, int *);
+enum rumpclock { RUMPUSER_CLOCK_RELWALL, RUMPUSER_CLOCK_ABSMONO };
+int rumpuser_clock_gettime(uint64_t *, uint64_t *, enum rumpclock);
+int rumpuser_clock_sleep(uint64_t, uint64_t, enum rumpclock);
+
 int rumpuser_getenv(const char *, char *, size_t, int *);
 
 int rumpuser_gethostname(char *, size_t, int *);
diff -r 12f0b6a6ae72 -r 8ace8da78447 sys/rump/librump/rumpkern/emul.c
--- a/sys/rump/librump/rumpkern/emul.c  Sun Apr 28 12:54:39 2013 +0000
+++ b/sys/rump/librump/rumpkern/emul.c  Sun Apr 28 13:17:24 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emul.c,v 1.155 2013/03/18 13:36:23 para Exp $  */
+/*     $NetBSD: emul.c,v 1.156 2013/04/28 13:17:24 pooka Exp $ */
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.155 2013/03/18 13:36:23 para Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.156 2013/04/28 13:17:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/null.h>
@@ -144,7 +144,7 @@
 kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
 {
        extern int hz;
-       int rv, error;
+       int rv;
        uint64_t sec, nsec;
 
        if (mtx)
@@ -152,14 +152,12 @@
 
        sec = timeo / hz;
        nsec = (timeo % hz) * (1000000000 / hz);
-       rv = rumpuser_nanosleep(&sec, &nsec, &error);
-       
+       rv = rumpuser_clock_sleep(sec, nsec, RUMPUSER_CLOCK_RELWALL);
+       KASSERT(rv == 0);
+
        if (mtx)
                mutex_enter(mtx);
 
-       if (rv)
-               return error;
-
        return 0;
 }
 
@@ -225,7 +223,6 @@
 rump_delay(unsigned int us)
 {
        uint64_t sec, nsec;
-       int error;
 
        sec = us / 1000000;
        nsec = (us % 1000000) * 1000;
@@ -233,7 +230,7 @@
        if (__predict_false(sec != 0))
                printf("WARNING: over 1s delay\n");
 
-       rumpuser_nanosleep(&sec, &nsec, &error);
+       rumpuser_clock_sleep(sec, nsec, RUMPUSER_CLOCK_RELWALL);
 }
 void (*delay_func)(unsigned int) = rump_delay;
 
diff -r 12f0b6a6ae72 -r 8ace8da78447 sys/rump/librump/rumpkern/intr.c
--- a/sys/rump/librump/rumpkern/intr.c  Sun Apr 28 12:54:39 2013 +0000
+++ b/sys/rump/librump/rumpkern/intr.c  Sun Apr 28 13:17:24 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.37 2013/04/27 16:32:57 pooka Exp $  */
+/*     $NetBSD: intr.c,v 1.38 2013/04/28 13:17:24 pooka Exp $  */
 
 /*
  * Copyright (c) 2008-2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.37 2013/04/27 16:32:57 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.38 2013/04/28 13:17:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -99,38 +99,27 @@
 static void
 doclock(void *noarg)
 {
-       struct timespec clockbase, clockup;
-       struct timespec thetick, curtime;



Home | Main Index | Thread Index | Old Index