diff --git a/sys/rump/librump/rumpkern/emul.c b/sys/rump/librump/rumpkern/emul.c index 39275d153fcf..5afe5dd2d550 100644 --- a/sys/rump/librump/rumpkern/emul.c +++ b/sys/rump/librump/rumpkern/emul.c @@ -1,4 +1,4 @@ -/* $NetBSD: emul.c,v 1.86 2009/04/26 14:37:03 pgoyette Exp $ */ +/* $NetBSD: emul.c,v 1.87 2009/04/26 20:41:24 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.86 2009/04/26 14:37:03 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.87 2009/04/26 20:41:24 pooka Exp $"); #include #include @@ -243,25 +243,17 @@ device_class(device_t dev) void getnanouptime(struct timespec *ts) { - uint64_t sec, nsec; - int error; - /* XXX: this is wrong, does not report *uptime* */ - rumpuser_gettime(&sec, &nsec, &error); - ts->tv_sec = sec; - ts->tv_nsec = nsec; + rump_getuptime(ts); } void getmicrouptime(struct timeval *tv) { - uint64_t sec, nsec; - int error; + struct timespec ts; - /* XXX: this is wrong, does not report *uptime* */ - rumpuser_gettime(&sec, &nsec, &error); - tv->tv_sec = sec; - tv->tv_usec = nsec / 1000; + getnanouptime(&ts); + TIMESPEC_TO_TIMEVAL(tv, &ts); } void diff --git a/sys/rump/librump/rumpkern/intr.c b/sys/rump/librump/rumpkern/intr.c index e76fdc6a24b6..7ab661c7f888 100644 --- a/sys/rump/librump/rumpkern/intr.c +++ b/sys/rump/librump/rumpkern/intr.c @@ -1,4 +1,4 @@ -/* $NetBSD: intr.c,v 1.15 2009/02/27 15:15:19 pooka Exp $ */ +/* $NetBSD: intr.c,v 1.16 2009/04/26 20:41:24 pooka Exp $ */ /* * Copyright (c) 2008 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.15 2009/02/27 15:15:19 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.16 2009/04/26 20:41:24 pooka Exp $"); #include #include @@ -89,19 +89,31 @@ makeworker(bool bootstrap) /* rumpuser structures since we call rumpuser interfaces directly */ static struct rumpuser_cv *clockcv; static struct rumpuser_mtx *clockmtx; -static struct timespec rump_clock; +static struct timespec clockbase, clockup; +static unsigned clkgen; + +void +rump_getuptime(struct timespec *ts) +{ + int startgen, i; + + do { + startgen = clkgen; + if (__predict_false(i++ > 10)) { + yield(); + i = 0; + } + *ts = clockup; + } while (startgen != clkgen || clkgen % 2 != 0); +} void rump_gettime(struct timespec *ts) { - struct timespec attempt; + struct timespec ts_up; - /* XXX: this is completely bogus */ - do { - attempt = rump_clock; - } while (memcmp(&attempt, &rump_clock, sizeof(struct timespec)) != 0); - - *ts = attempt; + rump_getuptime(&ts_up); + timespecadd(&clockbase, &ts_up, ts); } /* @@ -110,15 +122,15 @@ rump_gettime(struct timespec *ts) static void doclock(void *noarg) { - struct timespec tick; + struct timespec tick, curtime; uint64_t sec, nsec; - static int ticks = 0; + int ticks = 0, error; extern int hz; - int error; rumpuser_gettime(&sec, &nsec, &error); - rump_clock.tv_sec = sec; - rump_clock.tv_nsec = nsec; + clockbase.tv_sec = sec; + clockbase.tv_nsec = nsec; + curtime = clockbase; tick.tv_sec = 0; tick.tv_nsec = 1000000000/hz; @@ -133,11 +145,15 @@ doclock(void *noarg) ticks = 0; } - /* wait until the next tick */ + /* wait until the next tick. XXX: what if the clock changes? */ while (rumpuser_cv_timedwait(clockcv, clockmtx, - &rump_clock) != EWOULDBLOCK) + &curtime) != EWOULDBLOCK) continue; - timespecadd(&rump_clock, &tick, &rump_clock); + + clkgen++; + timespecadd(&clockup, &tick, &clockup); + clkgen++; + timespecadd(&clockup, &clockbase, &curtime); } } diff --git a/sys/rump/librump/rumpkern/rump_private.h b/sys/rump/librump/rumpkern/rump_private.h index 4d3915bf7fe8..aca2e68c3f84 100644 --- a/sys/rump/librump/rumpkern/rump_private.h +++ b/sys/rump/librump/rumpkern/rump_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: rump_private.h,v 1.26 2009/04/06 20:41:29 pooka Exp $ */ +/* $NetBSD: rump_private.h,v 1.27 2009/04/26 20:41:24 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -62,6 +62,7 @@ void rumpvm_enterva(vaddr_t addr, struct vm_page *); void rumpvm_flushva(struct uvm_object *); void rump_gettime(struct timespec *); +void rump_getuptime(struct timespec *); lwpid_t rump_nextlid(void);