Module Name: src Committed By: jmcneill Date: Sat Aug 13 12:06:24 UTC 2011
Modified Files: src/sys/arch/usermode/dev: clock.c src/sys/arch/usermode/include: thunk.h src/sys/arch/usermode/usermode: thunk.c Log Message: - replace the gettimeofday timecounter with one based on CLOCK_MONOTONIC - use gettimeofday for TODR clock To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/arch/usermode/dev/clock.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/include/thunk.h cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/usermode/thunk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/usermode/dev/clock.c diff -u src/sys/arch/usermode/dev/clock.c:1.7 src/sys/arch/usermode/dev/clock.c:1.8 --- src/sys/arch/usermode/dev/clock.c:1.7 Sat Aug 13 10:31:24 2011 +++ src/sys/arch/usermode/dev/clock.c Sat Aug 13 12:06:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.7 2011/08/13 10:31:24 jmcneill Exp $ */ +/* $NetBSD: clock.c,v 1.8 2011/08/13 12:06:22 jmcneill Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.7 2011/08/13 10:31:24 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.8 2011/08/13 12:06:22 jmcneill Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -39,23 +39,28 @@ #include <machine/mainbus.h> #include <machine/thunk.h> +#include <dev/clock_subr.h> + static int clock_match(device_t, cfdata_t, void *); static void clock_attach(device_t, device_t, void *); static void clock_intr(int); static u_int clock_getcounter(struct timecounter *); +static int clock_todr_gettime(struct todr_chip_handle *, struct timeval *); + typedef struct clock_softc { - device_t sc_dev; + device_t sc_dev; + struct todr_chip_handle sc_todr; } clock_softc_t; static struct timecounter clock_timecounter = { clock_getcounter, /* get_timecount */ 0, /* no poll_pps */ ~0u, /* counter_mask */ - 1000000, /* frequency */ - "gettimeofday", /* name */ - 100, /* quality */ + 0, /* frequency */ + "CLOCK_MONOTONIC", /* name */ + -100, /* quality */ NULL, /* prev */ NULL, /* next */ }; @@ -79,12 +84,16 @@ { clock_softc_t *sc = device_private(self); struct itimerval itimer; + struct timespec res; aprint_naive("\n"); aprint_normal("\n"); sc->sc_dev = self; + sc->sc_todr.todr_gettime = clock_todr_gettime; + todr_attach(&sc->sc_todr); + (void)signal(SIGALRM, clock_intr); itimer.it_interval.tv_sec = 0; @@ -92,6 +101,10 @@ itimer.it_value = itimer.it_interval; thunk_setitimer(ITIMER_REAL, &itimer, NULL); + if (thunk_clock_getres(CLOCK_MONOTONIC, &res) == 0 && res.tv_nsec > 0) { + clock_timecounter.tc_quality = 1000; + clock_timecounter.tc_frequency = 1000000000 / res.tv_nsec; + } tc_init(&clock_timecounter); } @@ -111,8 +124,14 @@ static u_int clock_getcounter(struct timecounter *tc) { - struct timeval tv; + struct timespec ts; - thunk_gettimeofday(&tv, NULL); - return tv.tv_sec * 1000000 + tv.tv_usec; + thunk_clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_nsec; +} + +static int +clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv) +{ + return thunk_gettimeofday(tv, NULL); } Index: src/sys/arch/usermode/include/thunk.h diff -u src/sys/arch/usermode/include/thunk.h:1.4 src/sys/arch/usermode/include/thunk.h:1.5 --- src/sys/arch/usermode/include/thunk.h:1.4 Sat Aug 13 10:33:52 2011 +++ src/sys/arch/usermode/include/thunk.h Sat Aug 13 12:06:23 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: thunk.h,v 1.4 2011/08/13 10:33:52 jmcneill Exp $ */ +/* $NetBSD: thunk.h,v 1.5 2011/08/13 12:06:23 jmcneill Exp $ */ /*- * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca> @@ -39,6 +39,8 @@ int thunk_setitimer(int, const struct itimerval *, struct itimerval *); int thunk_gettimeofday(struct timeval *, void *); +int thunk_clock_gettime(clockid_t, struct timespec *); +int thunk_clock_getres(clockid_t, struct timespec *); int thunk_usleep(useconds_t); void thunk_exit(int); Index: src/sys/arch/usermode/usermode/thunk.c diff -u src/sys/arch/usermode/usermode/thunk.c:1.4 src/sys/arch/usermode/usermode/thunk.c:1.5 --- src/sys/arch/usermode/usermode/thunk.c:1.4 Sat Aug 13 10:33:52 2011 +++ src/sys/arch/usermode/usermode/thunk.c Sat Aug 13 12:06:23 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: thunk.c,v 1.4 2011/08/13 10:33:52 jmcneill Exp $ */ +/* $NetBSD: thunk.c,v 1.5 2011/08/13 12:06:23 jmcneill Exp $ */ /*- * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: thunk.c,v 1.4 2011/08/13 10:33:52 jmcneill Exp $"); +__RCSID("$NetBSD: thunk.c,v 1.5 2011/08/13 12:06:23 jmcneill Exp $"); #include <machine/thunk.h> @@ -55,6 +55,18 @@ } int +thunk_clock_gettime(clockid_t clock_id, struct timespec *tp) +{ + return clock_gettime(clock_id, tp); +} + +int +thunk_clock_getres(clockid_t clock_id, struct timespec *res) +{ + return clock_getres(clock_id, res); +} + +int thunk_usleep(useconds_t microseconds) { return usleep(microseconds);