kern_softint.c revision 1.1.6.3 1 1.1.6.3 jmcneill /* $NetBSD: kern_softint.c,v 1.1.6.3 2007/12/09 19:38:20 jmcneill Exp $ */
2 1.1.6.1 joerg
3 1.1.6.1 joerg /*-
4 1.1.6.1 joerg * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.1.6.1 joerg * All rights reserved.
6 1.1.6.1 joerg *
7 1.1.6.1 joerg * This code is derived from software contributed to The NetBSD Foundation
8 1.1.6.1 joerg * by Andrew Doran.
9 1.1.6.1 joerg *
10 1.1.6.1 joerg * Redistribution and use in source and binary forms, with or without
11 1.1.6.1 joerg * modification, are permitted provided that the following conditions
12 1.1.6.1 joerg * are met:
13 1.1.6.1 joerg * 1. Redistributions of source code must retain the above copyright
14 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer.
15 1.1.6.1 joerg * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer in the
17 1.1.6.1 joerg * documentation and/or other materials provided with the distribution.
18 1.1.6.1 joerg * 3. All advertising materials mentioning features or use of this software
19 1.1.6.1 joerg * must display the following acknowledgement:
20 1.1.6.1 joerg * This product includes software developed by the NetBSD
21 1.1.6.1 joerg * Foundation, Inc. and its contributors.
22 1.1.6.1 joerg * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.6.1 joerg * contributors may be used to endorse or promote products derived
24 1.1.6.1 joerg * from this software without specific prior written permission.
25 1.1.6.1 joerg *
26 1.1.6.1 joerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.6.1 joerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.6.1 joerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.6.1 joerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.6.1 joerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.6.1 joerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.6.1 joerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.6.1 joerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.6.1 joerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.6.1 joerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.6.1 joerg * POSSIBILITY OF SUCH DAMAGE.
37 1.1.6.1 joerg */
38 1.1.6.1 joerg
39 1.1.6.1 joerg /*
40 1.1.6.3 jmcneill * Generic software interrupt framework.
41 1.1.6.3 jmcneill *
42 1.1.6.3 jmcneill * Overview
43 1.1.6.3 jmcneill *
44 1.1.6.3 jmcneill * The soft interrupt framework provides a mechanism to schedule a
45 1.1.6.3 jmcneill * low priority callback that runs with thread context. It allows
46 1.1.6.3 jmcneill * for dynamic registration of software interrupts, and for fair
47 1.1.6.3 jmcneill * queueing and prioritization of those interrupts. The callbacks
48 1.1.6.3 jmcneill * can be scheduled to run from nearly any point in the kernel: by
49 1.1.6.3 jmcneill * code running with thread context, by code running from a
50 1.1.6.3 jmcneill * hardware interrupt handler, and at any interrupt priority
51 1.1.6.3 jmcneill * level.
52 1.1.6.3 jmcneill *
53 1.1.6.3 jmcneill * Priority levels
54 1.1.6.3 jmcneill *
55 1.1.6.3 jmcneill * Since soft interrupt dispatch can be tied to the underlying
56 1.1.6.3 jmcneill * architecture's interrupt dispatch code, it can be limited
57 1.1.6.3 jmcneill * both by the capabilities of the hardware and the capabilities
58 1.1.6.3 jmcneill * of the interrupt dispatch code itself. The number of priority
59 1.1.6.3 jmcneill * levels is restricted to four. In order of priority (lowest to
60 1.1.6.3 jmcneill * highest) the levels are: clock, bio, net, serial.
61 1.1.6.3 jmcneill *
62 1.1.6.3 jmcneill * The names are symbolic and in isolation do not have any direct
63 1.1.6.3 jmcneill * connection with a particular kind of device activity: they are
64 1.1.6.3 jmcneill * only meant as a guide.
65 1.1.6.3 jmcneill *
66 1.1.6.3 jmcneill * The four priority levels map directly to scheduler priority
67 1.1.6.3 jmcneill * levels, and where the architecture implements 'fast' software
68 1.1.6.3 jmcneill * interrupts, they also map onto interrupt priorities. The
69 1.1.6.3 jmcneill * interrupt priorities are intended to be hidden from machine
70 1.1.6.3 jmcneill * independent code, which should use thread-safe mechanisms to
71 1.1.6.3 jmcneill * synchronize with software interrupts (for example: mutexes).
72 1.1.6.3 jmcneill *
73 1.1.6.3 jmcneill * Capabilities
74 1.1.6.3 jmcneill *
75 1.1.6.3 jmcneill * Software interrupts run with limited machine context. In
76 1.1.6.3 jmcneill * particular, they do not posess any address space context. They
77 1.1.6.3 jmcneill * should not try to operate on user space addresses, or to use
78 1.1.6.3 jmcneill * virtual memory facilities other than those noted as interrupt
79 1.1.6.3 jmcneill * safe.
80 1.1.6.3 jmcneill *
81 1.1.6.3 jmcneill * Unlike hardware interrupts, software interrupts do have thread
82 1.1.6.3 jmcneill * context. They may block on synchronization objects, sleep, and
83 1.1.6.3 jmcneill * resume execution at a later time.
84 1.1.6.3 jmcneill *
85 1.1.6.3 jmcneill * Since software interrupts are a limited resource and run with
86 1.1.6.3 jmcneill * higher priority than most other LWPs in the system, all
87 1.1.6.3 jmcneill * block-and-resume activity by a software interrupt must be kept
88 1.1.6.3 jmcneill * short to allow futher processing at that level to continue. By
89 1.1.6.3 jmcneill * extension, code running with process context must take care to
90 1.1.6.3 jmcneill * ensure that any lock that may be taken from a software interrupt
91 1.1.6.3 jmcneill * can not be held for more than a short period of time.
92 1.1.6.3 jmcneill *
93 1.1.6.3 jmcneill * The kernel does not allow software interrupts to use facilities
94 1.1.6.3 jmcneill * or perform actions that may block for a significant amount of
95 1.1.6.3 jmcneill * time. This means that it's not valid for a software interrupt
96 1.1.6.3 jmcneill * to: sleep on condition variables, use the lockmgr() facility,
97 1.1.6.3 jmcneill * or wait for resources to become available (for example,
98 1.1.6.3 jmcneill * memory).
99 1.1.6.3 jmcneill *
100 1.1.6.3 jmcneill * Per-CPU operation
101 1.1.6.3 jmcneill *
102 1.1.6.3 jmcneill * If a soft interrupt is triggered on a CPU, it can only be
103 1.1.6.3 jmcneill * dispatched on the same CPU. Each LWP dedicated to handling a
104 1.1.6.3 jmcneill * soft interrupt is bound to its home CPU, so if the LWP blocks
105 1.1.6.3 jmcneill * and needs to run again, it can only run there. Nearly all data
106 1.1.6.3 jmcneill * structures used to manage software interrupts are per-CPU.
107 1.1.6.3 jmcneill *
108 1.1.6.3 jmcneill * The per-CPU requirement is intended to reduce "ping-pong" of
109 1.1.6.3 jmcneill * cache lines between CPUs: lines occupied by data structures
110 1.1.6.3 jmcneill * used to manage the soft interrupts, and lines occupied by data
111 1.1.6.3 jmcneill * items being passed down to the soft interrupt. As a positive
112 1.1.6.3 jmcneill * side effect, this also means that the soft interrupt dispatch
113 1.1.6.3 jmcneill * code does not need to to use spinlocks to synchronize.
114 1.1.6.3 jmcneill *
115 1.1.6.3 jmcneill * Generic implementation
116 1.1.6.3 jmcneill *
117 1.1.6.3 jmcneill * A generic, low performance implementation is provided that
118 1.1.6.3 jmcneill * works across all architectures, with no machine-dependent
119 1.1.6.3 jmcneill * modifications needed. This implementation uses the scheduler,
120 1.1.6.3 jmcneill * and so has a number of restrictions:
121 1.1.6.3 jmcneill *
122 1.1.6.3 jmcneill * 1) The software interrupts are not currently preemptive, so
123 1.1.6.3 jmcneill * must wait for the currently executing LWP to yield the CPU.
124 1.1.6.3 jmcneill * This can introduce latency.
125 1.1.6.3 jmcneill *
126 1.1.6.3 jmcneill * 2) An expensive context switch is required for a software
127 1.1.6.3 jmcneill * interrupt to be handled.
128 1.1.6.3 jmcneill *
129 1.1.6.3 jmcneill * 'Fast' software interrupts
130 1.1.6.3 jmcneill *
131 1.1.6.3 jmcneill * If an architectures defines __HAVE_FAST_SOFTINTS, it implements
132 1.1.6.3 jmcneill * the fast mechanism. Threads running either in the kernel or in
133 1.1.6.3 jmcneill * userspace will be interrupted, but will not be preempted. When
134 1.1.6.3 jmcneill * the soft interrupt completes execution, the interrupted LWP
135 1.1.6.3 jmcneill * is resumed. Interrupt dispatch code must provide the minimum
136 1.1.6.3 jmcneill * level of context necessary for the soft interrupt to block and
137 1.1.6.3 jmcneill * be resumed at a later time. The machine-dependent dispatch
138 1.1.6.3 jmcneill * path looks something like the following:
139 1.1.6.3 jmcneill *
140 1.1.6.3 jmcneill * softintr()
141 1.1.6.3 jmcneill * {
142 1.1.6.3 jmcneill * go to IPL_HIGH if necessary for switch;
143 1.1.6.3 jmcneill * save any necessary registers in a format that can be
144 1.1.6.3 jmcneill * restored by cpu_switchto if the softint blocks;
145 1.1.6.3 jmcneill * arrange for cpu_switchto() to restore into the
146 1.1.6.3 jmcneill * trampoline function;
147 1.1.6.3 jmcneill * identify LWP to handle this interrupt;
148 1.1.6.3 jmcneill * switch to the LWP's stack;
149 1.1.6.3 jmcneill * switch register stacks, if necessary;
150 1.1.6.3 jmcneill * assign new value of curlwp;
151 1.1.6.3 jmcneill * call MI softint_dispatch, passing old curlwp and IPL
152 1.1.6.3 jmcneill * to execute interrupt at;
153 1.1.6.3 jmcneill * switch back to old stack;
154 1.1.6.3 jmcneill * switch back to old register stack, if necessary;
155 1.1.6.3 jmcneill * restore curlwp;
156 1.1.6.3 jmcneill * return to interrupted LWP;
157 1.1.6.3 jmcneill * }
158 1.1.6.3 jmcneill *
159 1.1.6.3 jmcneill * If the soft interrupt blocks, a trampoline function is returned
160 1.1.6.3 jmcneill * to in the context of the interrupted LWP, as arranged for by
161 1.1.6.3 jmcneill * softint():
162 1.1.6.3 jmcneill *
163 1.1.6.3 jmcneill * softint_ret()
164 1.1.6.3 jmcneill * {
165 1.1.6.3 jmcneill * unlock soft interrupt LWP;
166 1.1.6.3 jmcneill * resume interrupt processing, likely returning to
167 1.1.6.3 jmcneill * interrupted LWP or dispatching another, different
168 1.1.6.3 jmcneill * interrupt;
169 1.1.6.3 jmcneill * }
170 1.1.6.3 jmcneill *
171 1.1.6.3 jmcneill * Once the soft interrupt has fired (and even if it has blocked),
172 1.1.6.3 jmcneill * no further soft interrupts at that level will be triggered by
173 1.1.6.3 jmcneill * MI code until the soft interrupt handler has ceased execution.
174 1.1.6.3 jmcneill * If a soft interrupt handler blocks and is resumed, it resumes
175 1.1.6.3 jmcneill * execution as a normal LWP (kthread) and gains VM context. Only
176 1.1.6.3 jmcneill * when it has completed and is ready to fire again will it
177 1.1.6.3 jmcneill * interrupt other threads.
178 1.1.6.3 jmcneill *
179 1.1.6.3 jmcneill * Future directions
180 1.1.6.3 jmcneill *
181 1.1.6.3 jmcneill * Provide a cheap way to direct software interrupts to remote
182 1.1.6.3 jmcneill * CPUs. Provide a way to enqueue work items into the handler
183 1.1.6.3 jmcneill * record, removing additional spl calls (see subr_workqueue.c).
184 1.1.6.1 joerg */
185 1.1.6.1 joerg
186 1.1.6.1 joerg #include <sys/cdefs.h>
187 1.1.6.3 jmcneill __KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.1.6.3 2007/12/09 19:38:20 jmcneill Exp $");
188 1.1.6.1 joerg
189 1.1.6.1 joerg #include <sys/param.h>
190 1.1.6.3 jmcneill #include <sys/malloc.h>
191 1.1.6.3 jmcneill #include <sys/proc.h>
192 1.1.6.1 joerg #include <sys/intr.h>
193 1.1.6.3 jmcneill #include <sys/mutex.h>
194 1.1.6.3 jmcneill #include <sys/kthread.h>
195 1.1.6.3 jmcneill #include <sys/evcnt.h>
196 1.1.6.3 jmcneill #include <sys/cpu.h>
197 1.1.6.3 jmcneill
198 1.1.6.3 jmcneill #include <net/netisr.h>
199 1.1.6.3 jmcneill
200 1.1.6.3 jmcneill #include <uvm/uvm_extern.h>
201 1.1.6.3 jmcneill
202 1.1.6.3 jmcneill /* This could overlap with signal info in struct lwp. */
203 1.1.6.3 jmcneill typedef struct softint {
204 1.1.6.3 jmcneill SIMPLEQ_HEAD(, softhand) si_q;
205 1.1.6.3 jmcneill struct lwp *si_lwp;
206 1.1.6.3 jmcneill struct cpu_info *si_cpu;
207 1.1.6.3 jmcneill uintptr_t si_machdep;
208 1.1.6.3 jmcneill struct evcnt si_evcnt;
209 1.1.6.3 jmcneill struct evcnt si_evcnt_block;
210 1.1.6.3 jmcneill int si_active;
211 1.1.6.3 jmcneill char si_name[8];
212 1.1.6.3 jmcneill char si_name_block[8+6];
213 1.1.6.3 jmcneill } softint_t;
214 1.1.6.3 jmcneill
215 1.1.6.3 jmcneill typedef struct softhand {
216 1.1.6.3 jmcneill SIMPLEQ_ENTRY(softhand) sh_q;
217 1.1.6.3 jmcneill void (*sh_func)(void *);
218 1.1.6.3 jmcneill void *sh_arg;
219 1.1.6.3 jmcneill softint_t *sh_isr;
220 1.1.6.3 jmcneill u_int sh_pending;
221 1.1.6.3 jmcneill u_int sh_flags;
222 1.1.6.3 jmcneill } softhand_t;
223 1.1.6.3 jmcneill
224 1.1.6.3 jmcneill typedef struct softcpu {
225 1.1.6.3 jmcneill struct cpu_info *sc_cpu;
226 1.1.6.3 jmcneill softint_t sc_int[SOFTINT_COUNT];
227 1.1.6.3 jmcneill softhand_t sc_hand[1];
228 1.1.6.3 jmcneill } softcpu_t;
229 1.1.6.3 jmcneill
230 1.1.6.3 jmcneill static void softint_thread(void *);
231 1.1.6.3 jmcneill
232 1.1.6.3 jmcneill u_int softint_bytes = 8192;
233 1.1.6.3 jmcneill u_int softint_timing;
234 1.1.6.3 jmcneill static u_int softint_max;
235 1.1.6.3 jmcneill static kmutex_t softint_lock;
236 1.1.6.3 jmcneill static void *softint_netisrs[32];
237 1.1.6.1 joerg
238 1.1.6.3 jmcneill /*
239 1.1.6.3 jmcneill * softint_init_isr:
240 1.1.6.3 jmcneill *
241 1.1.6.3 jmcneill * Initialize a single interrupt level for a single CPU.
242 1.1.6.3 jmcneill */
243 1.1.6.3 jmcneill static void
244 1.1.6.3 jmcneill softint_init_isr(softcpu_t *sc, const char *desc, pri_t pri, u_int level)
245 1.1.6.3 jmcneill {
246 1.1.6.3 jmcneill struct cpu_info *ci;
247 1.1.6.3 jmcneill softint_t *si;
248 1.1.6.3 jmcneill int error;
249 1.1.6.3 jmcneill
250 1.1.6.3 jmcneill si = &sc->sc_int[level];
251 1.1.6.3 jmcneill ci = sc->sc_cpu;
252 1.1.6.3 jmcneill si->si_cpu = ci;
253 1.1.6.3 jmcneill
254 1.1.6.3 jmcneill SIMPLEQ_INIT(&si->si_q);
255 1.1.6.3 jmcneill
256 1.1.6.3 jmcneill error = kthread_create(pri, KTHREAD_MPSAFE | KTHREAD_INTR |
257 1.1.6.3 jmcneill KTHREAD_IDLE, ci, softint_thread, si, &si->si_lwp,
258 1.1.6.3 jmcneill "soft%s/%d", desc, (int)ci->ci_cpuid);
259 1.1.6.3 jmcneill if (error != 0)
260 1.1.6.3 jmcneill panic("softint_init_isr: error %d", error);
261 1.1.6.3 jmcneill
262 1.1.6.3 jmcneill snprintf(si->si_name, sizeof(si->si_name), "%s/%d", desc,
263 1.1.6.3 jmcneill (int)ci->ci_cpuid);
264 1.1.6.3 jmcneill evcnt_attach_dynamic(&si->si_evcnt, EVCNT_TYPE_INTR, NULL,
265 1.1.6.3 jmcneill "softint", si->si_name);
266 1.1.6.3 jmcneill snprintf(si->si_name_block, sizeof(si->si_name_block), "%s block/%d",
267 1.1.6.3 jmcneill desc, (int)ci->ci_cpuid);
268 1.1.6.3 jmcneill evcnt_attach_dynamic(&si->si_evcnt_block, EVCNT_TYPE_INTR, NULL,
269 1.1.6.3 jmcneill "softint", si->si_name_block);
270 1.1.6.1 joerg
271 1.1.6.3 jmcneill si->si_lwp->l_private = si;
272 1.1.6.3 jmcneill softint_init_md(si->si_lwp, level, &si->si_machdep);
273 1.1.6.3 jmcneill }
274 1.1.6.1 joerg /*
275 1.1.6.1 joerg * softint_init:
276 1.1.6.1 joerg *
277 1.1.6.1 joerg * Initialize per-CPU data structures. Called from mi_cpu_attach().
278 1.1.6.1 joerg */
279 1.1.6.1 joerg void
280 1.1.6.1 joerg softint_init(struct cpu_info *ci)
281 1.1.6.1 joerg {
282 1.1.6.3 jmcneill static struct cpu_info *first;
283 1.1.6.3 jmcneill softcpu_t *sc, *scfirst;
284 1.1.6.3 jmcneill softhand_t *sh, *shmax;
285 1.1.6.3 jmcneill
286 1.1.6.3 jmcneill if (first == NULL) {
287 1.1.6.3 jmcneill /* Boot CPU. */
288 1.1.6.3 jmcneill first = ci;
289 1.1.6.3 jmcneill mutex_init(&softint_lock, MUTEX_DEFAULT, IPL_NONE);
290 1.1.6.3 jmcneill softint_bytes = round_page(softint_bytes);
291 1.1.6.3 jmcneill softint_max = (softint_bytes - sizeof(softcpu_t)) /
292 1.1.6.3 jmcneill sizeof(softhand_t);
293 1.1.6.3 jmcneill }
294 1.1.6.1 joerg
295 1.1.6.3 jmcneill sc = (softcpu_t *)uvm_km_alloc(kernel_map, softint_bytes, 0,
296 1.1.6.3 jmcneill UVM_KMF_WIRED | UVM_KMF_ZERO);
297 1.1.6.3 jmcneill if (sc == NULL)
298 1.1.6.3 jmcneill panic("softint_init_cpu: cannot allocate memory");
299 1.1.6.3 jmcneill
300 1.1.6.3 jmcneill ci->ci_data.cpu_softcpu = sc;
301 1.1.6.3 jmcneill ci->ci_data.cpu_softints = 0;
302 1.1.6.3 jmcneill sc->sc_cpu = ci;
303 1.1.6.3 jmcneill
304 1.1.6.3 jmcneill softint_init_isr(sc, "net", PRI_SOFTNET, SOFTINT_NET);
305 1.1.6.3 jmcneill softint_init_isr(sc, "bio", PRI_SOFTBIO, SOFTINT_BIO);
306 1.1.6.3 jmcneill softint_init_isr(sc, "clk", PRI_SOFTCLOCK, SOFTINT_CLOCK);
307 1.1.6.3 jmcneill softint_init_isr(sc, "ser", PRI_SOFTSERIAL, SOFTINT_SERIAL);
308 1.1.6.3 jmcneill
309 1.1.6.3 jmcneill if (first != ci) {
310 1.1.6.3 jmcneill mutex_enter(&softint_lock);
311 1.1.6.3 jmcneill scfirst = first->ci_data.cpu_softcpu;
312 1.1.6.3 jmcneill sh = sc->sc_hand;
313 1.1.6.3 jmcneill memcpy(sh, scfirst->sc_hand, sizeof(*sh) * softint_max);
314 1.1.6.3 jmcneill /* Update pointers for this CPU. */
315 1.1.6.3 jmcneill for (shmax = sh + softint_max; sh < shmax; sh++) {
316 1.1.6.3 jmcneill if (sh->sh_func == NULL)
317 1.1.6.3 jmcneill continue;
318 1.1.6.3 jmcneill sh->sh_isr =
319 1.1.6.3 jmcneill &sc->sc_int[sh->sh_flags & SOFTINT_LVLMASK];
320 1.1.6.3 jmcneill }
321 1.1.6.3 jmcneill mutex_exit(&softint_lock);
322 1.1.6.3 jmcneill } else {
323 1.1.6.3 jmcneill /*
324 1.1.6.3 jmcneill * Establish handlers for legacy net interrupts.
325 1.1.6.3 jmcneill * XXX Needs to go away.
326 1.1.6.3 jmcneill */
327 1.1.6.3 jmcneill #define DONETISR(n, f) \
328 1.1.6.3 jmcneill softint_netisrs[(n)] = \
329 1.1.6.3 jmcneill softint_establish(SOFTINT_NET, (void (*)(void *))(f), NULL)
330 1.1.6.3 jmcneill #include <net/netisr_dispatch.h>
331 1.1.6.3 jmcneill }
332 1.1.6.1 joerg }
333 1.1.6.1 joerg
334 1.1.6.1 joerg /*
335 1.1.6.1 joerg * softint_establish:
336 1.1.6.1 joerg *
337 1.1.6.1 joerg * Register a software interrupt handler.
338 1.1.6.1 joerg */
339 1.1.6.1 joerg void *
340 1.1.6.1 joerg softint_establish(u_int flags, void (*func)(void *), void *arg)
341 1.1.6.1 joerg {
342 1.1.6.3 jmcneill CPU_INFO_ITERATOR cii;
343 1.1.6.3 jmcneill struct cpu_info *ci;
344 1.1.6.3 jmcneill softcpu_t *sc;
345 1.1.6.3 jmcneill softhand_t *sh;
346 1.1.6.3 jmcneill u_int level, index;
347 1.1.6.1 joerg
348 1.1.6.1 joerg level = (flags & SOFTINT_LVLMASK);
349 1.1.6.1 joerg KASSERT(level < SOFTINT_COUNT);
350 1.1.6.1 joerg
351 1.1.6.3 jmcneill mutex_enter(&softint_lock);
352 1.1.6.3 jmcneill
353 1.1.6.3 jmcneill /* Find a free slot. */
354 1.1.6.3 jmcneill sc = curcpu()->ci_data.cpu_softcpu;
355 1.1.6.3 jmcneill for (index = 1; index < softint_max; index++)
356 1.1.6.3 jmcneill if (sc->sc_hand[index].sh_func == NULL)
357 1.1.6.3 jmcneill break;
358 1.1.6.3 jmcneill if (index == softint_max) {
359 1.1.6.3 jmcneill mutex_exit(&softint_lock);
360 1.1.6.3 jmcneill printf("WARNING: softint_establish: table full, "
361 1.1.6.3 jmcneill "increase softint_bytes\n");
362 1.1.6.3 jmcneill return NULL;
363 1.1.6.1 joerg }
364 1.1.6.1 joerg
365 1.1.6.3 jmcneill /* Set up the handler on each CPU. */
366 1.1.6.3 jmcneill for (CPU_INFO_FOREACH(cii, ci)) {
367 1.1.6.3 jmcneill sc = ci->ci_data.cpu_softcpu;
368 1.1.6.3 jmcneill sh = &sc->sc_hand[index];
369 1.1.6.3 jmcneill
370 1.1.6.3 jmcneill sh->sh_isr = &sc->sc_int[level];
371 1.1.6.3 jmcneill sh->sh_func = func;
372 1.1.6.3 jmcneill sh->sh_arg = arg;
373 1.1.6.3 jmcneill sh->sh_flags = flags;
374 1.1.6.3 jmcneill sh->sh_pending = 0;
375 1.1.6.3 jmcneill }
376 1.1.6.3 jmcneill
377 1.1.6.3 jmcneill mutex_exit(&softint_lock);
378 1.1.6.3 jmcneill
379 1.1.6.3 jmcneill return (void *)((uint8_t *)&sc->sc_hand[index] - (uint8_t *)sc);
380 1.1.6.1 joerg }
381 1.1.6.1 joerg
382 1.1.6.1 joerg /*
383 1.1.6.1 joerg * softint_disestablish:
384 1.1.6.1 joerg *
385 1.1.6.1 joerg * Unregister a software interrupt handler.
386 1.1.6.1 joerg */
387 1.1.6.1 joerg void
388 1.1.6.1 joerg softint_disestablish(void *arg)
389 1.1.6.1 joerg {
390 1.1.6.3 jmcneill CPU_INFO_ITERATOR cii;
391 1.1.6.3 jmcneill struct cpu_info *ci;
392 1.1.6.3 jmcneill softcpu_t *sc;
393 1.1.6.3 jmcneill softhand_t *sh;
394 1.1.6.3 jmcneill uintptr_t offset;
395 1.1.6.3 jmcneill
396 1.1.6.3 jmcneill offset = (uintptr_t)arg;
397 1.1.6.3 jmcneill KASSERT(offset != 0 && offset < softint_bytes);
398 1.1.6.3 jmcneill
399 1.1.6.3 jmcneill mutex_enter(&softint_lock);
400 1.1.6.3 jmcneill
401 1.1.6.3 jmcneill /* Clear the handler on each CPU. */
402 1.1.6.3 jmcneill for (CPU_INFO_FOREACH(cii, ci)) {
403 1.1.6.3 jmcneill sc = ci->ci_data.cpu_softcpu;
404 1.1.6.3 jmcneill sh = (softhand_t *)((uint8_t *)sc + offset);
405 1.1.6.3 jmcneill KASSERT(sh->sh_func != NULL);
406 1.1.6.3 jmcneill KASSERT(sh->sh_pending == 0);
407 1.1.6.3 jmcneill sh->sh_func = NULL;
408 1.1.6.3 jmcneill }
409 1.1.6.1 joerg
410 1.1.6.3 jmcneill mutex_exit(&softint_lock);
411 1.1.6.1 joerg }
412 1.1.6.1 joerg
413 1.1.6.1 joerg /*
414 1.1.6.1 joerg * softint_schedule:
415 1.1.6.1 joerg *
416 1.1.6.1 joerg * Trigger a software interrupt. Must be called from a hardware
417 1.1.6.1 joerg * interrupt handler, or with preemption disabled (since we are
418 1.1.6.1 joerg * using the value of curcpu()).
419 1.1.6.1 joerg */
420 1.1.6.1 joerg void
421 1.1.6.1 joerg softint_schedule(void *arg)
422 1.1.6.1 joerg {
423 1.1.6.3 jmcneill softhand_t *sh;
424 1.1.6.3 jmcneill softint_t *si;
425 1.1.6.3 jmcneill uintptr_t offset;
426 1.1.6.3 jmcneill int s;
427 1.1.6.3 jmcneill
428 1.1.6.3 jmcneill /* Find the handler record for this CPU. */
429 1.1.6.3 jmcneill offset = (uintptr_t)arg;
430 1.1.6.3 jmcneill KASSERT(offset != 0 && offset < softint_bytes);
431 1.1.6.3 jmcneill sh = (softhand_t *)((uint8_t *)curcpu()->ci_data.cpu_softcpu + offset);
432 1.1.6.3 jmcneill
433 1.1.6.3 jmcneill /* If it's already pending there's nothing to do. */
434 1.1.6.3 jmcneill if (sh->sh_pending)
435 1.1.6.3 jmcneill return;
436 1.1.6.3 jmcneill
437 1.1.6.3 jmcneill /*
438 1.1.6.3 jmcneill * Enqueue the handler into the LWP's pending list.
439 1.1.6.3 jmcneill * If the LWP is completely idle, then make it run.
440 1.1.6.3 jmcneill */
441 1.1.6.3 jmcneill s = splhigh();
442 1.1.6.3 jmcneill if (!sh->sh_pending) {
443 1.1.6.3 jmcneill si = sh->sh_isr;
444 1.1.6.3 jmcneill sh->sh_pending = 1;
445 1.1.6.3 jmcneill SIMPLEQ_INSERT_TAIL(&si->si_q, sh, sh_q);
446 1.1.6.3 jmcneill if (si->si_active == 0) {
447 1.1.6.3 jmcneill si->si_active = 1;
448 1.1.6.3 jmcneill softint_trigger(si->si_machdep);
449 1.1.6.3 jmcneill }
450 1.1.6.3 jmcneill }
451 1.1.6.3 jmcneill splx(s);
452 1.1.6.3 jmcneill }
453 1.1.6.3 jmcneill
454 1.1.6.3 jmcneill /*
455 1.1.6.3 jmcneill * softint_execute:
456 1.1.6.3 jmcneill *
457 1.1.6.3 jmcneill * Invoke handlers for the specified soft interrupt.
458 1.1.6.3 jmcneill * Must be entered at splhigh. Will drop the priority
459 1.1.6.3 jmcneill * to the level specified, but returns back at splhigh.
460 1.1.6.3 jmcneill */
461 1.1.6.3 jmcneill static inline void
462 1.1.6.3 jmcneill softint_execute(softint_t *si, lwp_t *l, int s)
463 1.1.6.3 jmcneill {
464 1.1.6.3 jmcneill softhand_t *sh;
465 1.1.6.3 jmcneill bool havelock;
466 1.1.6.3 jmcneill
467 1.1.6.3 jmcneill #ifdef __HAVE_FAST_SOFTINTS
468 1.1.6.3 jmcneill KASSERT(si->si_lwp == curlwp);
469 1.1.6.3 jmcneill #else
470 1.1.6.3 jmcneill /* May be running in user context. */
471 1.1.6.3 jmcneill #endif
472 1.1.6.3 jmcneill KASSERT(si->si_cpu == curcpu());
473 1.1.6.3 jmcneill KASSERT(si->si_lwp->l_wchan == NULL);
474 1.1.6.3 jmcneill KASSERT(si->si_active);
475 1.1.6.3 jmcneill
476 1.1.6.3 jmcneill havelock = false;
477 1.1.6.3 jmcneill
478 1.1.6.3 jmcneill /*
479 1.1.6.3 jmcneill * Note: due to priority inheritance we may have interrupted a
480 1.1.6.3 jmcneill * higher priority LWP. Since the soft interrupt must be quick
481 1.1.6.3 jmcneill * and is non-preemptable, we don't bother yielding.
482 1.1.6.3 jmcneill */
483 1.1.6.3 jmcneill
484 1.1.6.3 jmcneill while (!SIMPLEQ_EMPTY(&si->si_q)) {
485 1.1.6.3 jmcneill /*
486 1.1.6.3 jmcneill * Pick the longest waiting handler to run. We block
487 1.1.6.3 jmcneill * interrupts but do not lock in order to do this, as
488 1.1.6.3 jmcneill * we are protecting against the local CPU only.
489 1.1.6.3 jmcneill */
490 1.1.6.3 jmcneill sh = SIMPLEQ_FIRST(&si->si_q);
491 1.1.6.3 jmcneill SIMPLEQ_REMOVE_HEAD(&si->si_q, sh_q);
492 1.1.6.3 jmcneill sh->sh_pending = 0;
493 1.1.6.3 jmcneill splx(s);
494 1.1.6.3 jmcneill
495 1.1.6.3 jmcneill /* Run the handler. */
496 1.1.6.3 jmcneill if ((sh->sh_flags & SOFTINT_MPSAFE) == 0 && !havelock) {
497 1.1.6.3 jmcneill KERNEL_LOCK(1, l);
498 1.1.6.3 jmcneill havelock = true;
499 1.1.6.3 jmcneill }
500 1.1.6.3 jmcneill (*sh->sh_func)(sh->sh_arg);
501 1.1.6.3 jmcneill
502 1.1.6.3 jmcneill (void)splhigh();
503 1.1.6.3 jmcneill }
504 1.1.6.3 jmcneill
505 1.1.6.3 jmcneill if (havelock) {
506 1.1.6.3 jmcneill KERNEL_UNLOCK_ONE(l);
507 1.1.6.3 jmcneill }
508 1.1.6.3 jmcneill
509 1.1.6.3 jmcneill /*
510 1.1.6.3 jmcneill * Unlocked, but only for statistics.
511 1.1.6.3 jmcneill * Should be per-CPU to prevent cache ping-pong.
512 1.1.6.3 jmcneill */
513 1.1.6.3 jmcneill uvmexp.softs++;
514 1.1.6.1 joerg
515 1.1.6.3 jmcneill si->si_evcnt.ev_count++;
516 1.1.6.3 jmcneill si->si_active = 0;
517 1.1.6.1 joerg }
518 1.1.6.1 joerg
519 1.1.6.1 joerg /*
520 1.1.6.1 joerg * softint_block:
521 1.1.6.1 joerg *
522 1.1.6.1 joerg * Update statistics when the soft interrupt blocks.
523 1.1.6.1 joerg */
524 1.1.6.1 joerg void
525 1.1.6.1 joerg softint_block(lwp_t *l)
526 1.1.6.1 joerg {
527 1.1.6.3 jmcneill softint_t *si = l->l_private;
528 1.1.6.1 joerg
529 1.1.6.3 jmcneill KASSERT((l->l_pflag & LP_INTR) != 0);
530 1.1.6.3 jmcneill si->si_evcnt_block.ev_count++;
531 1.1.6.3 jmcneill }
532 1.1.6.3 jmcneill
533 1.1.6.3 jmcneill /*
534 1.1.6.3 jmcneill * schednetisr:
535 1.1.6.3 jmcneill *
536 1.1.6.3 jmcneill * Trigger a legacy network interrupt. XXX Needs to go away.
537 1.1.6.3 jmcneill */
538 1.1.6.3 jmcneill void
539 1.1.6.3 jmcneill schednetisr(int isr)
540 1.1.6.3 jmcneill {
541 1.1.6.3 jmcneill
542 1.1.6.3 jmcneill softint_schedule(softint_netisrs[isr]);
543 1.1.6.3 jmcneill }
544 1.1.6.3 jmcneill
545 1.1.6.3 jmcneill #ifndef __HAVE_FAST_SOFTINTS
546 1.1.6.3 jmcneill
547 1.1.6.3 jmcneill /*
548 1.1.6.3 jmcneill * softint_init_md:
549 1.1.6.3 jmcneill *
550 1.1.6.3 jmcneill * Slow path: perform machine-dependent initialization.
551 1.1.6.3 jmcneill */
552 1.1.6.3 jmcneill void
553 1.1.6.3 jmcneill softint_init_md(lwp_t *l, u_int level, uintptr_t *machdep)
554 1.1.6.3 jmcneill {
555 1.1.6.3 jmcneill softint_t *si;
556 1.1.6.3 jmcneill
557 1.1.6.3 jmcneill *machdep = (1 << level);
558 1.1.6.3 jmcneill si = l->l_private;
559 1.1.6.3 jmcneill
560 1.1.6.3 jmcneill lwp_lock(l);
561 1.1.6.3 jmcneill lwp_unlock_to(l, l->l_cpu->ci_schedstate.spc_mutex);
562 1.1.6.3 jmcneill lwp_lock(l);
563 1.1.6.3 jmcneill /* Cheat and make the KASSERT in softint_thread() happy. */
564 1.1.6.3 jmcneill si->si_active = 1;
565 1.1.6.3 jmcneill l->l_stat = LSRUN;
566 1.1.6.3 jmcneill sched_enqueue(l, false);
567 1.1.6.3 jmcneill lwp_unlock(l);
568 1.1.6.3 jmcneill }
569 1.1.6.3 jmcneill
570 1.1.6.3 jmcneill /*
571 1.1.6.3 jmcneill * softint_trigger:
572 1.1.6.3 jmcneill *
573 1.1.6.3 jmcneill * Slow path: cause a soft interrupt handler to begin executing.
574 1.1.6.3 jmcneill * Called at IPL_HIGH.
575 1.1.6.3 jmcneill */
576 1.1.6.3 jmcneill void
577 1.1.6.3 jmcneill softint_trigger(uintptr_t machdep)
578 1.1.6.3 jmcneill {
579 1.1.6.3 jmcneill struct cpu_info *ci;
580 1.1.6.3 jmcneill lwp_t *l;
581 1.1.6.3 jmcneill
582 1.1.6.3 jmcneill l = curlwp;
583 1.1.6.3 jmcneill ci = l->l_cpu;
584 1.1.6.3 jmcneill ci->ci_data.cpu_softints |= machdep;
585 1.1.6.3 jmcneill if (l == ci->ci_data.cpu_idlelwp) {
586 1.1.6.3 jmcneill cpu_need_resched(ci, 0);
587 1.1.6.3 jmcneill } else {
588 1.1.6.3 jmcneill /* MI equivalent of aston() */
589 1.1.6.3 jmcneill cpu_signotify(l);
590 1.1.6.3 jmcneill }
591 1.1.6.3 jmcneill }
592 1.1.6.3 jmcneill
593 1.1.6.3 jmcneill /*
594 1.1.6.3 jmcneill * softint_thread:
595 1.1.6.3 jmcneill *
596 1.1.6.3 jmcneill * Slow path: MI software interrupt dispatch.
597 1.1.6.3 jmcneill */
598 1.1.6.3 jmcneill void
599 1.1.6.3 jmcneill softint_thread(void *cookie)
600 1.1.6.3 jmcneill {
601 1.1.6.3 jmcneill softint_t *si;
602 1.1.6.3 jmcneill lwp_t *l;
603 1.1.6.3 jmcneill int s;
604 1.1.6.3 jmcneill
605 1.1.6.3 jmcneill l = curlwp;
606 1.1.6.3 jmcneill si = l->l_private;
607 1.1.6.3 jmcneill
608 1.1.6.3 jmcneill for (;;) {
609 1.1.6.3 jmcneill /*
610 1.1.6.3 jmcneill * Clear pending status and run it. We must drop the
611 1.1.6.3 jmcneill * spl before mi_switch(), since IPL_HIGH may be higher
612 1.1.6.3 jmcneill * than IPL_SCHED (and it is not safe to switch at a
613 1.1.6.3 jmcneill * higher level).
614 1.1.6.3 jmcneill */
615 1.1.6.3 jmcneill s = splhigh();
616 1.1.6.3 jmcneill l->l_cpu->ci_data.cpu_softints &= ~si->si_machdep;
617 1.1.6.3 jmcneill softint_execute(si, l, s);
618 1.1.6.3 jmcneill splx(s);
619 1.1.6.3 jmcneill
620 1.1.6.3 jmcneill lwp_lock(l);
621 1.1.6.3 jmcneill l->l_stat = LSIDL;
622 1.1.6.3 jmcneill mi_switch(l);
623 1.1.6.3 jmcneill }
624 1.1.6.1 joerg }
625 1.1.6.2 joerg
626 1.1.6.2 joerg /*
627 1.1.6.2 joerg * softint_picklwp:
628 1.1.6.2 joerg *
629 1.1.6.2 joerg * Slow path: called from mi_switch() to pick the highest priority
630 1.1.6.2 joerg * soft interrupt LWP that needs to run.
631 1.1.6.2 joerg */
632 1.1.6.2 joerg lwp_t *
633 1.1.6.2 joerg softint_picklwp(void)
634 1.1.6.2 joerg {
635 1.1.6.3 jmcneill struct cpu_info *ci;
636 1.1.6.3 jmcneill u_int mask;
637 1.1.6.3 jmcneill softint_t *si;
638 1.1.6.3 jmcneill lwp_t *l;
639 1.1.6.3 jmcneill
640 1.1.6.3 jmcneill ci = curcpu();
641 1.1.6.3 jmcneill si = ((softcpu_t *)ci->ci_data.cpu_softcpu)->sc_int;
642 1.1.6.3 jmcneill mask = ci->ci_data.cpu_softints;
643 1.1.6.3 jmcneill
644 1.1.6.3 jmcneill if ((mask & (1 << SOFTINT_SERIAL)) != 0) {
645 1.1.6.3 jmcneill l = si[SOFTINT_SERIAL].si_lwp;
646 1.1.6.3 jmcneill } else if ((mask & (1 << SOFTINT_NET)) != 0) {
647 1.1.6.3 jmcneill l = si[SOFTINT_NET].si_lwp;
648 1.1.6.3 jmcneill } else if ((mask & (1 << SOFTINT_BIO)) != 0) {
649 1.1.6.3 jmcneill l = si[SOFTINT_BIO].si_lwp;
650 1.1.6.3 jmcneill } else if ((mask & (1 << SOFTINT_CLOCK)) != 0) {
651 1.1.6.3 jmcneill l = si[SOFTINT_CLOCK].si_lwp;
652 1.1.6.3 jmcneill } else {
653 1.1.6.3 jmcneill panic("softint_picklwp");
654 1.1.6.3 jmcneill }
655 1.1.6.2 joerg
656 1.1.6.3 jmcneill return l;
657 1.1.6.2 joerg }
658 1.1.6.2 joerg
659 1.1.6.2 joerg /*
660 1.1.6.2 joerg * softint_overlay:
661 1.1.6.2 joerg *
662 1.1.6.2 joerg * Slow path: called from lwp_userret() to run a soft interrupt
663 1.1.6.3 jmcneill * within the context of a user thread.
664 1.1.6.2 joerg */
665 1.1.6.2 joerg void
666 1.1.6.2 joerg softint_overlay(void)
667 1.1.6.2 joerg {
668 1.1.6.3 jmcneill struct cpu_info *ci;
669 1.1.6.3 jmcneill u_int softints;
670 1.1.6.3 jmcneill softint_t *si;
671 1.1.6.3 jmcneill pri_t obase;
672 1.1.6.3 jmcneill lwp_t *l;
673 1.1.6.3 jmcneill int s;
674 1.1.6.3 jmcneill
675 1.1.6.3 jmcneill l = curlwp;
676 1.1.6.3 jmcneill ci = l->l_cpu;
677 1.1.6.3 jmcneill si = ((softcpu_t *)ci->ci_data.cpu_softcpu)->sc_int;
678 1.1.6.3 jmcneill
679 1.1.6.3 jmcneill KASSERT((l->l_pflag & LP_INTR) == 0);
680 1.1.6.3 jmcneill
681 1.1.6.3 jmcneill /* Arrange to elevate priority if the LWP blocks. */
682 1.1.6.3 jmcneill obase = l->l_kpribase;
683 1.1.6.3 jmcneill l->l_kpribase = PRI_KERNEL_RT;
684 1.1.6.3 jmcneill l->l_pflag |= LP_INTR;
685 1.1.6.3 jmcneill s = splhigh();
686 1.1.6.3 jmcneill while ((softints = ci->ci_data.cpu_softints) != 0) {
687 1.1.6.3 jmcneill if ((softints & (1 << SOFTINT_SERIAL)) != 0) {
688 1.1.6.3 jmcneill ci->ci_data.cpu_softints &= ~(1 << SOFTINT_SERIAL);
689 1.1.6.3 jmcneill softint_execute(&si[SOFTINT_SERIAL], l, s);
690 1.1.6.3 jmcneill continue;
691 1.1.6.3 jmcneill }
692 1.1.6.3 jmcneill if ((softints & (1 << SOFTINT_NET)) != 0) {
693 1.1.6.3 jmcneill ci->ci_data.cpu_softints &= ~(1 << SOFTINT_NET);
694 1.1.6.3 jmcneill softint_execute(&si[SOFTINT_NET], l, s);
695 1.1.6.3 jmcneill continue;
696 1.1.6.3 jmcneill }
697 1.1.6.3 jmcneill if ((softints & (1 << SOFTINT_BIO)) != 0) {
698 1.1.6.3 jmcneill ci->ci_data.cpu_softints &= ~(1 << SOFTINT_BIO);
699 1.1.6.3 jmcneill softint_execute(&si[SOFTINT_BIO], l, s);
700 1.1.6.3 jmcneill continue;
701 1.1.6.3 jmcneill }
702 1.1.6.3 jmcneill if ((softints & (1 << SOFTINT_CLOCK)) != 0) {
703 1.1.6.3 jmcneill ci->ci_data.cpu_softints &= ~(1 << SOFTINT_CLOCK);
704 1.1.6.3 jmcneill softint_execute(&si[SOFTINT_CLOCK], l, s);
705 1.1.6.3 jmcneill continue;
706 1.1.6.3 jmcneill }
707 1.1.6.3 jmcneill }
708 1.1.6.3 jmcneill splx(s);
709 1.1.6.3 jmcneill l->l_pflag &= ~LP_INTR;
710 1.1.6.3 jmcneill l->l_kpribase = obase;
711 1.1.6.3 jmcneill }
712 1.1.6.2 joerg
713 1.1.6.3 jmcneill #else /* !__HAVE_FAST_SOFTINTS */
714 1.1.6.3 jmcneill
715 1.1.6.3 jmcneill /*
716 1.1.6.3 jmcneill * softint_thread:
717 1.1.6.3 jmcneill *
718 1.1.6.3 jmcneill * Fast path: the LWP is switched to without restoring any state,
719 1.1.6.3 jmcneill * so we should not arrive here - there is a direct handoff between
720 1.1.6.3 jmcneill * the interrupt stub and softint_dispatch().
721 1.1.6.3 jmcneill */
722 1.1.6.3 jmcneill void
723 1.1.6.3 jmcneill softint_thread(void *cookie)
724 1.1.6.3 jmcneill {
725 1.1.6.3 jmcneill
726 1.1.6.3 jmcneill panic("softint_thread");
727 1.1.6.2 joerg }
728 1.1.6.2 joerg
729 1.1.6.2 joerg /*
730 1.1.6.3 jmcneill * softint_dispatch:
731 1.1.6.2 joerg *
732 1.1.6.3 jmcneill * Fast path: entry point from machine-dependent code.
733 1.1.6.2 joerg */
734 1.1.6.3 jmcneill void
735 1.1.6.3 jmcneill softint_dispatch(lwp_t *pinned, int s)
736 1.1.6.2 joerg {
737 1.1.6.3 jmcneill struct timeval now;
738 1.1.6.3 jmcneill softint_t *si;
739 1.1.6.3 jmcneill u_int timing;
740 1.1.6.3 jmcneill lwp_t *l;
741 1.1.6.3 jmcneill
742 1.1.6.3 jmcneill l = curlwp;
743 1.1.6.3 jmcneill si = l->l_private;
744 1.1.6.3 jmcneill
745 1.1.6.3 jmcneill /*
746 1.1.6.3 jmcneill * Note the interrupted LWP, and mark the current LWP as running
747 1.1.6.3 jmcneill * before proceeding. Although this must as a rule be done with
748 1.1.6.3 jmcneill * the LWP locked, at this point no external agents will want to
749 1.1.6.3 jmcneill * modify the interrupt LWP's state.
750 1.1.6.3 jmcneill */
751 1.1.6.3 jmcneill timing = (softint_timing ? LW_TIMEINTR : 0);
752 1.1.6.3 jmcneill l->l_switchto = pinned;
753 1.1.6.3 jmcneill l->l_stat = LSONPROC;
754 1.1.6.3 jmcneill l->l_flag |= (LW_RUNNING | timing);
755 1.1.6.3 jmcneill
756 1.1.6.3 jmcneill /*
757 1.1.6.3 jmcneill * Dispatch the interrupt. If softints are being timed, charge
758 1.1.6.3 jmcneill * for it.
759 1.1.6.3 jmcneill */
760 1.1.6.3 jmcneill if (timing)
761 1.1.6.3 jmcneill microtime(&l->l_stime);
762 1.1.6.3 jmcneill softint_execute(si, l, s);
763 1.1.6.3 jmcneill if (timing) {
764 1.1.6.3 jmcneill microtime(&now);
765 1.1.6.3 jmcneill updatertime(l, &now);
766 1.1.6.3 jmcneill l->l_flag &= ~LW_TIMEINTR;
767 1.1.6.3 jmcneill }
768 1.1.6.2 joerg
769 1.1.6.3 jmcneill /*
770 1.1.6.3 jmcneill * If we blocked while handling the interrupt, the pinned LWP is
771 1.1.6.3 jmcneill * gone so switch to the idle LWP. It will select a new LWP to
772 1.1.6.3 jmcneill * run.
773 1.1.6.3 jmcneill *
774 1.1.6.3 jmcneill * We must drop the priority level as switching at IPL_HIGH could
775 1.1.6.3 jmcneill * deadlock the system. We have already set si->si_active = 0,
776 1.1.6.3 jmcneill * which means another interrupt at this level can be triggered.
777 1.1.6.3 jmcneill * That's not be a problem: we are lowering to level 's' which will
778 1.1.6.3 jmcneill * prevent softint_dispatch() from being reentered at level 's',
779 1.1.6.3 jmcneill * until the priority is finally dropped to IPL_NONE on entry to
780 1.1.6.3 jmcneill * the idle loop.
781 1.1.6.3 jmcneill */
782 1.1.6.3 jmcneill l->l_stat = LSIDL;
783 1.1.6.3 jmcneill if (l->l_switchto == NULL) {
784 1.1.6.3 jmcneill splx(s);
785 1.1.6.3 jmcneill pmap_deactivate(l);
786 1.1.6.3 jmcneill lwp_exit_switchaway(l);
787 1.1.6.3 jmcneill /* NOTREACHED */
788 1.1.6.3 jmcneill }
789 1.1.6.3 jmcneill l->l_switchto = NULL;
790 1.1.6.3 jmcneill l->l_flag &= ~LW_RUNNING;
791 1.1.6.2 joerg }
792 1.1.6.3 jmcneill
793 1.1.6.3 jmcneill #endif /* !__HAVE_FAST_SOFTINTS */
794