Fix getnano/microuptime to report actual uptime.
This commit is contained in:
parent
094ee5306f
commit
aab61fc839
|
@ -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 <sys/cdefs.h>
|
||||
__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 <sys/param.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -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 <sys/cdefs.h>
|
||||
__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 <sys/param.h>
|
||||
#include <sys/cpu.h>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue