Fri Dec 9 17:23:33 2011 UTC ()
Restructure dev/clock to run from the signal stack since its safe to do now.


(reinoud)
diff -r1.20 -r1.21 src/sys/arch/usermode/dev/clock.c

cvs diff -r1.20 -r1.21 src/sys/arch/usermode/dev/clock.c (expand / switch to unified diff)

--- src/sys/arch/usermode/dev/clock.c 2011/09/17 21:38:15 1.20
+++ src/sys/arch/usermode/dev/clock.c 2011/12/09 17:23:33 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: clock.c,v 1.20 2011/09/17 21:38:15 reinoud Exp $ */ 1/* $NetBSD: clock.c,v 1.21 2011/12/09 17:23:33 reinoud 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,66 +17,73 @@ @@ -17,66 +17,73 @@
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.20 2011/09/17 21:38:15 reinoud Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.21 2011/12/09 17:23:33 reinoud 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/lwp.h>
 37#include <sys/cpu.h>
 38#include <sys/malloc.h>
36#include <sys/timetc.h> 39#include <sys/timetc.h>
37#include <sys/time.h> 40#include <sys/time.h>
38 41
 42#include <machine/pcb.h>
39#include <machine/mainbus.h> 43#include <machine/mainbus.h>
40#include <machine/thunk.h> 44#include <machine/thunk.h>
41 45
42#include <dev/clock_subr.h> 46#include <dev/clock_subr.h>
43 47
44static int clock_match(device_t, cfdata_t, void *); 48static int clock_match(device_t, cfdata_t, void *);
45static void clock_attach(device_t, device_t, void *); 49static void clock_attach(device_t, device_t, void *);
46 50
 51static void clock(void);
47static void clock_signal(int sig, siginfo_t *info, void *ctx); 52static void clock_signal(int sig, siginfo_t *info, void *ctx);
48static unsigned int clock_getcounter(struct timecounter *); 53static unsigned int clock_getcounter(struct timecounter *);
49 54
50static int clock_todr_gettime(struct todr_chip_handle *, struct timeval *); 55static int clock_todr_gettime(struct todr_chip_handle *, struct timeval *);
51 56
52typedef struct clock_softc { 57typedef struct clock_softc {
53 device_t sc_dev; 58 device_t sc_dev;
54 struct todr_chip_handle sc_todr; 59 struct todr_chip_handle sc_todr;
55} clock_softc_t; 60} clock_softc_t;
56 61
57static struct timecounter clock_timecounter = { 62static struct timecounter clock_timecounter = {
58 clock_getcounter, /* get_timecount */ 63 clock_getcounter, /* get_timecount */
59 0, /* no poll_pps */ 64 0, /* no poll_pps */
60 ~0u, /* counter_mask */ 65 ~0u, /* counter_mask */
61 0, /* frequency */ 66 0, /* frequency */
62 "CLOCK_MONOTONIC", /* name */ 67 "CLOCK_MONOTONIC", /* name */
63 -100, /* quality */ 68 -100, /* quality */
64 NULL, /* prev */ 69 NULL, /* prev */
65 NULL, /* next */ 70 NULL, /* next */
66}; 71};
67 72
68static struct clock_softc *clock_sc; 73static struct clock_softc *clock_sc;
69 74
 75
 76
70CFATTACH_DECL_NEW(clock, sizeof(clock_softc_t), 77CFATTACH_DECL_NEW(clock, sizeof(clock_softc_t),
71 clock_match, clock_attach, NULL, NULL); 78 clock_match, clock_attach, NULL, NULL);
72 79
73static int 80static int
74clock_match(device_t parent, cfdata_t match, void *opaque) 81clock_match(device_t parent, cfdata_t match, void *opaque)
75{ 82{
76 struct thunkbus_attach_args *taa = opaque; 83 struct thunkbus_attach_args *taa = opaque;
77 84
78 if (taa->taa_type != THUNKBUS_TYPE_CLOCK) 85 if (taa->taa_type != THUNKBUS_TYPE_CLOCK)
79 return 0; 86 return 0;
80 87
81 return 1; 88 return 1;
82} 89}
@@ -92,52 +99,67 @@ clock_attach(device_t parent, device_t s @@ -92,52 +99,67 @@ clock_attach(device_t parent, device_t s
92 aprint_normal("\n"); 99 aprint_normal("\n");
93 100
94 KASSERT(clock_sc == NULL); 101 KASSERT(clock_sc == NULL);
95 clock_sc = sc; 102 clock_sc = sc;
96 103
97 sc->sc_dev = self; 104 sc->sc_dev = self;
98 105
99 sc->sc_todr.todr_gettime = clock_todr_gettime; 106 sc->sc_todr.todr_gettime = clock_todr_gettime;
100 todr_attach(&sc->sc_todr); 107 todr_attach(&sc->sc_todr);
101 108
102 memset(&sa, 0, sizeof(sa)); 109 memset(&sa, 0, sizeof(sa));
103 thunk_sigemptyset(&sa.sa_mask); 110 thunk_sigemptyset(&sa.sa_mask);
104 sa.sa_sigaction = clock_signal; 111 sa.sa_sigaction = clock_signal;
105 sa.sa_flags = SA_SIGINFO; 112 sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
106 if (thunk_sigaction(SIGALRM, &sa, NULL) == -1) 113 if (thunk_sigaction(SIGALRM, &sa, NULL) == -1)
107 panic("couldn't register SIGALRM handler : %d", 114 panic("couldn't register SIGALRM handler : %d",
108 thunk_geterrno()); 115 thunk_geterrno());
109 116
110 tcres = thunk_clock_getres_monotonic(); 117 tcres = thunk_clock_getres_monotonic();
111 if (tcres > 0) { 118 if (tcres > 0) {
112 clock_timecounter.tc_quality = 1000; 119 clock_timecounter.tc_quality = 1000;
113 clock_timecounter.tc_frequency = 1000000000 / tcres; 120 clock_timecounter.tc_frequency = 1000000000 / tcres;
114 } 121 }
115 tc_init(&clock_timecounter); 122 tc_init(&clock_timecounter);
116} 123}
117 124
118static void 125static void
119clock_signal(int sig, siginfo_t *info, void *ctx) 126clock(void)
120{ 127{
121 struct clockframe cf; 128 struct clockframe cf;
122 129
123 curcpu()->ci_idepth++; 130 curcpu()->ci_idepth++;
124 
125 spl_intr(IPL_SOFTCLOCK, (void (*)(void *)) hardclock, &cf); 131 spl_intr(IPL_SOFTCLOCK, (void (*)(void *)) hardclock, &cf);
126 // hardclock(&cf); 
127 
128 curcpu()->ci_idepth--; 132 curcpu()->ci_idepth--;
129} 133}
130 134
 135static void
 136clock_signal(int sig, siginfo_t *info, void *ctx)
 137{
 138#if 0
 139 ucontext_t *uct = ctx;
 140 struct lwp *l;
 141 struct pcb *pcb;
 142
 143 l = curlwp;
 144 pcb = lwp_getpcb(l);
 145
 146 /* copy this state as where the lwp was XXX NEEDED? */
 147 memcpy(&pcb->pcb_ucp, uct, sizeof(ucontext_t));
 148#endif
 149
 150 clock();
 151}
 152
131static unsigned int 153static unsigned int
132clock_getcounter(struct timecounter *tc) 154clock_getcounter(struct timecounter *tc)
133{ 155{
134 return thunk_getcounter(); 156 return thunk_getcounter();
135} 157}
136 158
137static int 159static int
138clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv) 160clock_todr_gettime(struct todr_chip_handle *tch, struct timeval *tv)
139{ 161{
140 struct thunk_timeval ttv; 162 struct thunk_timeval ttv;
141 int error; 163 int error;
142 164
143 error = thunk_gettimeofday(&ttv, NULL); 165 error = thunk_gettimeofday(&ttv, NULL);