more host vs. userkernel time_t fixesdiff -r1.9 -r1.10 src/sys/arch/usermode/dev/clock.c
(jmcneill)
--- src/sys/arch/usermode/dev/clock.c 2011/08/23 14:37:50 1.9
+++ src/sys/arch/usermode/dev/clock.c 2011/08/23 16:09:27 1.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: clock.c,v 1.9 2011/08/23 14:37:50 jmcneill Exp $ */ | 1 | /* $NetBSD: clock.c,v 1.10 2011/08/23 16:09:27 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -17,45 +17,45 @@ | @@ -17,45 +17,45 @@ | |||
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | 26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.9 2011/08/23 14:37:50 jmcneill Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.10 2011/08/23 16:09:27 jmcneill Exp $"); | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/proc.h> | 33 | #include <sys/proc.h> | |
34 | #include <sys/systm.h> | 34 | #include <sys/systm.h> | |
35 | #include <sys/device.h> | 35 | #include <sys/device.h> | |
36 | #include <sys/timetc.h> | 36 | #include <sys/timetc.h> | |
37 | #include <sys/time.h> | 37 | #include <sys/time.h> | |
38 | 38 | |||
39 | #include <machine/mainbus.h> | 39 | #include <machine/mainbus.h> | |
40 | #include <machine/thunk.h> | 40 | #include <machine/thunk.h> | |
41 | 41 | |||
42 | #include <dev/clock_subr.h> | 42 | #include <dev/clock_subr.h> | |
43 | 43 | |||
44 | static int clock_match(device_t, cfdata_t, void *); | 44 | static int clock_match(device_t, cfdata_t, void *); | |
45 | static void clock_attach(device_t, device_t, void *); | 45 | static void clock_attach(device_t, device_t, void *); | |
46 | 46 | |||
47 | static void clock_intr(int); | 47 | static void clock_intr(int); | |
48 | static u_int clock_getcounter(struct timecounter *); | 48 | static unsigned int clock_getcounter(struct timecounter *); | |
49 | 49 | |||
50 | static int clock_todr_gettime(struct todr_chip_handle *, struct timeval *); | 50 | static int clock_todr_gettime(struct todr_chip_handle *, struct timeval *); | |
51 | 51 | |||
52 | typedef struct clock_softc { | 52 | typedef struct clock_softc { | |
53 | device_t sc_dev; | 53 | device_t sc_dev; | |
54 | struct todr_chip_handle sc_todr; | 54 | struct todr_chip_handle sc_todr; | |
55 | } clock_softc_t; | 55 | } clock_softc_t; | |
56 | 56 | |||
57 | static struct timecounter clock_timecounter = { | 57 | static struct timecounter clock_timecounter = { | |
58 | clock_getcounter, /* get_timecount */ | 58 | clock_getcounter, /* get_timecount */ | |
59 | 0, /* no poll_pps */ | 59 | 0, /* no poll_pps */ | |
60 | ~0u, /* counter_mask */ | 60 | ~0u, /* counter_mask */ | |
61 | 0, /* frequency */ | 61 | 0, /* frequency */ | |
@@ -112,27 +112,34 @@ clock_attach(device_t parent, device_t s | @@ -112,27 +112,34 @@ clock_attach(device_t parent, device_t s | |||
112 | static void | 112 | static void | |
113 | clock_intr(int notused) | 113 | clock_intr(int notused) | |
114 | { | 114 | { | |
115 | extern int usermode_x; | 115 | extern int usermode_x; | |
116 | struct clockframe cf; | 116 | struct clockframe cf; | |
117 | 117 | |||
118 | curcpu()->ci_idepth++; | 118 | curcpu()->ci_idepth++; | |
119 | 119 | |||
120 | hardclock(&cf); | 120 | hardclock(&cf); | |
121 | 121 | |||
122 | curcpu()->ci_idepth--; | 122 | curcpu()->ci_idepth--; | |
123 | } | 123 | } | |
124 | 124 | |||
125 | static u_int | 125 | static unsigned int | |
126 | clock_getcounter(struct timecounter *tc) | 126 | clock_getcounter(struct timecounter *tc) | |
127 | { | 127 | { | |
128 | struct timespec ts; | 128 | return thunk_getcounter(); | |
129 | ||||
130 | thunk_clock_gettime(CLOCK_MONOTONIC, &ts); | |||
131 | return ts.tv_nsec; | |||
132 | } | 129 | } | |
133 | 130 | |||
134 | static int | 131 | static int | |
135 | clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv) | 132 | clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv) | |
136 | { | 133 | { | |
137 | return thunk_gettimeofday(tv, NULL); | 134 | struct thunk_timeval ttv; | |
135 | int error; | |||
136 | ||||
137 | error = thunk_gettimeofday(&ttv, NULL); | |||
138 | if (error) | |||
139 | return error; | |||
140 | ||||
141 | tv->tv_sec = ttv.tv_sec; | |||
142 | tv->tv_usec = ttv.tv_usec; | |||
143 | ||||
144 | return 0; | |||
138 | } | 145 | } |
--- src/sys/arch/usermode/include/thunk.h 2011/08/23 14:37:50 1.10
+++ src/sys/arch/usermode/include/thunk.h 2011/08/23 16:09:27 1.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: thunk.h,v 1.10 2011/08/23 14:37:50 jmcneill Exp $ */ | 1 | /* $NetBSD: thunk.h,v 1.11 2011/08/23 16:09:27 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -28,29 +28,34 @@ | @@ -28,29 +28,34 @@ | |||
28 | 28 | |||
29 | #ifndef _ARCH_USERMODE_INCLUDE_THUNK_H | 29 | #ifndef _ARCH_USERMODE_INCLUDE_THUNK_H | |
30 | #define _ARCH_USERMODE_INCLUDE_THUNK_H | 30 | #define _ARCH_USERMODE_INCLUDE_THUNK_H | |
31 | 31 | |||
32 | #include <sys/types.h> | 32 | #include <sys/types.h> | |
33 | #include <sys/time.h> | 33 | #include <sys/time.h> | |
34 | #include <sys/stat.h> | 34 | #include <sys/stat.h> | |
35 | #include <sys/fcntl.h> | 35 | #include <sys/fcntl.h> | |
36 | #include <sys/ucontext.h> | 36 | #include <sys/ucontext.h> | |
37 | #include <sys/signal.h> | 37 | #include <sys/signal.h> | |
38 | #include <sys/aio.h> | 38 | #include <sys/aio.h> | |
39 | #include <sys/mman.h> | 39 | #include <sys/mman.h> | |
40 | 40 | |||
41 | struct thunk_timeval { | |||
42 | int64_t tv_sec; | |||
43 | int32_t tv_usec; | |||
44 | }; | |||
45 | ||||
41 | int thunk_setitimer(int, const struct itimerval *, struct itimerval *); | 46 | int thunk_setitimer(int, const struct itimerval *, struct itimerval *); | |
42 | int thunk_gettimeofday(struct timeval *, void *); | 47 | int thunk_gettimeofday(struct thunk_timeval *, void *); | |
43 | int thunk_clock_gettime(clockid_t, struct timespec *); | 48 | unsigned int thunk_getcounter(void); | |
44 | long thunk_clock_getres_monotonic(void); | 49 | long thunk_clock_getres_monotonic(void); | |
45 | int thunk_usleep(useconds_t); | 50 | int thunk_usleep(useconds_t); | |
46 | 51 | |||
47 | void thunk_exit(int); | 52 | void thunk_exit(int); | |
48 | void thunk_abort(void); | 53 | void thunk_abort(void); | |
49 | 54 | |||
50 | int thunk_getcontext(ucontext_t *); | 55 | int thunk_getcontext(ucontext_t *); | |
51 | int thunk_setcontext(const ucontext_t *); | 56 | int thunk_setcontext(const ucontext_t *); | |
52 | void thunk_makecontext(ucontext_t *, void (*)(void), int, void (*)(void *), void *); | 57 | void thunk_makecontext(ucontext_t *, void (*)(void), int, void (*)(void *), void *); | |
53 | int thunk_swapcontext(ucontext_t *, ucontext_t *); | 58 | int thunk_swapcontext(ucontext_t *, ucontext_t *); | |
54 | 59 | |||
55 | int thunk_getchar(void); | 60 | int thunk_getchar(void); | |
56 | void thunk_putchar(int); | 61 | void thunk_putchar(int); |
--- src/sys/arch/usermode/usermode/thunk.c 2011/08/23 14:37:50 1.11
+++ src/sys/arch/usermode/usermode/thunk.c 2011/08/23 16:09:27 1.12
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: thunk.c,v 1.11 2011/08/23 14:37:50 jmcneill Exp $ */ | 1 | /* $NetBSD: thunk.c,v 1.12 2011/08/23 16:09:27 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -17,62 +17,81 @@ | @@ -17,62 +17,81 @@ | |||
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | 26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __RCSID("$NetBSD: thunk.c,v 1.11 2011/08/23 14:37:50 jmcneill Exp $"); | 30 | __RCSID("$NetBSD: thunk.c,v 1.12 2011/08/23 16:09:27 jmcneill Exp $"); | |
31 | 31 | |||
32 | #include <sys/types.h> | 32 | #include <sys/types.h> | |
33 | #include <sys/ansi.h> | 33 | #include <sys/ansi.h> | |
34 | 34 | |||
35 | #include <aio.h> | 35 | #include <aio.h> | |
36 | #include <assert.h> | 36 | #include <assert.h> | |
37 | #include <fcntl.h> | 37 | #include <fcntl.h> | |
38 | #include <stdarg.h> | 38 | #include <stdarg.h> | |
39 | #include <stdint.h> | 39 | #include <stdint.h> | |
40 | #include <stdio.h> | 40 | #include <stdio.h> | |
41 | #include <stdlib.h> | 41 | #include <stdlib.h> | |
42 | #include <signal.h> | 42 | #include <signal.h> | |
43 | #include <time.h> | 43 | #include <time.h> | |
44 | #include <ucontext.h> | 44 | #include <ucontext.h> | |
45 | #include <unistd.h> | 45 | #include <unistd.h> | |
46 | 46 | |||
47 | #include "../include/thunk.h" | 47 | #include "../include/thunk.h" | |
48 | 48 | |||
49 | int | 49 | int | |
50 | thunk_setitimer(int which, const struct itimerval *value, | 50 | thunk_setitimer(int which, const struct itimerval *value, | |
51 | struct itimerval *ovalue) | 51 | struct itimerval *ovalue) | |
52 | { | 52 | { | |
53 | return setitimer(which, value, ovalue); | 53 | return setitimer(which, value, ovalue); | |
54 | } | 54 | } | |
55 | 55 | |||
56 | int | 56 | int | |
57 | thunk_gettimeofday(struct timeval *tp, void *tzp) | 57 | thunk_gettimeofday(struct thunk_timeval *tp, void *tzp) | |
58 | { | 58 | { | |
59 | return gettimeofday(tp, tzp); | 59 | struct timeval tv; | |
60 | int error; | |||
61 | ||||
62 | error = gettimeofday(&tv, tzp); | |||
63 | if (error) | |||
64 | return error; | |||
65 | ||||
66 | tp->tv_sec = tv.tv_sec; | |||
67 | tp->tv_usec = tv.tv_usec; | |||
68 | ||||
69 | return 0; | |||
60 | } | 70 | } | |
61 | 71 | |||
62 | int | 72 | unsigned int | |
63 | thunk_clock_gettime(clockid_t clock_id, struct timespec *tp) | 73 | thunk_getcounter(void) | |
64 | { | 74 | { | |
65 | return clock_gettime(clock_id, tp); | 75 | struct timespec ts; | |
76 | int error; | |||
77 | ||||
78 | error = clock_gettime(CLOCK_MONOTONIC, &ts); | |||
79 | if (error) { | |||
80 | perror("clock_gettime CLOCK_MONOTONIC"); | |||
81 | abort(); | |||
82 | } | |||
83 | ||||
84 | return (unsigned int)(ts.tv_sec * 1000000000ULL + ts.tv_nsec); | |||
66 | } | 85 | } | |
67 | 86 | |||
68 | long | 87 | long | |
69 | thunk_clock_getres_monotonic(void) | 88 | thunk_clock_getres_monotonic(void) | |
70 | { | 89 | { | |
71 | struct timespec res; | 90 | struct timespec res; | |
72 | int error; | 91 | int error; | |
73 | 92 | |||
74 | error = clock_getres(CLOCK_MONOTONIC, &res); | 93 | error = clock_getres(CLOCK_MONOTONIC, &res); | |
75 | if (error) | 94 | if (error) | |
76 | return -1; | 95 | return -1; | |
77 | 96 | |||
78 | return res.tv_nsec; | 97 | return res.tv_nsec; |