Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode - replace the gettimeofday timecounter wit...



details:   https://anonhg.NetBSD.org/src/rev/0f7d68989e7a
branches:  trunk
changeset: 768261:0f7d68989e7a
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Aug 13 12:06:22 2011 +0000

description:
- replace the gettimeofday timecounter with one based on CLOCK_MONOTONIC
- use gettimeofday for TODR clock

diffstat:

 sys/arch/usermode/dev/clock.c      |  37 ++++++++++++++++++++++++++++---------
 sys/arch/usermode/include/thunk.h  |   4 +++-
 sys/arch/usermode/usermode/thunk.c |  16 ++++++++++++++--
 3 files changed, 45 insertions(+), 12 deletions(-)

diffs (152 lines):

diff -r 9fdd43b67a5a -r 0f7d68989e7a sys/arch/usermode/dev/clock.c
--- a/sys/arch/usermode/dev/clock.c     Sat Aug 13 11:41:57 2011 +0000
+++ b/sys/arch/usermode/dev/clock.c     Sat Aug 13 12:06:22 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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_clock_gettime(CLOCK_MONOTONIC, &ts);
+       return ts.tv_nsec;
+}
 
-       thunk_gettimeofday(&tv, NULL);
-       return tv.tv_sec * 1000000 + tv.tv_usec;
+static int
+clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv)
+{
+       return thunk_gettimeofday(tv,  NULL);
 }
diff -r 9fdd43b67a5a -r 0f7d68989e7a sys/arch/usermode/include/thunk.h
--- a/sys/arch/usermode/include/thunk.h Sat Aug 13 11:41:57 2011 +0000
+++ b/sys/arch/usermode/include/thunk.h Sat Aug 13 12:06:22 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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);
diff -r 9fdd43b67a5a -r 0f7d68989e7a sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Sat Aug 13 11:41:57 2011 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Sat Aug 13 12:06:22 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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);



Home | Main Index | Thread Index | Old Index