Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode host and userkernel timespec might differ ...



details:   https://anonhg.NetBSD.org/src/rev/b429e386ad9c
branches:  trunk
changeset: 768640:b429e386ad9c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Aug 23 14:37:50 2011 +0000

description:
host and userkernel timespec might differ in size (because of time_t) so
instead of thunk_clock_getres() filling in a timespec, use instead
thunk_clock_getres_monotonic() that returns the resolution as a long

diffstat:

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

diffs (97 lines):

diff -r 24a975ff161d -r b429e386ad9c sys/arch/usermode/dev/clock.c
--- a/sys/arch/usermode/dev/clock.c     Tue Aug 23 14:23:08 2011 +0000
+++ b/sys/arch/usermode/dev/clock.c     Tue Aug 23 14:37:50 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.8 2011/08/13 12:06:22 jmcneill Exp $ */
+/* $NetBSD: clock.c,v 1.9 2011/08/23 14:37:50 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.8 2011/08/13 12:06:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.9 2011/08/23 14:37:50 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -84,7 +84,7 @@
 {
        clock_softc_t *sc = device_private(self);
        struct itimerval itimer;
-       struct timespec res;
+       long tcres;
 
        aprint_naive("\n");
        aprint_normal("\n");
@@ -101,9 +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) {
+       tcres = thunk_clock_getres_monotonic();
+       if (tcres > 0) {
                clock_timecounter.tc_quality = 1000;
-               clock_timecounter.tc_frequency = 1000000000 / res.tv_nsec;
+               clock_timecounter.tc_frequency = 1000000000 / tcres;
        }
        tc_init(&clock_timecounter);
 }
diff -r 24a975ff161d -r b429e386ad9c sys/arch/usermode/include/thunk.h
--- a/sys/arch/usermode/include/thunk.h Tue Aug 23 14:23:08 2011 +0000
+++ b/sys/arch/usermode/include/thunk.h Tue Aug 23 14:37:50 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.9 2011/08/22 15:30:16 reinoud Exp $ */
+/* $NetBSD: thunk.h,v 1.10 2011/08/23 14:37:50 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -41,7 +41,7 @@
 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 *);
+long   thunk_clock_getres_monotonic(void);
 int    thunk_usleep(useconds_t);
 
 void   thunk_exit(int);
diff -r 24a975ff161d -r b429e386ad9c sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Tue Aug 23 14:23:08 2011 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Tue Aug 23 14:37:50 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.10 2011/08/22 21:45:38 jmcneill Exp $ */
+/* $NetBSD: thunk.c,v 1.11 2011/08/23 14:37:50 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.10 2011/08/22 21:45:38 jmcneill Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.11 2011/08/23 14:37:50 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/ansi.h>
@@ -65,10 +65,17 @@
        return clock_gettime(clock_id, tp);
 }
 
-int
-thunk_clock_getres(clockid_t clock_id, struct timespec *res)
+long
+thunk_clock_getres_monotonic(void)
 {
-       return clock_getres(clock_id, res);
+       struct timespec res;
+       int error;
+
+       error = clock_getres(CLOCK_MONOTONIC, &res);
+       if (error)
+               return -1;
+
+       return res.tv_nsec;
 }
 
 int



Home | Main Index | Thread Index | Old Index