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.
This commit is contained in:
pooka 2013-04-28 13:37:51 +00:00
parent 0cffcac141
commit 49bb662cc0
4 changed files with 32 additions and 37 deletions

View File

@ -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 *cv, struct rumpuser_mtx *mtx,
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);

View File

@ -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 *mtx)
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);
}

View File

@ -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 *mtx)
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);

View File

@ -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_t *kinterlock)
} 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);
}