Include kern_tc and use a timecounter driver instead of homerolled

kern_tc implementation.
This commit is contained in:
pooka 2010-04-14 10:27:53 +00:00
parent 9f6376d703
commit d3b3912fd0
4 changed files with 49 additions and 118 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.rumpkern,v 1.75 2010/04/12 22:17:23 pooka Exp $
# $NetBSD: Makefile.rumpkern,v 1.76 2010/04/14 10:27:53 pooka Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@ -39,8 +39,8 @@ SRCS+= rump_syscalls.c rumpkern_if_wrappers.c
# sys/kern
SRCS+= init_sysctl_base.c kern_auth.c kern_descrip.c kern_event.c \
kern_hook.c kern_ksyms.c kern_malloc_stdtype.c kern_module.c \
kern_mutex_obj.c kern_rate.c kern_stub.c kern_sysctl.c \
kern_timeout.c kern_uidinfo.c param.c \
kern_mutex_obj.c kern_ntptime.c kern_rate.c kern_stub.c \
kern_sysctl.c kern_tc.c kern_timeout.c kern_uidinfo.c param.c \
sys_descrip.c sys_generic.c sys_pipe.c sys_select.c syscalls.c
# sys/kern subr (misc)

View File

@ -1,4 +1,4 @@
/* $NetBSD: emul.c,v 1.124 2010/03/31 14:08:33 pooka Exp $ */
/* $NetBSD: emul.c,v 1.125 2010/04/14 10:27:53 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.124 2010/03/31 14:08:33 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.125 2010/04/14 10:27:53 pooka Exp $");
#include <sys/param.h>
#include <sys/null.h>
@ -62,8 +62,6 @@ __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.124 2010/03/31 14:08:33 pooka Exp $");
#include "rump_private.h"
time_t time_second = 1;
kmutex_t *proc_lock;
struct lwp lwp0;
struct vnode *rootvp;
@ -112,6 +110,8 @@ int booted_partition;
kmutex_t tty_lock;
krwlock_t exec_lock;
struct lwplist alllwp = LIST_HEAD_INITIALIZER(alllwp);
/* sparc doesn't sport constant page size */
#ifdef __sparc__
int nbpg = 4096;
@ -124,73 +124,6 @@ struct loadavg averunnable = {
FSCALE,
};
void
getnanouptime(struct timespec *ts)
{
rump_getuptime(ts);
}
void
getmicrouptime(struct timeval *tv)
{
struct timespec ts;
getnanouptime(&ts);
TIMESPEC_TO_TIMEVAL(tv, &ts);
}
static void
gettime(struct timespec *ts)
{
uint64_t sec, nsec;
int error;
rumpuser_gettime(&sec, &nsec, &error);
ts->tv_sec = sec;
ts->tv_nsec = nsec;
}
void
nanotime(struct timespec *ts)
{
if (rump_threads) {
rump_gettime(ts);
} else {
gettime(ts);
}
}
/* hooray for mick, so what if I do */
void
getnanotime(struct timespec *ts)
{
nanotime(ts);
}
void
microtime(struct timeval *tv)
{
struct timespec ts;
if (rump_threads) {
rump_gettime(&ts);
TIMESPEC_TO_TIMEVAL(tv, &ts);
} else {
gettime(&ts);
TIMESPEC_TO_TIMEVAL(tv, &ts);
}
}
void
getmicrotime(struct timeval *tv)
{
microtime(tv);
}
struct proc *
p_find(pid_t pid, uint flags)
{
@ -317,13 +250,6 @@ assert_sleepable(void)
/* always sleepable, although we should improve this */
}
void
tc_setclock(const struct timespec *ts)
{
panic("%s: not implemented", __func__);
}
int
proc_uidmatch(kauth_cred_t cred, kauth_cred_t target)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: intr.c,v 1.23 2009/12/05 22:44:08 pooka Exp $ */
/* $NetBSD: intr.c,v 1.24 2010/04/14 10:27:53 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@ -26,13 +26,15 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.23 2009/12/05 22:44:08 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.24 2010/04/14 10:27:53 pooka Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/kernel.h>
#include <sys/kmem.h>
#include <sys/kthread.h>
#include <sys/intr.h>
#include <sys/timetc.h>
#include <rump/rumpuser.h>
@ -42,8 +44,6 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.23 2009/12/05 22:44:08 pooka Exp $");
* Interrupt simulator. It executes hardclock() and softintrs.
*/
time_t time_uptime = 0;
#define SI_MPSAFE 0x01
#define SI_ONLIST 0x02
#define SI_KILLME 0x04
@ -67,33 +67,27 @@ struct softint_lev {
static struct rumpuser_cv *clockcv;
static struct rumpuser_mtx *clockmtx;
static struct timespec clockbase, clockup;
static unsigned clkgen;
kcondvar_t lbolt; /* Oh Kath Ra */
void
rump_getuptime(struct timespec *ts)
{
int startgen, i = 0;
static u_int ticks;
do {
startgen = clkgen;
if (__predict_false(i++ > 10)) {
yield();
i = 0;
}
*ts = clockup;
} while (startgen != clkgen || clkgen % 2 != 0);
static u_int
rumptc_get(struct timecounter *tc)
{
KASSERT(rump_threads);
return ticks;
}
void
rump_gettime(struct timespec *ts)
{
struct timespec ts_up;
rump_getuptime(&ts_up);
timespecadd(&clockbase, &ts_up, ts);
}
static struct timecounter rumptc = {
.tc_get_timecount = rumptc_get,
.tc_poll_pps = NULL,
.tc_counter_mask = ~0,
.tc_frequency = 0,
.tc_name = "rumpclk",
.tc_quality = 0,
};
/*
* clock "interrupt"
@ -101,17 +95,17 @@ rump_gettime(struct timespec *ts)
static void
doclock(void *noarg)
{
struct timespec tick, curtime;
struct timespec thetick, curtime;
uint64_t sec, nsec;
int ticks = 0, error;
int error;
extern int hz;
rumpuser_gettime(&sec, &nsec, &error);
clockbase.tv_sec = sec;
clockbase.tv_nsec = nsec;
curtime = clockbase;
tick.tv_sec = 0;
tick.tv_nsec = 1000000000/hz;
thetick.tv_sec = 0;
thetick.tv_nsec = 1000000000/hz;
rumpuser_mutex_enter(clockmtx);
rumpuser_cv_signal(clockcv);
@ -126,15 +120,12 @@ doclock(void *noarg)
/* if !maincpu: continue */
if (++ticks == hz) {
time_uptime++;
ticks = 0;
if ((++ticks % hz) == 0) {
cv_broadcast(&lbolt);
}
tc_ticktock();
clkgen++;
timespecadd(&clockup, &tick, &clockup);
clkgen++;
timespecadd(&clockup, &thetick, &clockup);
timespecadd(&clockup, &clockbase, &curtime);
}
}
@ -246,6 +237,9 @@ softint_init(struct cpu_info *ci)
panic("clock thread creation failed: %d", rv);
}
rumptc.tc_frequency = hz;
tc_init(&rumptc);
/*
* Make sure we have a clocktime before returning.
* XXX: mp

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump.c,v 1.159 2010/04/12 22:17:23 pooka Exp $ */
/* $NetBSD: rump.c,v 1.160 2010/04/14 10:27:53 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.159 2010/04/12 22:17:23 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.160 2010/04/14 10:27:53 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -58,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.159 2010/04/12 22:17:23 pooka Exp $");
#include <sys/select.h>
#include <sys/sysctl.h>
#include <sys/syscall.h>
#include <sys/timetc.h>
#include <sys/tty.h>
#include <sys/uidinfo.h>
#include <sys/vmem.h>
@ -186,6 +187,7 @@ int
rump__init(int rump_version)
{
char buf[256];
struct timespec ts;
uint64_t sec, nsec;
struct proc *p;
struct lwp *l;
@ -290,6 +292,13 @@ rump__init(int rump_version)
rump_schedule();
percpu_init();
inittimecounter();
ntp_init();
rumpuser_gettime(&sec, &nsec, &error);
ts.tv_sec = sec;
ts.tv_nsec = nsec;
tc_setclock(&ts);
/* we are mostly go. do per-cpu subsystem init */
for (i = 0; i < ncpu; i++) {
@ -490,6 +499,7 @@ rump_lwp_alloc(pid_t pid, lwpid_t lid)
l->l_fd = p->p_fd;
l->l_cpu = NULL;
lwp_initspecific(l);
LIST_INSERT_HEAD(&alllwp, l, l_list);
return l;
}
@ -537,6 +547,7 @@ rump_lwp_free(struct lwp *l)
if (l->l_name)
kmem_free(l->l_name, MAXCOMLEN);
lwp_finispecific(l);
LIST_REMOVE(l, l_list);
kmem_free(l, sizeof(*l));
}