xref: /freebsd/sys/kern/kern_intr.c (revision 71fad9fdeefd5d874768802125f98ea6450cfa5c)
1425f9fdaSStefan Eßer /*
2425f9fdaSStefan Eßer  * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
3425f9fdaSStefan Eßer  * All rights reserved.
4425f9fdaSStefan Eßer  *
5425f9fdaSStefan Eßer  * Redistribution and use in source and binary forms, with or without
6425f9fdaSStefan Eßer  * modification, are permitted provided that the following conditions
7425f9fdaSStefan Eßer  * are met:
8425f9fdaSStefan Eßer  * 1. Redistributions of source code must retain the above copyright
9425f9fdaSStefan Eßer  *    notice unmodified, this list of conditions, and the following
10425f9fdaSStefan Eßer  *    disclaimer.
11425f9fdaSStefan Eßer  * 2. Redistributions in binary form must reproduce the above copyright
12425f9fdaSStefan Eßer  *    notice, this list of conditions and the following disclaimer in the
13425f9fdaSStefan Eßer  *    documentation and/or other materials provided with the distribution.
14425f9fdaSStefan Eßer  *
15425f9fdaSStefan Eßer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16425f9fdaSStefan Eßer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17425f9fdaSStefan Eßer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18425f9fdaSStefan Eßer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19425f9fdaSStefan Eßer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20425f9fdaSStefan Eßer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21425f9fdaSStefan Eßer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22425f9fdaSStefan Eßer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23425f9fdaSStefan Eßer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24425f9fdaSStefan Eßer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25425f9fdaSStefan Eßer  *
26c3aac50fSPeter Wemm  * $FreeBSD$
27425f9fdaSStefan Eßer  *
28425f9fdaSStefan Eßer  */
29425f9fdaSStefan Eßer 
303900ddb2SDoug Rabson 
311c5bb3eaSPeter Wemm #include <sys/param.h>
329a94c9c5SJohn Baldwin #include <sys/bus.h>
339a94c9c5SJohn Baldwin #include <sys/rtprio.h>
34425f9fdaSStefan Eßer #include <sys/systm.h>
3568352337SDoug Rabson #include <sys/interrupt.h>
361931cf94SJohn Baldwin #include <sys/kernel.h>
371931cf94SJohn Baldwin #include <sys/kthread.h>
381931cf94SJohn Baldwin #include <sys/ktr.h>
39f34fa851SJohn Baldwin #include <sys/lock.h>
401931cf94SJohn Baldwin #include <sys/malloc.h>
4135e0e5b3SJohn Baldwin #include <sys/mutex.h>
421931cf94SJohn Baldwin #include <sys/proc.h>
433e5da754SJohn Baldwin #include <sys/random.h>
44b4151f71SJohn Baldwin #include <sys/resourcevar.h>
45d279178dSThomas Moestl #include <sys/sysctl.h>
461931cf94SJohn Baldwin #include <sys/unistd.h>
471931cf94SJohn Baldwin #include <sys/vmmeter.h>
481931cf94SJohn Baldwin #include <machine/atomic.h>
491931cf94SJohn Baldwin #include <machine/cpu.h>
508088699fSJohn Baldwin #include <machine/md_var.h>
51b4151f71SJohn Baldwin #include <machine/stdarg.h>
52425f9fdaSStefan Eßer 
538088699fSJohn Baldwin #include <net/netisr.h>		/* prototype for legacy_setsoftnet */
5418c5a6c4SBruce Evans 
553e5da754SJohn Baldwin struct	int_entropy {
563e5da754SJohn Baldwin 	struct	proc *proc;
573e5da754SJohn Baldwin 	int	vector;
583e5da754SJohn Baldwin };
593e5da754SJohn Baldwin 
60b4151f71SJohn Baldwin void	*net_ih;
61b4151f71SJohn Baldwin void	*vm_ih;
62b4151f71SJohn Baldwin void	*softclock_ih;
638088699fSJohn Baldwin struct	ithd *clk_ithd;
648088699fSJohn Baldwin struct	ithd *tty_ithd;
651931cf94SJohn Baldwin 
66b4151f71SJohn Baldwin static MALLOC_DEFINE(M_ITHREAD, "ithread", "Interrupt Threads");
67b4151f71SJohn Baldwin 
68b4151f71SJohn Baldwin static void	ithread_update(struct ithd *);
69b4151f71SJohn Baldwin static void	ithread_loop(void *);
701931cf94SJohn Baldwin static void	start_softintr(void *);
718088699fSJohn Baldwin static void	swi_net(void *);
7218c5a6c4SBruce Evans 
73b4151f71SJohn Baldwin u_char
74b4151f71SJohn Baldwin ithread_priority(enum intr_type flags)
759a94c9c5SJohn Baldwin {
76b4151f71SJohn Baldwin 	u_char pri;
779a94c9c5SJohn Baldwin 
78b4151f71SJohn Baldwin 	flags &= (INTR_TYPE_TTY | INTR_TYPE_BIO | INTR_TYPE_NET |
795a280d9cSPeter Wemm 	    INTR_TYPE_CAM | INTR_TYPE_MISC | INTR_TYPE_CLK | INTR_TYPE_AV);
809a94c9c5SJohn Baldwin 	switch (flags) {
81b4151f71SJohn Baldwin 	case INTR_TYPE_TTY:
829a94c9c5SJohn Baldwin 		pri = PI_TTYLOW;
839a94c9c5SJohn Baldwin 		break;
849a94c9c5SJohn Baldwin 	case INTR_TYPE_BIO:
859a94c9c5SJohn Baldwin 		/*
869a94c9c5SJohn Baldwin 		 * XXX We need to refine this.  BSD/OS distinguishes
879a94c9c5SJohn Baldwin 		 * between tape and disk priorities.
889a94c9c5SJohn Baldwin 		 */
899a94c9c5SJohn Baldwin 		pri = PI_DISK;
909a94c9c5SJohn Baldwin 		break;
919a94c9c5SJohn Baldwin 	case INTR_TYPE_NET:
929a94c9c5SJohn Baldwin 		pri = PI_NET;
939a94c9c5SJohn Baldwin 		break;
949a94c9c5SJohn Baldwin 	case INTR_TYPE_CAM:
959a94c9c5SJohn Baldwin 		pri = PI_DISK;          /* XXX or PI_CAM? */
969a94c9c5SJohn Baldwin 		break;
975a280d9cSPeter Wemm 	case INTR_TYPE_AV:		/* Audio/video */
985a280d9cSPeter Wemm 		pri = PI_AV;
995a280d9cSPeter Wemm 		break;
100b4151f71SJohn Baldwin 	case INTR_TYPE_CLK:
101b4151f71SJohn Baldwin 		pri = PI_REALTIME;
102b4151f71SJohn Baldwin 		break;
1039a94c9c5SJohn Baldwin 	case INTR_TYPE_MISC:
1049a94c9c5SJohn Baldwin 		pri = PI_DULL;          /* don't care */
1059a94c9c5SJohn Baldwin 		break;
1069a94c9c5SJohn Baldwin 	default:
107b4151f71SJohn Baldwin 		/* We didn't specify an interrupt level. */
1089a94c9c5SJohn Baldwin 		panic("ithread_priority: no interrupt type in flags");
1099a94c9c5SJohn Baldwin 	}
1109a94c9c5SJohn Baldwin 
1119a94c9c5SJohn Baldwin 	return pri;
1129a94c9c5SJohn Baldwin }
1139a94c9c5SJohn Baldwin 
114b4151f71SJohn Baldwin /*
115b4151f71SJohn Baldwin  * Regenerate the name (p_comm) and priority for a threaded interrupt thread.
116b4151f71SJohn Baldwin  */
117b4151f71SJohn Baldwin static void
118b4151f71SJohn Baldwin ithread_update(struct ithd *ithd)
119b4151f71SJohn Baldwin {
120b4151f71SJohn Baldwin 	struct intrhand *ih;
121b40ce416SJulian Elischer 	struct thread *td;
122b4151f71SJohn Baldwin 	struct proc *p;
123b4151f71SJohn Baldwin 	int entropy;
1248088699fSJohn Baldwin 
1254d29cb2dSJohn Baldwin 	mtx_assert(&ithd->it_lock, MA_OWNED);
126b40ce416SJulian Elischer 	td = ithd->it_td;
127b40ce416SJulian Elischer 	if (td == NULL)
128b4151f71SJohn Baldwin 		return;
129b40ce416SJulian Elischer 	p = td->td_proc;
130b4151f71SJohn Baldwin 
131b4151f71SJohn Baldwin 	strncpy(p->p_comm, ithd->it_name, sizeof(ithd->it_name));
132b4151f71SJohn Baldwin 	ih = TAILQ_FIRST(&ithd->it_handlers);
133b4151f71SJohn Baldwin 	if (ih == NULL) {
134b106d2f5SJohn Baldwin 		mtx_lock_spin(&sched_lock);
1352c100766SJulian Elischer 		td->td_priority = PRI_MAX_ITHD;
136b106d2f5SJohn Baldwin 		td->td_base_pri = PRI_MAX_ITHD;
137b106d2f5SJohn Baldwin 		mtx_unlock_spin(&sched_lock);
138b4151f71SJohn Baldwin 		ithd->it_flags &= ~IT_ENTROPY;
139b4151f71SJohn Baldwin 		return;
140b4151f71SJohn Baldwin 	}
141b4151f71SJohn Baldwin 	entropy = 0;
142b106d2f5SJohn Baldwin 	mtx_lock_spin(&sched_lock);
1432c100766SJulian Elischer 	td->td_priority = ih->ih_pri;
1442c100766SJulian Elischer 	td->td_base_pri = ih->ih_pri;
145b106d2f5SJohn Baldwin 	mtx_unlock_spin(&sched_lock);
146b4151f71SJohn Baldwin 	TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) {
147b4151f71SJohn Baldwin 		if (strlen(p->p_comm) + strlen(ih->ih_name) + 1 <
148b4151f71SJohn Baldwin 		    sizeof(p->p_comm)) {
149b4151f71SJohn Baldwin 			strcat(p->p_comm, " ");
150b4151f71SJohn Baldwin 			strcat(p->p_comm, ih->ih_name);
151b4151f71SJohn Baldwin 		} else if (strlen(p->p_comm) + 1 == sizeof(p->p_comm)) {
152b4151f71SJohn Baldwin 			if (p->p_comm[sizeof(p->p_comm) - 2] == '+')
153b4151f71SJohn Baldwin 				p->p_comm[sizeof(p->p_comm) - 2] = '*';
154b4151f71SJohn Baldwin 			else
155b4151f71SJohn Baldwin 				p->p_comm[sizeof(p->p_comm) - 2] = '+';
156b4151f71SJohn Baldwin 		} else
157b4151f71SJohn Baldwin 			strcat(p->p_comm, "+");
158b4151f71SJohn Baldwin 		if (ih->ih_flags & IH_ENTROPY)
159b4151f71SJohn Baldwin 			entropy++;
160b4151f71SJohn Baldwin 	}
1613e5da754SJohn Baldwin 	if (entropy)
162b4151f71SJohn Baldwin 		ithd->it_flags |= IT_ENTROPY;
163b4151f71SJohn Baldwin 	else
164b4151f71SJohn Baldwin 		ithd->it_flags &= ~IT_ENTROPY;
16591f91617SDavid E. O'Brien 	CTR2(KTR_INTR, "%s: updated %s\n", __func__, p->p_comm);
166b4151f71SJohn Baldwin }
167b4151f71SJohn Baldwin 
168b4151f71SJohn Baldwin int
169b4151f71SJohn Baldwin ithread_create(struct ithd **ithread, int vector, int flags,
170b4151f71SJohn Baldwin     void (*disable)(int), void (*enable)(int), const char *fmt, ...)
171b4151f71SJohn Baldwin {
172b4151f71SJohn Baldwin 	struct ithd *ithd;
173b40ce416SJulian Elischer 	struct thread *td;
174b4151f71SJohn Baldwin 	struct proc *p;
175b4151f71SJohn Baldwin 	int error;
176b4151f71SJohn Baldwin 	va_list ap;
177b4151f71SJohn Baldwin 
1783e5da754SJohn Baldwin 	/* The only valid flag during creation is IT_SOFT. */
1793e5da754SJohn Baldwin 	if ((flags & ~IT_SOFT) != 0)
1803e5da754SJohn Baldwin 		return (EINVAL);
1813e5da754SJohn Baldwin 
182b4151f71SJohn Baldwin 	ithd = malloc(sizeof(struct ithd), M_ITHREAD, M_WAITOK | M_ZERO);
183b4151f71SJohn Baldwin 	ithd->it_vector = vector;
184b4151f71SJohn Baldwin 	ithd->it_disable = disable;
185b4151f71SJohn Baldwin 	ithd->it_enable = enable;
186b4151f71SJohn Baldwin 	ithd->it_flags = flags;
187b4151f71SJohn Baldwin 	TAILQ_INIT(&ithd->it_handlers);
1886008862bSJohn Baldwin 	mtx_init(&ithd->it_lock, "ithread", NULL, MTX_DEF);
189b4151f71SJohn Baldwin 
190b4151f71SJohn Baldwin 	va_start(ap, fmt);
191b4151f71SJohn Baldwin 	vsnprintf(ithd->it_name, sizeof(ithd->it_name), fmt, ap);
192b4151f71SJohn Baldwin 	va_end(ap);
193b4151f71SJohn Baldwin 
194b4151f71SJohn Baldwin 	error = kthread_create(ithread_loop, ithd, &p, RFSTOPPED | RFHIGHPID,
1951f723035SJohn Baldwin 	    "%s", ithd->it_name);
196b4151f71SJohn Baldwin 	if (error) {
1974d29cb2dSJohn Baldwin 		mtx_destroy(&ithd->it_lock);
198b4151f71SJohn Baldwin 		free(ithd, M_ITHREAD);
199b4151f71SJohn Baldwin 		return (error);
200b4151f71SJohn Baldwin 	}
201079b7badSJulian Elischer 	td = FIRST_THREAD_IN_PROC(p);	/* XXXKSE */
2022c100766SJulian Elischer 	td->td_ksegrp->kg_pri_class = PRI_ITHD;
2032c100766SJulian Elischer 	td->td_priority = PRI_MAX_ITHD;
20471fad9fdSJulian Elischer 	TD_SET_IWAIT(td);
205b40ce416SJulian Elischer 	ithd->it_td = td;
206b40ce416SJulian Elischer 	td->td_ithd = ithd;
207b4151f71SJohn Baldwin 	if (ithread != NULL)
208b4151f71SJohn Baldwin 		*ithread = ithd;
209b4151f71SJohn Baldwin 
21091f91617SDavid E. O'Brien 	CTR2(KTR_INTR, "%s: created %s", __func__, ithd->it_name);
211b4151f71SJohn Baldwin 	return (0);
212b4151f71SJohn Baldwin }
213b4151f71SJohn Baldwin 
214b4151f71SJohn Baldwin int
215b4151f71SJohn Baldwin ithread_destroy(struct ithd *ithread)
216b4151f71SJohn Baldwin {
217b4151f71SJohn Baldwin 
218b40ce416SJulian Elischer 	struct thread *td;
219b40ce416SJulian Elischer 	struct proc *p;
2204d29cb2dSJohn Baldwin 	if (ithread == NULL)
221b4151f71SJohn Baldwin 		return (EINVAL);
222b4151f71SJohn Baldwin 
223b40ce416SJulian Elischer 	td = ithread->it_td;
224b40ce416SJulian Elischer 	p = td->td_proc;
2254d29cb2dSJohn Baldwin 	mtx_lock(&ithread->it_lock);
2264d29cb2dSJohn Baldwin 	if (!TAILQ_EMPTY(&ithread->it_handlers)) {
2274d29cb2dSJohn Baldwin 		mtx_unlock(&ithread->it_lock);
2284d29cb2dSJohn Baldwin 		return (EINVAL);
2294d29cb2dSJohn Baldwin 	}
230b4151f71SJohn Baldwin 	ithread->it_flags |= IT_DEAD;
2314d29cb2dSJohn Baldwin 	mtx_lock_spin(&sched_lock);
23271fad9fdSJulian Elischer 	if (TD_AWAITING_INTR(td)) {
23371fad9fdSJulian Elischer 		TD_CLR_IWAIT(td);
234b40ce416SJulian Elischer 		setrunqueue(td);
235b4151f71SJohn Baldwin 	}
236b4151f71SJohn Baldwin 	mtx_unlock_spin(&sched_lock);
2374d29cb2dSJohn Baldwin 	mtx_unlock(&ithread->it_lock);
23891f91617SDavid E. O'Brien 	CTR2(KTR_INTR, "%s: killing %s", __func__, ithread->it_name);
239b4151f71SJohn Baldwin 	return (0);
240b4151f71SJohn Baldwin }
241b4151f71SJohn Baldwin 
242b4151f71SJohn Baldwin int
243b4151f71SJohn Baldwin ithread_add_handler(struct ithd* ithread, const char *name,
244b4151f71SJohn Baldwin     driver_intr_t handler, void *arg, u_char pri, enum intr_type flags,
245b4151f71SJohn Baldwin     void **cookiep)
246b4151f71SJohn Baldwin {
247b4151f71SJohn Baldwin 	struct intrhand *ih, *temp_ih;
248b4151f71SJohn Baldwin 
249b4151f71SJohn Baldwin 	if (ithread == NULL || name == NULL || handler == NULL)
250b4151f71SJohn Baldwin 		return (EINVAL);
251b4151f71SJohn Baldwin 	if ((flags & INTR_FAST) !=0)
252b4151f71SJohn Baldwin 		flags |= INTR_EXCL;
253b4151f71SJohn Baldwin 
254b4151f71SJohn Baldwin 	ih = malloc(sizeof(struct intrhand), M_ITHREAD, M_WAITOK | M_ZERO);
255b4151f71SJohn Baldwin 	ih->ih_handler = handler;
256b4151f71SJohn Baldwin 	ih->ih_argument = arg;
257b4151f71SJohn Baldwin 	ih->ih_name = name;
258b4151f71SJohn Baldwin 	ih->ih_ithread = ithread;
259b4151f71SJohn Baldwin 	ih->ih_pri = pri;
260b4151f71SJohn Baldwin 	if (flags & INTR_FAST)
261b4151f71SJohn Baldwin 		ih->ih_flags = IH_FAST | IH_EXCLUSIVE;
262b4151f71SJohn Baldwin 	else if (flags & INTR_EXCL)
263b4151f71SJohn Baldwin 		ih->ih_flags = IH_EXCLUSIVE;
264b4151f71SJohn Baldwin 	if (flags & INTR_MPSAFE)
265b4151f71SJohn Baldwin 		ih->ih_flags |= IH_MPSAFE;
266b4151f71SJohn Baldwin 	if (flags & INTR_ENTROPY)
267b4151f71SJohn Baldwin 		ih->ih_flags |= IH_ENTROPY;
268b4151f71SJohn Baldwin 
2694d29cb2dSJohn Baldwin 	mtx_lock(&ithread->it_lock);
270b4151f71SJohn Baldwin 	if ((flags & INTR_EXCL) !=0 && !TAILQ_EMPTY(&ithread->it_handlers))
271b4151f71SJohn Baldwin 		goto fail;
272b4151f71SJohn Baldwin 	if (!TAILQ_EMPTY(&ithread->it_handlers) &&
273b4151f71SJohn Baldwin 	    (TAILQ_FIRST(&ithread->it_handlers)->ih_flags & IH_EXCLUSIVE) != 0)
274b4151f71SJohn Baldwin 		goto fail;
275b4151f71SJohn Baldwin 
276b4151f71SJohn Baldwin 	TAILQ_FOREACH(temp_ih, &ithread->it_handlers, ih_next)
277b4151f71SJohn Baldwin 	    if (temp_ih->ih_pri > ih->ih_pri)
278b4151f71SJohn Baldwin 		    break;
279b4151f71SJohn Baldwin 	if (temp_ih == NULL)
280b4151f71SJohn Baldwin 		TAILQ_INSERT_TAIL(&ithread->it_handlers, ih, ih_next);
281b4151f71SJohn Baldwin 	else
282b4151f71SJohn Baldwin 		TAILQ_INSERT_BEFORE(temp_ih, ih, ih_next);
283b4151f71SJohn Baldwin 	ithread_update(ithread);
2844d29cb2dSJohn Baldwin 	mtx_unlock(&ithread->it_lock);
285b4151f71SJohn Baldwin 
286b4151f71SJohn Baldwin 	if (cookiep != NULL)
287b4151f71SJohn Baldwin 		*cookiep = ih;
28891f91617SDavid E. O'Brien 	CTR3(KTR_INTR, "%s: added %s to %s", __func__, ih->ih_name,
289addec20cSJohn Baldwin 	    ithread->it_name);
290b4151f71SJohn Baldwin 	return (0);
291b4151f71SJohn Baldwin 
292b4151f71SJohn Baldwin fail:
2934d29cb2dSJohn Baldwin 	mtx_unlock(&ithread->it_lock);
294b4151f71SJohn Baldwin 	free(ih, M_ITHREAD);
295b4151f71SJohn Baldwin 	return (EINVAL);
296b4151f71SJohn Baldwin }
297b4151f71SJohn Baldwin 
298b4151f71SJohn Baldwin int
299b4151f71SJohn Baldwin ithread_remove_handler(void *cookie)
300b4151f71SJohn Baldwin {
301b4151f71SJohn Baldwin 	struct intrhand *handler = (struct intrhand *)cookie;
302b4151f71SJohn Baldwin 	struct ithd *ithread;
303b4151f71SJohn Baldwin #ifdef INVARIANTS
304b4151f71SJohn Baldwin 	struct intrhand *ih;
305b4151f71SJohn Baldwin #endif
306b4151f71SJohn Baldwin 
3073e5da754SJohn Baldwin 	if (handler == NULL)
308b4151f71SJohn Baldwin 		return (EINVAL);
30976bd604eSJohn Baldwin 	ithread = handler->ih_ithread;
31076bd604eSJohn Baldwin 	KASSERT(ithread != NULL,
3113e5da754SJohn Baldwin 	    ("interrupt handler \"%s\" has a NULL interrupt thread",
3123e5da754SJohn Baldwin 		handler->ih_name));
31391f91617SDavid E. O'Brien 	CTR3(KTR_INTR, "%s: removing %s from %s", __func__, handler->ih_name,
314addec20cSJohn Baldwin 	    ithread->it_name);
3154d29cb2dSJohn Baldwin 	mtx_lock(&ithread->it_lock);
316b4151f71SJohn Baldwin #ifdef INVARIANTS
317b4151f71SJohn Baldwin 	TAILQ_FOREACH(ih, &ithread->it_handlers, ih_next)
3183e5da754SJohn Baldwin 		if (ih == handler)
3193e5da754SJohn Baldwin 			goto ok;
3204d29cb2dSJohn Baldwin 	mtx_unlock(&ithread->it_lock);
3213e5da754SJohn Baldwin 	panic("interrupt handler \"%s\" not found in interrupt thread \"%s\"",
3223e5da754SJohn Baldwin 	    ih->ih_name, ithread->it_name);
3233e5da754SJohn Baldwin ok:
324b4151f71SJohn Baldwin #endif
325de271f01SJohn Baldwin 	/*
326de271f01SJohn Baldwin 	 * If the interrupt thread is already running, then just mark this
327de271f01SJohn Baldwin 	 * handler as being dead and let the ithread do the actual removal.
328de271f01SJohn Baldwin 	 */
329de271f01SJohn Baldwin 	mtx_lock_spin(&sched_lock);
33071fad9fdSJulian Elischer 	if (!TD_AWAITING_INTR(ithread->it_td)) {
331de271f01SJohn Baldwin 		handler->ih_flags |= IH_DEAD;
332de271f01SJohn Baldwin 
333de271f01SJohn Baldwin 		/*
334de271f01SJohn Baldwin 		 * Ensure that the thread will process the handler list
335de271f01SJohn Baldwin 		 * again and remove this handler if it has already passed
336de271f01SJohn Baldwin 		 * it on the list.
337de271f01SJohn Baldwin 		 */
338de271f01SJohn Baldwin 		ithread->it_need = 1;
3394d29cb2dSJohn Baldwin 	} else
340b4151f71SJohn Baldwin 		TAILQ_REMOVE(&ithread->it_handlers, handler, ih_next);
341de271f01SJohn Baldwin 	mtx_unlock_spin(&sched_lock);
3424d29cb2dSJohn Baldwin 	if ((handler->ih_flags & IH_DEAD) != 0)
3434d29cb2dSJohn Baldwin 		msleep(handler, &ithread->it_lock, PUSER, "itrmh", 0);
3444d29cb2dSJohn Baldwin 	ithread_update(ithread);
3454d29cb2dSJohn Baldwin 	mtx_unlock(&ithread->it_lock);
346b4151f71SJohn Baldwin 	free(handler, M_ITHREAD);
347b4151f71SJohn Baldwin 	return (0);
348b4151f71SJohn Baldwin }
349b4151f71SJohn Baldwin 
350b4151f71SJohn Baldwin int
3513e5da754SJohn Baldwin ithread_schedule(struct ithd *ithread, int do_switch)
3523e5da754SJohn Baldwin {
3533e5da754SJohn Baldwin 	struct int_entropy entropy;
354b40ce416SJulian Elischer 	struct thread *td;
35504774f23SJulian Elischer 	struct thread *ctd;
3563e5da754SJohn Baldwin 	struct proc *p;
3573e5da754SJohn Baldwin 
3583e5da754SJohn Baldwin 	/*
3593e5da754SJohn Baldwin 	 * If no ithread or no handlers, then we have a stray interrupt.
3603e5da754SJohn Baldwin 	 */
3613e5da754SJohn Baldwin 	if ((ithread == NULL) || TAILQ_EMPTY(&ithread->it_handlers))
3623e5da754SJohn Baldwin 		return (EINVAL);
3633e5da754SJohn Baldwin 
36404774f23SJulian Elischer 	ctd = curthread;
3653e5da754SJohn Baldwin 	/*
3663e5da754SJohn Baldwin 	 * If any of the handlers for this ithread claim to be good
3673e5da754SJohn Baldwin 	 * sources of entropy, then gather some.
3683e5da754SJohn Baldwin 	 */
3693e5da754SJohn Baldwin 	if (harvest.interrupt && ithread->it_flags & IT_ENTROPY) {
3703e5da754SJohn Baldwin 		entropy.vector = ithread->it_vector;
37165c17e74SDavid Xu 		entropy.proc = ctd->td_proc;
3723e5da754SJohn Baldwin 		random_harvest(&entropy, sizeof(entropy), 2, 0,
3733e5da754SJohn Baldwin 		    RANDOM_INTERRUPT);
3743e5da754SJohn Baldwin 	}
3753e5da754SJohn Baldwin 
376b40ce416SJulian Elischer 	td = ithread->it_td;
377b40ce416SJulian Elischer 	p = td->td_proc;
378653dd8c2SJohn Baldwin 	KASSERT(p != NULL, ("ithread %s has no process", ithread->it_name));
379e602ba25SJulian Elischer 	CTR4(KTR_INTR, "%s: pid %d: (%s) need = %d",
380e602ba25SJulian Elischer 	    __func__, p->p_pid, p->p_comm, ithread->it_need);
3813e5da754SJohn Baldwin 
3823e5da754SJohn Baldwin 	/*
3833e5da754SJohn Baldwin 	 * Set it_need to tell the thread to keep running if it is already
3843e5da754SJohn Baldwin 	 * running.  Then, grab sched_lock and see if we actually need to
3853e5da754SJohn Baldwin 	 * put this thread on the runqueue.  If so and the do_switch flag is
386c86b6ff5SJohn Baldwin 	 * true and it is safe to switch, then switch to the ithread
387c86b6ff5SJohn Baldwin 	 * immediately.  Otherwise, set the needresched flag to guarantee
388c86b6ff5SJohn Baldwin 	 * that this ithread will run before any userland processes.
3893e5da754SJohn Baldwin 	 */
3903e5da754SJohn Baldwin 	ithread->it_need = 1;
3913e5da754SJohn Baldwin 	mtx_lock_spin(&sched_lock);
39271fad9fdSJulian Elischer 	if (TD_AWAITING_INTR(td)) {
39391f91617SDavid E. O'Brien 		CTR2(KTR_INTR, "%s: setrunqueue %d", __func__, p->p_pid);
39471fad9fdSJulian Elischer 		TD_CLR_IWAIT(td);
395e602ba25SJulian Elischer 		setrunqueue(td);
396e602ba25SJulian Elischer 		if (do_switch &&
39704774f23SJulian Elischer 		    (ctd->td_critnest == 1) ) {
39871fad9fdSJulian Elischer 			KASSERT((TD_IS_RUNNING(ctd)),
39904774f23SJulian Elischer 			    ("ithread_schedule: Bad state for curthread."));
40004774f23SJulian Elischer 			ctd->td_proc->p_stats->p_ru.ru_nivcsw++;
40104774f23SJulian Elischer 			if (ctd->td_kse->ke_flags & KEF_IDLEKSE)
40271fad9fdSJulian Elischer 				ctd->td_state = TDS_CAN_RUN; /* XXXKSE */
4033e5da754SJohn Baldwin 			mi_switch();
4042d0231f5SJulian Elischer 		} else {
405b40ce416SJulian Elischer 			curthread->td_kse->ke_flags |= KEF_NEEDRESCHED;
4062d0231f5SJulian Elischer 		}
4073e5da754SJohn Baldwin 	} else {
40891f91617SDavid E. O'Brien 		CTR4(KTR_INTR, "%s: pid %d: it_need %d, state %d",
409e602ba25SJulian Elischer 		    __func__, p->p_pid, ithread->it_need, p->p_state);
4103e5da754SJohn Baldwin 	}
4113e5da754SJohn Baldwin 	mtx_unlock_spin(&sched_lock);
4123e5da754SJohn Baldwin 
4133e5da754SJohn Baldwin 	return (0);
4143e5da754SJohn Baldwin }
4153e5da754SJohn Baldwin 
4163e5da754SJohn Baldwin int
417b4151f71SJohn Baldwin swi_add(struct ithd **ithdp, const char *name, driver_intr_t handler,
418b4151f71SJohn Baldwin 	    void *arg, int pri, enum intr_type flags, void **cookiep)
4198088699fSJohn Baldwin {
4208088699fSJohn Baldwin 	struct ithd *ithd;
421b4151f71SJohn Baldwin 	int error;
4228088699fSJohn Baldwin 
4233e5da754SJohn Baldwin 	if (flags & (INTR_FAST | INTR_ENTROPY))
4243e5da754SJohn Baldwin 		return (EINVAL);
4253e5da754SJohn Baldwin 
4268088699fSJohn Baldwin 	ithd = (ithdp != NULL) ? *ithdp : NULL;
4278088699fSJohn Baldwin 
4283e5da754SJohn Baldwin 	if (ithd != NULL) {
4293e5da754SJohn Baldwin 		if ((ithd->it_flags & IT_SOFT) == 0)
4303e5da754SJohn Baldwin 			return(EINVAL);
4313e5da754SJohn Baldwin 	} else {
432b4151f71SJohn Baldwin 		error = ithread_create(&ithd, pri, IT_SOFT, NULL, NULL,
433b4151f71SJohn Baldwin 		    "swi%d:", pri);
4348088699fSJohn Baldwin 		if (error)
435b4151f71SJohn Baldwin 			return (error);
436b4151f71SJohn Baldwin 
4378088699fSJohn Baldwin 		if (ithdp != NULL)
4388088699fSJohn Baldwin 			*ithdp = ithd;
4398088699fSJohn Baldwin 	}
440d5a08a60SJake Burkholder 	return (ithread_add_handler(ithd, name, handler, arg,
441d5a08a60SJake Burkholder 		    (pri * RQ_PPQ) + PI_SOFT, flags, cookiep));
4428088699fSJohn Baldwin }
4438088699fSJohn Baldwin 
4448088699fSJohn Baldwin 
4451931cf94SJohn Baldwin /*
4468088699fSJohn Baldwin  * Schedule a heavyweight software interrupt process.
4471931cf94SJohn Baldwin  */
4481931cf94SJohn Baldwin void
449b4151f71SJohn Baldwin swi_sched(void *cookie, int flags)
4501931cf94SJohn Baldwin {
451b4151f71SJohn Baldwin 	struct intrhand *ih = (struct intrhand *)cookie;
452b4151f71SJohn Baldwin 	struct ithd *it = ih->ih_ithread;
4533e5da754SJohn Baldwin 	int error;
4548088699fSJohn Baldwin 
4551931cf94SJohn Baldwin 	atomic_add_int(&cnt.v_intr, 1); /* one more global interrupt */
4561931cf94SJohn Baldwin 
457b4151f71SJohn Baldwin 	CTR3(KTR_INTR, "swi_sched pid %d(%s) need=%d",
458b40ce416SJulian Elischer 		it->it_td->td_proc->p_pid, it->it_td->td_proc->p_comm, it->it_need);
4591931cf94SJohn Baldwin 
4601931cf94SJohn Baldwin 	/*
4613e5da754SJohn Baldwin 	 * Set ih_need for this handler so that if the ithread is already
4623e5da754SJohn Baldwin 	 * running it will execute this handler on the next pass.  Otherwise,
4633e5da754SJohn Baldwin 	 * it will execute it the next time it runs.
4641931cf94SJohn Baldwin 	 */
465b4151f71SJohn Baldwin 	atomic_store_rel_int(&ih->ih_need, 1);
466b4151f71SJohn Baldwin 	if (!(flags & SWI_DELAY)) {
467c86b6ff5SJohn Baldwin 		error = ithread_schedule(it, !cold);
4683e5da754SJohn Baldwin 		KASSERT(error == 0, ("stray software interrupt"));
4698088699fSJohn Baldwin 	}
4708088699fSJohn Baldwin }
4718088699fSJohn Baldwin 
4728088699fSJohn Baldwin /*
473b4151f71SJohn Baldwin  * This is the main code for interrupt threads.
4748088699fSJohn Baldwin  */
4758088699fSJohn Baldwin void
476b4151f71SJohn Baldwin ithread_loop(void *arg)
4778088699fSJohn Baldwin {
478b4151f71SJohn Baldwin 	struct ithd *ithd;		/* our thread context */
4798088699fSJohn Baldwin 	struct intrhand *ih;		/* and our interrupt handler chain */
480b40ce416SJulian Elischer 	struct thread *td;
481b4151f71SJohn Baldwin 	struct proc *p;
4828088699fSJohn Baldwin 
483b40ce416SJulian Elischer 	td = curthread;
484b40ce416SJulian Elischer 	p = td->td_proc;
485b4151f71SJohn Baldwin 	ithd = (struct ithd *)arg;	/* point to myself */
486b40ce416SJulian Elischer 	KASSERT(ithd->it_td == td && td->td_ithd == ithd,
48791f91617SDavid E. O'Brien 	    ("%s: ithread and proc linkage out of sync", __func__));
4888088699fSJohn Baldwin 
4898088699fSJohn Baldwin 	/*
4908088699fSJohn Baldwin 	 * As long as we have interrupts outstanding, go through the
4918088699fSJohn Baldwin 	 * list of handlers, giving each one a go at it.
4928088699fSJohn Baldwin 	 */
4938088699fSJohn Baldwin 	for (;;) {
494b4151f71SJohn Baldwin 		/*
495b4151f71SJohn Baldwin 		 * If we are an orphaned thread, then just die.
496b4151f71SJohn Baldwin 		 */
497b4151f71SJohn Baldwin 		if (ithd->it_flags & IT_DEAD) {
49891f91617SDavid E. O'Brien 			CTR3(KTR_INTR, "%s: pid %d: (%s) exiting", __func__,
499b4151f71SJohn Baldwin 			    p->p_pid, p->p_comm);
500b40ce416SJulian Elischer 			td->td_ithd = NULL;
5014d29cb2dSJohn Baldwin 			mtx_destroy(&ithd->it_lock);
502b4151f71SJohn Baldwin 			mtx_lock(&Giant);
503b4151f71SJohn Baldwin 			free(ithd, M_ITHREAD);
504b4151f71SJohn Baldwin 			kthread_exit(0);
505b4151f71SJohn Baldwin 		}
506b4151f71SJohn Baldwin 
50791f91617SDavid E. O'Brien 		CTR4(KTR_INTR, "%s: pid %d: (%s) need=%d", __func__,
508b4151f71SJohn Baldwin 		     p->p_pid, p->p_comm, ithd->it_need);
509b4151f71SJohn Baldwin 		while (ithd->it_need) {
5108088699fSJohn Baldwin 			/*
5118088699fSJohn Baldwin 			 * Service interrupts.  If another interrupt
5128088699fSJohn Baldwin 			 * arrives while we are running, they will set
5138088699fSJohn Baldwin 			 * it_need to denote that we should make
5148088699fSJohn Baldwin 			 * another pass.
5158088699fSJohn Baldwin 			 */
516b4151f71SJohn Baldwin 			atomic_store_rel_int(&ithd->it_need, 0);
517de271f01SJohn Baldwin restart:
518b4151f71SJohn Baldwin 			TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) {
519b4151f71SJohn Baldwin 				if (ithd->it_flags & IT_SOFT && !ih->ih_need)
5208088699fSJohn Baldwin 					continue;
521b4151f71SJohn Baldwin 				atomic_store_rel_int(&ih->ih_need, 0);
52291f91617SDavid E. O'Brien 				CTR6(KTR_INTR,
52391f91617SDavid E. O'Brien 				    "%s: pid %d ih=%p: %p(%p) flg=%x", __func__,
5248088699fSJohn Baldwin 				    p->p_pid, (void *)ih,
5258088699fSJohn Baldwin 				    (void *)ih->ih_handler, ih->ih_argument,
5268088699fSJohn Baldwin 				    ih->ih_flags);
5278088699fSJohn Baldwin 
528de271f01SJohn Baldwin 				if ((ih->ih_flags & IH_DEAD) != 0) {
5294d29cb2dSJohn Baldwin 					mtx_lock(&ithd->it_lock);
530de271f01SJohn Baldwin 					TAILQ_REMOVE(&ithd->it_handlers, ih,
531de271f01SJohn Baldwin 					    ih_next);
5324d29cb2dSJohn Baldwin 					wakeup(ih);
5334d29cb2dSJohn Baldwin 					mtx_unlock(&ithd->it_lock);
534de271f01SJohn Baldwin 					goto restart;
535de271f01SJohn Baldwin 				}
5364d29cb2dSJohn Baldwin 				if ((ih->ih_flags & IH_MPSAFE) == 0)
5374d29cb2dSJohn Baldwin 					mtx_lock(&Giant);
5388088699fSJohn Baldwin 				ih->ih_handler(ih->ih_argument);
539b4151f71SJohn Baldwin 				if ((ih->ih_flags & IH_MPSAFE) == 0)
5409ed346baSBosko Milekic 					mtx_unlock(&Giant);
5418088699fSJohn Baldwin 			}
5428088699fSJohn Baldwin 		}
5438088699fSJohn Baldwin 
5448088699fSJohn Baldwin 		/*
5458088699fSJohn Baldwin 		 * Processed all our interrupts.  Now get the sched
5468088699fSJohn Baldwin 		 * lock.  This may take a while and it_need may get
5478088699fSJohn Baldwin 		 * set again, so we have to check it again.
5488088699fSJohn Baldwin 		 */
549896c2303SJohn Baldwin 		mtx_assert(&Giant, MA_NOTOWNED);
5509ed346baSBosko Milekic 		mtx_lock_spin(&sched_lock);
551b4151f71SJohn Baldwin 		if (!ithd->it_need) {
552b4151f71SJohn Baldwin 			/*
553b4151f71SJohn Baldwin 			 * Should we call this earlier in the loop above?
554b4151f71SJohn Baldwin 			 */
555b4151f71SJohn Baldwin 			if (ithd->it_enable != NULL)
556b4151f71SJohn Baldwin 				ithd->it_enable(ithd->it_vector);
55771fad9fdSJulian Elischer 			TD_SET_IWAIT(td); /* we're idle */
55884bbc4dbSJohn Baldwin 			p->p_stats->p_ru.ru_nvcsw++;
55991f91617SDavid E. O'Brien 			CTR2(KTR_INTR, "%s: pid %d: done", __func__, p->p_pid);
5608088699fSJohn Baldwin 			mi_switch();
56191f91617SDavid E. O'Brien 			CTR2(KTR_INTR, "%s: pid %d: resumed", __func__, p->p_pid);
5628088699fSJohn Baldwin 		}
5639ed346baSBosko Milekic 		mtx_unlock_spin(&sched_lock);
5648088699fSJohn Baldwin 	}
5651931cf94SJohn Baldwin }
5661931cf94SJohn Baldwin 
567b4151f71SJohn Baldwin /*
5688088699fSJohn Baldwin  * Start standard software interrupt threads
5691931cf94SJohn Baldwin  */
5701931cf94SJohn Baldwin static void
571b4151f71SJohn Baldwin start_softintr(void *dummy)
5721931cf94SJohn Baldwin {
573b4151f71SJohn Baldwin 
574b4151f71SJohn Baldwin 	if (swi_add(NULL, "net", swi_net, NULL, SWI_NET, 0, &net_ih) ||
575b4151f71SJohn Baldwin 	    swi_add(&clk_ithd, "clock", softclock, NULL, SWI_CLOCK,
576b4151f71SJohn Baldwin 		INTR_MPSAFE, &softclock_ih) ||
577b4151f71SJohn Baldwin 	    swi_add(NULL, "vm", swi_vm, NULL, SWI_VM, 0, &vm_ih))
578b4151f71SJohn Baldwin 		panic("died while creating standard software ithreads");
5793e5da754SJohn Baldwin 
580b40ce416SJulian Elischer 	PROC_LOCK(clk_ithd->it_td->td_proc);
581b40ce416SJulian Elischer 	clk_ithd->it_td->td_proc->p_flag |= P_NOLOAD;
582b40ce416SJulian Elischer 	PROC_UNLOCK(clk_ithd->it_td->td_proc);
5831931cf94SJohn Baldwin }
584b4151f71SJohn Baldwin SYSINIT(start_softintr, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softintr, NULL)
5851931cf94SJohn Baldwin 
5861931cf94SJohn Baldwin void
587b4151f71SJohn Baldwin legacy_setsoftnet(void)
5881931cf94SJohn Baldwin {
589c86b6ff5SJohn Baldwin 	swi_sched(net_ih, 0);
5901931cf94SJohn Baldwin }
5911931cf94SJohn Baldwin 
5928088699fSJohn Baldwin /*
5938088699fSJohn Baldwin  * XXX: This should really be in the network code somewhere and installed
5948088699fSJohn Baldwin  * via a SI_SUB_SOFINTR, SI_ORDER_MIDDLE sysinit.
5958088699fSJohn Baldwin  */
5964d77a549SAlfred Perlstein void	(*netisrs[32])(void);
5976533ba2eSDavid E. O'Brien volatile unsigned int	netisr;	/* scheduling bits for network */
5988088699fSJohn Baldwin 
5991eb44f02SJake Burkholder int
6001eb44f02SJake Burkholder register_netisr(num, handler)
6011eb44f02SJake Burkholder 	int num;
6021eb44f02SJake Burkholder 	netisr_t *handler;
6031eb44f02SJake Burkholder {
6041eb44f02SJake Burkholder 
6051eb44f02SJake Burkholder 	if (num < 0 || num >= (sizeof(netisrs)/sizeof(*netisrs)) ) {
6061eb44f02SJake Burkholder 		printf("register_netisr: bad isr number: %d\n", num);
6071eb44f02SJake Burkholder 		return (EINVAL);
6081eb44f02SJake Burkholder 	}
6091eb44f02SJake Burkholder 	netisrs[num] = handler;
6101eb44f02SJake Burkholder 	return (0);
6111eb44f02SJake Burkholder }
6121eb44f02SJake Burkholder 
6131eb44f02SJake Burkholder int
6141eb44f02SJake Burkholder unregister_netisr(num)
6151eb44f02SJake Burkholder 	int num;
6161eb44f02SJake Burkholder {
6171eb44f02SJake Burkholder 
6181eb44f02SJake Burkholder 	if (num < 0 || num >= (sizeof(netisrs)/sizeof(*netisrs)) ) {
6191eb44f02SJake Burkholder 		printf("unregister_netisr: bad isr number: %d\n", num);
6201eb44f02SJake Burkholder 		return (EINVAL);
6211eb44f02SJake Burkholder 	}
6221eb44f02SJake Burkholder 	netisrs[num] = NULL;
6231eb44f02SJake Burkholder 	return (0);
6241eb44f02SJake Burkholder }
6251eb44f02SJake Burkholder 
6262dbd9d5bSLuigi Rizzo #ifdef DEVICE_POLLING
6272dbd9d5bSLuigi Rizzo 	void netisr_pollmore(void);
6282dbd9d5bSLuigi Rizzo #endif
6292dbd9d5bSLuigi Rizzo 
6308088699fSJohn Baldwin static void
6318088699fSJohn Baldwin swi_net(void *dummy)
6321931cf94SJohn Baldwin {
6338088699fSJohn Baldwin 	u_int bits;
6348088699fSJohn Baldwin 	int i;
6358088699fSJohn Baldwin 
636e4fc250cSLuigi Rizzo #ifdef DEVICE_POLLING
637e4fc250cSLuigi Rizzo     for (;;) {
638e4fc250cSLuigi Rizzo 	int pollmore;
639e4fc250cSLuigi Rizzo #endif
6408088699fSJohn Baldwin 	bits = atomic_readandclear_int(&netisr);
641e4fc250cSLuigi Rizzo #ifdef DEVICE_POLLING
642e4fc250cSLuigi Rizzo 	if (bits == 0)
643e4fc250cSLuigi Rizzo 		return;
644e4fc250cSLuigi Rizzo 	pollmore = bits & (1 << NETISR_POLL);
645e4fc250cSLuigi Rizzo #endif
6468088699fSJohn Baldwin 	while ((i = ffs(bits)) != 0) {
6478088699fSJohn Baldwin 		i--;
648338c0bc6SSeigo Tanimura 		if (netisrs[i] != NULL)
6498088699fSJohn Baldwin 			netisrs[i]();
650338c0bc6SSeigo Tanimura 		else
651338c0bc6SSeigo Tanimura 			printf("swi_net: unregistered isr number: %d.\n", i);
6528088699fSJohn Baldwin 		bits &= ~(1 << i);
6538088699fSJohn Baldwin 	}
654e4fc250cSLuigi Rizzo #ifdef DEVICE_POLLING
655e4fc250cSLuigi Rizzo 	if (pollmore)
656daccb638SLuigi Rizzo 		netisr_pollmore();
657e4fc250cSLuigi Rizzo     }
658e4fc250cSLuigi Rizzo #endif
6591931cf94SJohn Baldwin }
660d279178dSThomas Moestl 
661d279178dSThomas Moestl /*
662d279178dSThomas Moestl  * Sysctls used by systat and others: hw.intrnames and hw.intrcnt.
663d279178dSThomas Moestl  * The data for this machine dependent, and the declarations are in machine
664d279178dSThomas Moestl  * dependent code.  The layout of intrnames and intrcnt however is machine
665d279178dSThomas Moestl  * independent.
666d279178dSThomas Moestl  *
667d279178dSThomas Moestl  * We do not know the length of intrcnt and intrnames at compile time, so
668d279178dSThomas Moestl  * calculate things at run time.
669d279178dSThomas Moestl  */
670d279178dSThomas Moestl static int
671d279178dSThomas Moestl sysctl_intrnames(SYSCTL_HANDLER_ARGS)
672d279178dSThomas Moestl {
673d279178dSThomas Moestl 	return (sysctl_handle_opaque(oidp, intrnames, eintrnames - intrnames,
674d279178dSThomas Moestl 	   req));
675d279178dSThomas Moestl }
676d279178dSThomas Moestl 
677d279178dSThomas Moestl SYSCTL_PROC(_hw, OID_AUTO, intrnames, CTLTYPE_OPAQUE | CTLFLAG_RD,
678d279178dSThomas Moestl     NULL, 0, sysctl_intrnames, "", "Interrupt Names");
679d279178dSThomas Moestl 
680d279178dSThomas Moestl static int
681d279178dSThomas Moestl sysctl_intrcnt(SYSCTL_HANDLER_ARGS)
682d279178dSThomas Moestl {
683d279178dSThomas Moestl 	return (sysctl_handle_opaque(oidp, intrcnt,
684d279178dSThomas Moestl 	    (char *)eintrcnt - (char *)intrcnt, req));
685d279178dSThomas Moestl }
686d279178dSThomas Moestl 
687d279178dSThomas Moestl SYSCTL_PROC(_hw, OID_AUTO, intrcnt, CTLTYPE_OPAQUE | CTLFLAG_RD,
688d279178dSThomas Moestl     NULL, 0, sysctl_intrcnt, "", "Interrupt Counts");
689