2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "opt_kstack_usage_prof.h"
33 #include <sys/param.h>
36 #include <sys/cpuset.h>
37 #include <sys/rtprio.h>
38 #include <sys/systm.h>
39 #include <sys/interrupt.h>
40 #include <sys/kernel.h>
41 #include <sys/kthread.h>
43 #include <sys/limits.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
49 #include <sys/random.h>
50 #include <sys/resourcevar.h>
51 #include <sys/sched.h>
53 #include <sys/sysctl.h>
54 #include <sys/syslog.h>
55 #include <sys/unistd.h>
56 #include <sys/vmmeter.h>
57 #include <machine/atomic.h>
58 #include <machine/cpu.h>
59 #include <machine/md_var.h>
60 #include <machine/stdarg.h>
63 #include <ddb/db_sym.h>
67 * Describe an interrupt thread. There is one of these per interrupt event.
70 struct intr_event *it_event;
71 struct thread *it_thread; /* Kernel thread. */
72 int it_flags; /* (j) IT_* flags. */
73 int it_need; /* Needs service. */
76 /* Interrupt thread flags kept in it_flags */
77 #define IT_DEAD 0x000001 /* Thread is waiting to exit. */
78 #define IT_WAIT 0x000002 /* Thread is waiting for completion. */
85 struct intr_event *clk_intr_event;
86 struct intr_event *tty_intr_event;
88 struct proc *intrproc;
90 static MALLOC_DEFINE(M_ITHREAD, "ithread", "Interrupt Threads");
92 static int intr_storm_threshold = 1000;
93 SYSCTL_INT(_hw, OID_AUTO, intr_storm_threshold, CTLFLAG_RWTUN,
94 &intr_storm_threshold, 0,
95 "Number of consecutive interrupts before storm protection is enabled");
96 static TAILQ_HEAD(, intr_event) event_list =
97 TAILQ_HEAD_INITIALIZER(event_list);
98 static struct mtx event_lock;
99 MTX_SYSINIT(intr_event_list, &event_lock, "intr event list", MTX_DEF);
101 static void intr_event_update(struct intr_event *ie);
103 static int intr_event_schedule_thread(struct intr_event *ie,
104 struct intr_thread *ithd);
105 static int intr_filter_loop(struct intr_event *ie,
106 struct trapframe *frame, struct intr_thread **ithd);
107 static struct intr_thread *ithread_create(const char *name,
108 struct intr_handler *ih);
110 static int intr_event_schedule_thread(struct intr_event *ie);
111 static struct intr_thread *ithread_create(const char *name);
113 static void ithread_destroy(struct intr_thread *ithread);
114 static void ithread_execute_handlers(struct proc *p,
115 struct intr_event *ie);
117 static void priv_ithread_execute_handler(struct proc *p,
118 struct intr_handler *ih);
120 static void ithread_loop(void *);
121 static void ithread_update(struct intr_thread *ithd);
122 static void start_softintr(void *);
124 /* Map an interrupt type to an ithread priority. */
126 intr_priority(enum intr_type flags)
130 flags &= (INTR_TYPE_TTY | INTR_TYPE_BIO | INTR_TYPE_NET |
131 INTR_TYPE_CAM | INTR_TYPE_MISC | INTR_TYPE_CLK | INTR_TYPE_AV);
152 pri = PI_DULL; /* don't care */
155 /* We didn't specify an interrupt level. */
156 panic("intr_priority: no interrupt type in flags");
163 * Update an ithread based on the associated intr_event.
166 ithread_update(struct intr_thread *ithd)
168 struct intr_event *ie;
173 td = ithd->it_thread;
175 /* Determine the overall priority of this event. */
176 if (TAILQ_EMPTY(&ie->ie_handlers))
179 pri = TAILQ_FIRST(&ie->ie_handlers)->ih_pri;
181 /* Update name and priority. */
182 strlcpy(td->td_name, ie->ie_fullname, sizeof(td->td_name));
184 sched_clear_tdname(td);
192 * Regenerate the full name of an interrupt event and update its priority.
195 intr_event_update(struct intr_event *ie)
197 struct intr_handler *ih;
201 /* Start off with no entropy and just the name of the event. */
202 mtx_assert(&ie->ie_lock, MA_OWNED);
203 strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname));
204 ie->ie_flags &= ~IE_ENTROPY;
208 /* Run through all the handlers updating values. */
209 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
210 if (strlen(ie->ie_fullname) + strlen(ih->ih_name) + 1 <
211 sizeof(ie->ie_fullname)) {
212 strcat(ie->ie_fullname, " ");
213 strcat(ie->ie_fullname, ih->ih_name);
217 if (ih->ih_flags & IH_ENTROPY)
218 ie->ie_flags |= IE_ENTROPY;
222 * If the handler names were too long, add +'s to indicate missing
223 * names. If we run out of room and still have +'s to add, change
224 * the last character from a + to a *.
226 last = &ie->ie_fullname[sizeof(ie->ie_fullname) - 2];
227 while (missed-- > 0) {
228 if (strlen(ie->ie_fullname) + 1 == sizeof(ie->ie_fullname)) {
235 strcat(ie->ie_fullname, " +");
238 strcat(ie->ie_fullname, "+");
242 * If this event has an ithread, update it's priority and
245 if (ie->ie_thread != NULL)
246 ithread_update(ie->ie_thread);
247 CTR2(KTR_INTR, "%s: updated %s", __func__, ie->ie_fullname);
251 intr_event_create(struct intr_event **event, void *source, int flags, int irq,
252 void (*pre_ithread)(void *), void (*post_ithread)(void *),
253 void (*post_filter)(void *), int (*assign_cpu)(void *, int),
254 const char *fmt, ...)
256 struct intr_event *ie;
259 /* The only valid flag during creation is IE_SOFT. */
260 if ((flags & ~IE_SOFT) != 0)
262 ie = malloc(sizeof(struct intr_event), M_ITHREAD, M_WAITOK | M_ZERO);
263 ie->ie_source = source;
264 ie->ie_pre_ithread = pre_ithread;
265 ie->ie_post_ithread = post_ithread;
266 ie->ie_post_filter = post_filter;
267 ie->ie_assign_cpu = assign_cpu;
268 ie->ie_flags = flags;
271 TAILQ_INIT(&ie->ie_handlers);
272 mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF);
275 vsnprintf(ie->ie_name, sizeof(ie->ie_name), fmt, ap);
277 strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname));
278 mtx_lock(&event_lock);
279 TAILQ_INSERT_TAIL(&event_list, ie, ie_list);
280 mtx_unlock(&event_lock);
283 CTR2(KTR_INTR, "%s: created %s", __func__, ie->ie_name);
288 * Bind an interrupt event to the specified CPU. Note that not all
289 * platforms support binding an interrupt to a CPU. For those
290 * platforms this request will fail. For supported platforms, any
291 * associated ithreads as well as the primary interrupt context will
292 * be bound to the specificed CPU. Using a cpu id of NOCPU unbinds
293 * the interrupt event.
296 intr_event_bind(struct intr_event *ie, int cpu)
301 /* Need a CPU to bind to. */
302 if (cpu != NOCPU && CPU_ABSENT(cpu))
305 if (ie->ie_assign_cpu == NULL)
308 error = priv_check(curthread, PRIV_SCHED_CPUSET_INTR);
313 * If we have any ithreads try to set their mask first to verify
316 mtx_lock(&ie->ie_lock);
317 if (ie->ie_thread != NULL) {
318 id = ie->ie_thread->it_thread->td_tid;
319 mtx_unlock(&ie->ie_lock);
320 error = cpuset_setithread(id, cpu);
324 mtx_unlock(&ie->ie_lock);
325 error = ie->ie_assign_cpu(ie->ie_source, cpu);
327 mtx_lock(&ie->ie_lock);
328 if (ie->ie_thread != NULL) {
330 id = ie->ie_thread->it_thread->td_tid;
331 mtx_unlock(&ie->ie_lock);
332 (void)cpuset_setithread(id, cpu);
334 mtx_unlock(&ie->ie_lock);
338 mtx_lock(&ie->ie_lock);
340 mtx_unlock(&ie->ie_lock);
345 static struct intr_event *
348 struct intr_event *ie;
350 mtx_lock(&event_lock);
351 TAILQ_FOREACH(ie, &event_list, ie_list)
352 if (ie->ie_irq == irq &&
353 (ie->ie_flags & IE_SOFT) == 0 &&
354 TAILQ_FIRST(&ie->ie_handlers) != NULL)
356 mtx_unlock(&event_lock);
361 intr_setaffinity(int irq, void *m)
363 struct intr_event *ie;
370 * If we're setting all cpus we can unbind. Otherwise make sure
371 * only one cpu is in the set.
373 if (CPU_CMP(cpuset_root, mask)) {
374 for (n = 0; n < CPU_SETSIZE; n++) {
375 if (!CPU_ISSET(n, mask))
382 ie = intr_lookup(irq);
385 return (intr_event_bind(ie, cpu));
389 intr_getaffinity(int irq, void *m)
391 struct intr_event *ie;
395 ie = intr_lookup(irq);
399 mtx_lock(&ie->ie_lock);
400 if (ie->ie_cpu == NOCPU)
401 CPU_COPY(cpuset_root, mask);
403 CPU_SET(ie->ie_cpu, mask);
404 mtx_unlock(&ie->ie_lock);
409 intr_event_destroy(struct intr_event *ie)
412 mtx_lock(&event_lock);
413 mtx_lock(&ie->ie_lock);
414 if (!TAILQ_EMPTY(&ie->ie_handlers)) {
415 mtx_unlock(&ie->ie_lock);
416 mtx_unlock(&event_lock);
419 TAILQ_REMOVE(&event_list, ie, ie_list);
421 if (ie->ie_thread != NULL) {
422 ithread_destroy(ie->ie_thread);
423 ie->ie_thread = NULL;
426 mtx_unlock(&ie->ie_lock);
427 mtx_unlock(&event_lock);
428 mtx_destroy(&ie->ie_lock);
434 static struct intr_thread *
435 ithread_create(const char *name)
437 struct intr_thread *ithd;
441 ithd = malloc(sizeof(struct intr_thread), M_ITHREAD, M_WAITOK | M_ZERO);
443 error = kproc_kthread_add(ithread_loop, ithd, &intrproc,
444 &td, RFSTOPPED | RFHIGHPID,
445 0, "intr", "%s", name);
447 panic("kproc_create() failed with %d", error);
449 sched_class(td, PRI_ITHD);
452 td->td_pflags |= TDP_ITHREAD;
453 ithd->it_thread = td;
454 CTR2(KTR_INTR, "%s: created %s", __func__, name);
458 static struct intr_thread *
459 ithread_create(const char *name, struct intr_handler *ih)
461 struct intr_thread *ithd;
465 ithd = malloc(sizeof(struct intr_thread), M_ITHREAD, M_WAITOK | M_ZERO);
467 error = kproc_kthread_add(ithread_loop, ih, &intrproc,
468 &td, RFSTOPPED | RFHIGHPID,
469 0, "intr", "%s", name);
471 panic("kproc_create() failed with %d", error);
473 sched_class(td, PRI_ITHD);
476 td->td_pflags |= TDP_ITHREAD;
477 ithd->it_thread = td;
478 CTR2(KTR_INTR, "%s: created %s", __func__, name);
484 ithread_destroy(struct intr_thread *ithread)
488 CTR2(KTR_INTR, "%s: killing %s", __func__, ithread->it_event->ie_name);
489 td = ithread->it_thread;
491 ithread->it_flags |= IT_DEAD;
492 if (TD_AWAITING_INTR(td)) {
494 sched_add(td, SRQ_INTR);
501 intr_event_add_handler(struct intr_event *ie, const char *name,
502 driver_filter_t filter, driver_intr_t handler, void *arg, u_char pri,
503 enum intr_type flags, void **cookiep)
505 struct intr_handler *ih, *temp_ih;
506 struct intr_thread *it;
508 if (ie == NULL || name == NULL || (handler == NULL && filter == NULL))
511 /* Allocate and populate an interrupt handler structure. */
512 ih = malloc(sizeof(struct intr_handler), M_ITHREAD, M_WAITOK | M_ZERO);
513 ih->ih_filter = filter;
514 ih->ih_handler = handler;
515 ih->ih_argument = arg;
516 strlcpy(ih->ih_name, name, sizeof(ih->ih_name));
519 if (flags & INTR_EXCL)
520 ih->ih_flags = IH_EXCLUSIVE;
521 if (flags & INTR_MPSAFE)
522 ih->ih_flags |= IH_MPSAFE;
523 if (flags & INTR_ENTROPY)
524 ih->ih_flags |= IH_ENTROPY;
526 /* We can only have one exclusive handler in a event. */
527 mtx_lock(&ie->ie_lock);
528 if (!TAILQ_EMPTY(&ie->ie_handlers)) {
529 if ((flags & INTR_EXCL) ||
530 (TAILQ_FIRST(&ie->ie_handlers)->ih_flags & IH_EXCLUSIVE)) {
531 mtx_unlock(&ie->ie_lock);
537 /* Create a thread if we need one. */
538 while (ie->ie_thread == NULL && handler != NULL) {
539 if (ie->ie_flags & IE_ADDING_THREAD)
540 msleep(ie, &ie->ie_lock, 0, "ithread", 0);
542 ie->ie_flags |= IE_ADDING_THREAD;
543 mtx_unlock(&ie->ie_lock);
544 it = ithread_create("intr: newborn");
545 mtx_lock(&ie->ie_lock);
546 ie->ie_flags &= ~IE_ADDING_THREAD;
554 /* Add the new handler to the event in priority order. */
555 TAILQ_FOREACH(temp_ih, &ie->ie_handlers, ih_next) {
556 if (temp_ih->ih_pri > ih->ih_pri)
560 TAILQ_INSERT_TAIL(&ie->ie_handlers, ih, ih_next);
562 TAILQ_INSERT_BEFORE(temp_ih, ih, ih_next);
563 intr_event_update(ie);
565 CTR3(KTR_INTR, "%s: added %s to %s", __func__, ih->ih_name,
567 mtx_unlock(&ie->ie_lock);
575 intr_event_add_handler(struct intr_event *ie, const char *name,
576 driver_filter_t filter, driver_intr_t handler, void *arg, u_char pri,
577 enum intr_type flags, void **cookiep)
579 struct intr_handler *ih, *temp_ih;
580 struct intr_thread *it;
582 if (ie == NULL || name == NULL || (handler == NULL && filter == NULL))
585 /* Allocate and populate an interrupt handler structure. */
586 ih = malloc(sizeof(struct intr_handler), M_ITHREAD, M_WAITOK | M_ZERO);
587 ih->ih_filter = filter;
588 ih->ih_handler = handler;
589 ih->ih_argument = arg;
590 strlcpy(ih->ih_name, name, sizeof(ih->ih_name));
593 if (flags & INTR_EXCL)
594 ih->ih_flags = IH_EXCLUSIVE;
595 if (flags & INTR_MPSAFE)
596 ih->ih_flags |= IH_MPSAFE;
597 if (flags & INTR_ENTROPY)
598 ih->ih_flags |= IH_ENTROPY;
600 /* We can only have one exclusive handler in a event. */
601 mtx_lock(&ie->ie_lock);
602 if (!TAILQ_EMPTY(&ie->ie_handlers)) {
603 if ((flags & INTR_EXCL) ||
604 (TAILQ_FIRST(&ie->ie_handlers)->ih_flags & IH_EXCLUSIVE)) {
605 mtx_unlock(&ie->ie_lock);
611 /* For filtered handlers, create a private ithread to run on. */
612 if (filter != NULL && handler != NULL) {
613 mtx_unlock(&ie->ie_lock);
614 it = ithread_create("intr: newborn", ih);
615 mtx_lock(&ie->ie_lock);
618 ithread_update(it); /* XXX - do we really need this?!?!? */
619 } else { /* Create the global per-event thread if we need one. */
620 while (ie->ie_thread == NULL && handler != NULL) {
621 if (ie->ie_flags & IE_ADDING_THREAD)
622 msleep(ie, &ie->ie_lock, 0, "ithread", 0);
624 ie->ie_flags |= IE_ADDING_THREAD;
625 mtx_unlock(&ie->ie_lock);
626 it = ithread_create("intr: newborn", ih);
627 mtx_lock(&ie->ie_lock);
628 ie->ie_flags &= ~IE_ADDING_THREAD;
637 /* Add the new handler to the event in priority order. */
638 TAILQ_FOREACH(temp_ih, &ie->ie_handlers, ih_next) {
639 if (temp_ih->ih_pri > ih->ih_pri)
643 TAILQ_INSERT_TAIL(&ie->ie_handlers, ih, ih_next);
645 TAILQ_INSERT_BEFORE(temp_ih, ih, ih_next);
646 intr_event_update(ie);
648 CTR3(KTR_INTR, "%s: added %s to %s", __func__, ih->ih_name,
650 mtx_unlock(&ie->ie_lock);
659 * Append a description preceded by a ':' to the name of the specified
663 intr_event_describe_handler(struct intr_event *ie, void *cookie,
666 struct intr_handler *ih;
670 mtx_lock(&ie->ie_lock);
672 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
677 mtx_unlock(&ie->ie_lock);
678 panic("handler %p not found in interrupt event %p", cookie, ie);
684 * Look for an existing description by checking for an
685 * existing ":". This assumes device names do not include
686 * colons. If one is found, prepare to insert the new
687 * description at that point. If one is not found, find the
688 * end of the name to use as the insertion point.
690 start = strchr(ih->ih_name, ':');
692 start = strchr(ih->ih_name, 0);
695 * See if there is enough remaining room in the string for the
696 * description + ":". The "- 1" leaves room for the trailing
697 * '\0'. The "+ 1" accounts for the colon.
699 space = sizeof(ih->ih_name) - (start - ih->ih_name) - 1;
700 if (strlen(descr) + 1 > space) {
701 mtx_unlock(&ie->ie_lock);
705 /* Append a colon followed by the description. */
707 strcpy(start + 1, descr);
708 intr_event_update(ie);
709 mtx_unlock(&ie->ie_lock);
714 * Return the ie_source field from the intr_event an intr_handler is
718 intr_handler_source(void *cookie)
720 struct intr_handler *ih;
721 struct intr_event *ie;
723 ih = (struct intr_handler *)cookie;
728 ("interrupt handler \"%s\" has a NULL interrupt event",
730 return (ie->ie_source);
734 * Sleep until an ithread finishes executing an interrupt handler.
736 * XXX Doesn't currently handle interrupt filters or fast interrupt
737 * handlers. This is intended for compatibility with linux drivers
738 * only. Do not use in BSD code.
743 struct intr_event *ie;
744 struct intr_thread *ithd;
747 ie = intr_lookup(irq);
750 if (ie->ie_thread == NULL)
752 ithd = ie->ie_thread;
753 td = ithd->it_thread;
755 * We set the flag and wait for it to be cleared to avoid
756 * long delays with potentially busy interrupt handlers
757 * were we to only sample TD_AWAITING_INTR() every tick.
760 if (!TD_AWAITING_INTR(td)) {
761 ithd->it_flags |= IT_WAIT;
762 while (ithd->it_flags & IT_WAIT) {
775 intr_event_remove_handler(void *cookie)
777 struct intr_handler *handler = (struct intr_handler *)cookie;
778 struct intr_event *ie;
780 struct intr_handler *ih;
788 ie = handler->ih_event;
790 ("interrupt handler \"%s\" has a NULL interrupt event",
792 mtx_lock(&ie->ie_lock);
793 CTR3(KTR_INTR, "%s: removing %s from %s", __func__, handler->ih_name,
796 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next)
799 mtx_unlock(&ie->ie_lock);
800 panic("interrupt handler \"%s\" not found in interrupt event \"%s\"",
801 ih->ih_name, ie->ie_name);
805 * If there is no ithread, then just remove the handler and return.
806 * XXX: Note that an INTR_FAST handler might be running on another
809 if (ie->ie_thread == NULL) {
810 TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next);
811 mtx_unlock(&ie->ie_lock);
812 free(handler, M_ITHREAD);
817 * If the interrupt thread is already running, then just mark this
818 * handler as being dead and let the ithread do the actual removal.
820 * During a cold boot while cold is set, msleep() does not sleep,
821 * so we have to remove the handler here rather than letting the
824 thread_lock(ie->ie_thread->it_thread);
825 if (!TD_AWAITING_INTR(ie->ie_thread->it_thread) && !cold) {
826 handler->ih_flags |= IH_DEAD;
829 * Ensure that the thread will process the handler list
830 * again and remove this handler if it has already passed
833 * The release part of the following store ensures
834 * that the update of ih_flags is ordered before the
835 * it_need setting. See the comment before
836 * atomic_cmpset_acq(&ithd->it_need, ...) operation in
837 * the ithread_execute_handlers().
839 atomic_store_rel_int(&ie->ie_thread->it_need, 1);
841 TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next);
842 thread_unlock(ie->ie_thread->it_thread);
843 while (handler->ih_flags & IH_DEAD)
844 msleep(handler, &ie->ie_lock, 0, "iev_rmh", 0);
845 intr_event_update(ie);
848 * XXX: This could be bad in the case of ppbus(8). Also, I think
849 * this could lead to races of stale data when servicing an
853 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
854 if (!(ih->ih_flags & IH_FAST)) {
860 ithread_destroy(ie->ie_thread);
861 ie->ie_thread = NULL;
864 mtx_unlock(&ie->ie_lock);
865 free(handler, M_ITHREAD);
870 intr_event_schedule_thread(struct intr_event *ie)
872 struct intr_entropy entropy;
873 struct intr_thread *it;
879 * If no ithread or no handlers, then we have a stray interrupt.
881 if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers) ||
882 ie->ie_thread == NULL)
891 * If any of the handlers for this ithread claim to be good
892 * sources of entropy, then gather some.
894 if (ie->ie_flags & IE_ENTROPY) {
895 entropy.event = (uintptr_t)ie;
897 random_harvest_queue(&entropy, sizeof(entropy), 2, RANDOM_INTERRUPT);
900 KASSERT(p != NULL, ("ithread %s has no process", ie->ie_name));
903 * Set it_need to tell the thread to keep running if it is already
904 * running. Then, lock the thread and see if we actually need to
905 * put it on the runqueue.
907 * Use store_rel to arrange that the store to ih_need in
908 * swi_sched() is before the store to it_need and prepare for
909 * transfer of this order to loads in the ithread.
911 atomic_store_rel_int(&it->it_need, 1);
913 if (TD_AWAITING_INTR(td)) {
914 CTR3(KTR_INTR, "%s: schedule pid %d (%s)", __func__, p->p_pid,
917 sched_add(td, SRQ_INTR);
919 CTR5(KTR_INTR, "%s: pid %d (%s): it_need %d, state %d",
920 __func__, p->p_pid, td->td_name, it->it_need, td->td_state);
928 intr_event_remove_handler(void *cookie)
930 struct intr_handler *handler = (struct intr_handler *)cookie;
931 struct intr_event *ie;
932 struct intr_thread *it;
934 struct intr_handler *ih;
942 ie = handler->ih_event;
944 ("interrupt handler \"%s\" has a NULL interrupt event",
946 mtx_lock(&ie->ie_lock);
947 CTR3(KTR_INTR, "%s: removing %s from %s", __func__, handler->ih_name,
950 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next)
953 mtx_unlock(&ie->ie_lock);
954 panic("interrupt handler \"%s\" not found in interrupt event \"%s\"",
955 ih->ih_name, ie->ie_name);
959 * If there are no ithreads (per event and per handler), then
960 * just remove the handler and return.
961 * XXX: Note that an INTR_FAST handler might be running on another CPU!
963 if (ie->ie_thread == NULL && handler->ih_thread == NULL) {
964 TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next);
965 mtx_unlock(&ie->ie_lock);
966 free(handler, M_ITHREAD);
970 /* Private or global ithread? */
971 it = (handler->ih_thread) ? handler->ih_thread : ie->ie_thread;
973 * If the interrupt thread is already running, then just mark this
974 * handler as being dead and let the ithread do the actual removal.
976 * During a cold boot while cold is set, msleep() does not sleep,
977 * so we have to remove the handler here rather than letting the
980 thread_lock(it->it_thread);
981 if (!TD_AWAITING_INTR(it->it_thread) && !cold) {
982 handler->ih_flags |= IH_DEAD;
985 * Ensure that the thread will process the handler list
986 * again and remove this handler if it has already passed
989 * The release part of the following store ensures
990 * that the update of ih_flags is ordered before the
991 * it_need setting. See the comment before
992 * atomic_cmpset_acq(&ithd->it_need, ...) operation in
993 * the ithread_execute_handlers().
995 atomic_store_rel_int(&it->it_need, 1);
997 TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next);
998 thread_unlock(it->it_thread);
999 while (handler->ih_flags & IH_DEAD)
1000 msleep(handler, &ie->ie_lock, 0, "iev_rmh", 0);
1002 * At this point, the handler has been disconnected from the event,
1003 * so we can kill the private ithread if any.
1005 if (handler->ih_thread) {
1006 ithread_destroy(handler->ih_thread);
1007 handler->ih_thread = NULL;
1009 intr_event_update(ie);
1012 * XXX: This could be bad in the case of ppbus(8). Also, I think
1013 * this could lead to races of stale data when servicing an
1017 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
1018 if (handler != NULL) {
1024 ithread_destroy(ie->ie_thread);
1025 ie->ie_thread = NULL;
1028 mtx_unlock(&ie->ie_lock);
1029 free(handler, M_ITHREAD);
1034 intr_event_schedule_thread(struct intr_event *ie, struct intr_thread *it)
1036 struct intr_entropy entropy;
1042 * If no ithread or no handlers, then we have a stray interrupt.
1044 if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers) || it == NULL)
1052 * If any of the handlers for this ithread claim to be good
1053 * sources of entropy, then gather some.
1055 if (ie->ie_flags & IE_ENTROPY) {
1056 entropy.event = (uintptr_t)ie;
1058 random_harvest_queue(&entropy, sizeof(entropy), 2, RANDOM_INTERRUPT);
1061 KASSERT(p != NULL, ("ithread %s has no process", ie->ie_name));
1064 * Set it_need to tell the thread to keep running if it is already
1065 * running. Then, lock the thread and see if we actually need to
1066 * put it on the runqueue.
1068 * Use store_rel to arrange that the store to ih_need in
1069 * swi_sched() is before the store to it_need and prepare for
1070 * transfer of this order to loads in the ithread.
1072 atomic_store_rel_int(&it->it_need, 1);
1074 if (TD_AWAITING_INTR(td)) {
1075 CTR3(KTR_INTR, "%s: schedule pid %d (%s)", __func__, p->p_pid,
1078 sched_add(td, SRQ_INTR);
1080 CTR5(KTR_INTR, "%s: pid %d (%s): it_need %d, state %d",
1081 __func__, p->p_pid, td->td_name, it->it_need, td->td_state);
1090 * Allow interrupt event binding for software interrupt handlers -- a no-op,
1091 * since interrupts are generated in software rather than being directed by
1095 swi_assign_cpu(void *arg, int cpu)
1102 * Add a software interrupt handler to a specified event. If a given event
1103 * is not specified, then a new event is created.
1106 swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler,
1107 void *arg, int pri, enum intr_type flags, void **cookiep)
1109 struct intr_event *ie;
1112 if (flags & INTR_ENTROPY)
1115 ie = (eventp != NULL) ? *eventp : NULL;
1118 if (!(ie->ie_flags & IE_SOFT))
1121 error = intr_event_create(&ie, NULL, IE_SOFT, 0,
1122 NULL, NULL, NULL, swi_assign_cpu, "swi%d:", pri);
1128 error = intr_event_add_handler(ie, name, NULL, handler, arg,
1129 PI_SWI(pri), flags, cookiep);
1134 * Schedule a software interrupt thread.
1137 swi_sched(void *cookie, int flags)
1139 struct intr_handler *ih = (struct intr_handler *)cookie;
1140 struct intr_event *ie = ih->ih_event;
1141 struct intr_entropy entropy;
1144 CTR3(KTR_INTR, "swi_sched: %s %s need=%d", ie->ie_name, ih->ih_name,
1147 entropy.event = (uintptr_t)ih;
1148 entropy.td = curthread;
1149 random_harvest_queue(&entropy, sizeof(entropy), 1, RANDOM_SWI);
1152 * Set ih_need for this handler so that if the ithread is already
1153 * running it will execute this handler on the next pass. Otherwise,
1154 * it will execute it the next time it runs.
1158 if (!(flags & SWI_DELAY)) {
1159 PCPU_INC(cnt.v_soft);
1161 error = intr_event_schedule_thread(ie, ie->ie_thread);
1163 error = intr_event_schedule_thread(ie);
1165 KASSERT(error == 0, ("stray software interrupt"));
1170 * Remove a software interrupt handler. Currently this code does not
1171 * remove the associated interrupt event if it becomes empty. Calling code
1172 * may do so manually via intr_event_destroy(), but that's not really
1173 * an optimal interface.
1176 swi_remove(void *cookie)
1179 return (intr_event_remove_handler(cookie));
1184 priv_ithread_execute_handler(struct proc *p, struct intr_handler *ih)
1186 struct intr_event *ie;
1190 * If this handler is marked for death, remove it from
1191 * the list of handlers and wake up the sleeper.
1193 if (ih->ih_flags & IH_DEAD) {
1194 mtx_lock(&ie->ie_lock);
1195 TAILQ_REMOVE(&ie->ie_handlers, ih, ih_next);
1196 ih->ih_flags &= ~IH_DEAD;
1198 mtx_unlock(&ie->ie_lock);
1202 /* Execute this handler. */
1203 CTR6(KTR_INTR, "%s: pid %d exec %p(%p) for %s flg=%x",
1204 __func__, p->p_pid, (void *)ih->ih_handler, ih->ih_argument,
1205 ih->ih_name, ih->ih_flags);
1207 if (!(ih->ih_flags & IH_MPSAFE))
1209 ih->ih_handler(ih->ih_argument);
1210 if (!(ih->ih_flags & IH_MPSAFE))
1216 * This is a public function for use by drivers that mux interrupt
1217 * handlers for child devices from their interrupt handler.
1220 intr_event_execute_handlers(struct proc *p, struct intr_event *ie)
1222 struct intr_handler *ih, *ihn;
1224 TAILQ_FOREACH_SAFE(ih, &ie->ie_handlers, ih_next, ihn) {
1226 * If this handler is marked for death, remove it from
1227 * the list of handlers and wake up the sleeper.
1229 if (ih->ih_flags & IH_DEAD) {
1230 mtx_lock(&ie->ie_lock);
1231 TAILQ_REMOVE(&ie->ie_handlers, ih, ih_next);
1232 ih->ih_flags &= ~IH_DEAD;
1234 mtx_unlock(&ie->ie_lock);
1238 /* Skip filter only handlers */
1239 if (ih->ih_handler == NULL)
1243 * For software interrupt threads, we only execute
1244 * handlers that have their need flag set. Hardware
1245 * interrupt threads always invoke all of their handlers.
1247 * ih_need can only be 0 or 1. Failed cmpset below
1248 * means that there is no request to execute handlers,
1249 * so a retry of the cmpset is not needed.
1251 if ((ie->ie_flags & IE_SOFT) != 0 &&
1252 atomic_cmpset_int(&ih->ih_need, 1, 0) == 0)
1255 /* Execute this handler. */
1256 CTR6(KTR_INTR, "%s: pid %d exec %p(%p) for %s flg=%x",
1257 __func__, p->p_pid, (void *)ih->ih_handler,
1258 ih->ih_argument, ih->ih_name, ih->ih_flags);
1260 if (!(ih->ih_flags & IH_MPSAFE))
1262 ih->ih_handler(ih->ih_argument);
1263 if (!(ih->ih_flags & IH_MPSAFE))
1269 ithread_execute_handlers(struct proc *p, struct intr_event *ie)
1272 /* Interrupt handlers should not sleep. */
1273 if (!(ie->ie_flags & IE_SOFT))
1274 THREAD_NO_SLEEPING();
1275 intr_event_execute_handlers(p, ie);
1276 if (!(ie->ie_flags & IE_SOFT))
1277 THREAD_SLEEPING_OK();
1280 * Interrupt storm handling:
1282 * If this interrupt source is currently storming, then throttle
1283 * it to only fire the handler once per clock tick.
1285 * If this interrupt source is not currently storming, but the
1286 * number of back to back interrupts exceeds the storm threshold,
1287 * then enter storming mode.
1289 if (intr_storm_threshold != 0 && ie->ie_count >= intr_storm_threshold &&
1290 !(ie->ie_flags & IE_SOFT)) {
1291 /* Report the message only once every second. */
1292 if (ppsratecheck(&ie->ie_warntm, &ie->ie_warncnt, 1)) {
1294 "interrupt storm detected on \"%s\"; throttling interrupt source\n",
1302 * Now that all the handlers have had a chance to run, reenable
1303 * the interrupt source.
1305 if (ie->ie_post_ithread != NULL)
1306 ie->ie_post_ithread(ie->ie_source);
1311 * This is the main code for interrupt threads.
1314 ithread_loop(void *arg)
1316 struct intr_thread *ithd;
1317 struct intr_event *ie;
1324 ithd = (struct intr_thread *)arg;
1325 KASSERT(ithd->it_thread == td,
1326 ("%s: ithread and proc linkage out of sync", __func__));
1327 ie = ithd->it_event;
1332 * As long as we have interrupts outstanding, go through the
1333 * list of handlers, giving each one a go at it.
1337 * If we are an orphaned thread, then just die.
1339 if (ithd->it_flags & IT_DEAD) {
1340 CTR3(KTR_INTR, "%s: pid %d (%s) exiting", __func__,
1341 p->p_pid, td->td_name);
1342 free(ithd, M_ITHREAD);
1347 * Service interrupts. If another interrupt arrives while
1348 * we are running, it will set it_need to note that we
1349 * should make another pass.
1351 * The load_acq part of the following cmpset ensures
1352 * that the load of ih_need in ithread_execute_handlers()
1353 * is ordered after the load of it_need here.
1355 while (atomic_cmpset_acq_int(&ithd->it_need, 1, 0) != 0)
1356 ithread_execute_handlers(p, ie);
1357 WITNESS_WARN(WARN_PANIC, NULL, "suspending ithread");
1358 mtx_assert(&Giant, MA_NOTOWNED);
1361 * Processed all our interrupts. Now get the sched
1362 * lock. This may take a while and it_need may get
1363 * set again, so we have to check it again.
1366 if (atomic_load_acq_int(&ithd->it_need) == 0 &&
1367 (ithd->it_flags & (IT_DEAD | IT_WAIT)) == 0) {
1370 mi_switch(SW_VOL | SWT_IWAIT, NULL);
1372 if (ithd->it_flags & IT_WAIT) {
1374 ithd->it_flags &= ~IT_WAIT;
1385 * Main interrupt handling body.
1388 * o ie: the event connected to this interrupt.
1389 * o frame: some archs (i.e. i386) pass a frame to some.
1390 * handlers as their main argument.
1392 * o 0: everything ok.
1393 * o EINVAL: stray interrupt.
1396 intr_event_handle(struct intr_event *ie, struct trapframe *frame)
1398 struct intr_handler *ih;
1399 struct trapframe *oldframe;
1401 int error, ret, thread;
1405 #ifdef KSTACK_USAGE_PROF
1406 intr_prof_stack_use(td, frame);
1409 /* An interrupt with no event or handlers is a stray interrupt. */
1410 if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers))
1414 * Execute fast interrupt handlers directly.
1415 * To support clock handlers, if a handler registers
1416 * with a NULL argument, then we pass it a pointer to
1417 * a trapframe as its argument.
1419 td->td_intr_nesting_level++;
1423 oldframe = td->td_intr_frame;
1424 td->td_intr_frame = frame;
1425 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
1426 if (ih->ih_filter == NULL) {
1430 CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__,
1431 ih->ih_filter, ih->ih_argument == NULL ? frame :
1432 ih->ih_argument, ih->ih_name);
1433 if (ih->ih_argument == NULL)
1434 ret = ih->ih_filter(frame);
1436 ret = ih->ih_filter(ih->ih_argument);
1437 KASSERT(ret == FILTER_STRAY ||
1438 ((ret & (FILTER_SCHEDULE_THREAD | FILTER_HANDLED)) != 0 &&
1439 (ret & ~(FILTER_SCHEDULE_THREAD | FILTER_HANDLED)) == 0),
1440 ("%s: incorrect return value %#x from %s", __func__, ret,
1444 * Wrapper handler special handling:
1446 * in some particular cases (like pccard and pccbb),
1447 * the _real_ device handler is wrapped in a couple of
1448 * functions - a filter wrapper and an ithread wrapper.
1449 * In this case (and just in this case), the filter wrapper
1450 * could ask the system to schedule the ithread and mask
1451 * the interrupt source if the wrapped handler is composed
1452 * of just an ithread handler.
1454 * TODO: write a generic wrapper to avoid people rolling
1458 if (ret == FILTER_SCHEDULE_THREAD)
1462 td->td_intr_frame = oldframe;
1465 if (ie->ie_pre_ithread != NULL)
1466 ie->ie_pre_ithread(ie->ie_source);
1468 if (ie->ie_post_filter != NULL)
1469 ie->ie_post_filter(ie->ie_source);
1472 /* Schedule the ithread if needed. */
1474 error = intr_event_schedule_thread(ie);
1475 KASSERT(error == 0, ("bad stray interrupt"));
1478 td->td_intr_nesting_level--;
1483 * This is the main code for interrupt threads.
1486 ithread_loop(void *arg)
1488 struct intr_thread *ithd;
1489 struct intr_handler *ih;
1490 struct intr_event *ie;
1498 ih = (struct intr_handler *)arg;
1499 priv = (ih->ih_thread != NULL) ? 1 : 0;
1500 ithd = (priv) ? ih->ih_thread : ih->ih_event->ie_thread;
1501 KASSERT(ithd->it_thread == td,
1502 ("%s: ithread and proc linkage out of sync", __func__));
1503 ie = ithd->it_event;
1508 * As long as we have interrupts outstanding, go through the
1509 * list of handlers, giving each one a go at it.
1513 * If we are an orphaned thread, then just die.
1515 if (ithd->it_flags & IT_DEAD) {
1516 CTR3(KTR_INTR, "%s: pid %d (%s) exiting", __func__,
1517 p->p_pid, td->td_name);
1518 free(ithd, M_ITHREAD);
1523 * Service interrupts. If another interrupt arrives while
1524 * we are running, it will set it_need to note that we
1525 * should make another pass.
1527 * The load_acq part of the following cmpset ensures
1528 * that the load of ih_need in ithread_execute_handlers()
1529 * is ordered after the load of it_need here.
1531 while (atomic_cmpset_acq_int(&ithd->it_need, 1, 0) != 0) {
1533 priv_ithread_execute_handler(p, ih);
1535 ithread_execute_handlers(p, ie);
1537 WITNESS_WARN(WARN_PANIC, NULL, "suspending ithread");
1538 mtx_assert(&Giant, MA_NOTOWNED);
1541 * Processed all our interrupts. Now get the sched
1542 * lock. This may take a while and it_need may get
1543 * set again, so we have to check it again.
1546 if (atomic_load_acq_int(&ithd->it_need) == 0 &&
1547 (ithd->it_flags & (IT_DEAD | IT_WAIT)) == 0) {
1550 mi_switch(SW_VOL | SWT_IWAIT, NULL);
1552 if (ithd->it_flags & IT_WAIT) {
1554 ithd->it_flags &= ~IT_WAIT;
1565 * Main loop for interrupt filter.
1567 * Some architectures (i386, amd64 and arm) require the optional frame
1568 * parameter, and use it as the main argument for fast handler execution
1569 * when ih_argument == NULL.
1572 * o FILTER_STRAY: No filter recognized the event, and no
1573 * filter-less handler is registered on this
1575 * o FILTER_HANDLED: A filter claimed the event and served it.
1576 * o FILTER_SCHEDULE_THREAD: No filter claimed the event, but there's at
1577 * least one filter-less handler on this line.
1578 * o FILTER_HANDLED |
1579 * FILTER_SCHEDULE_THREAD: A filter claimed the event, and asked for
1580 * scheduling the per-handler ithread.
1582 * In case an ithread has to be scheduled, in *ithd there will be a
1583 * pointer to a struct intr_thread containing the thread to be
1588 intr_filter_loop(struct intr_event *ie, struct trapframe *frame,
1589 struct intr_thread **ithd)
1591 struct intr_handler *ih;
1593 int ret, thread_only;
1597 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
1599 * Execute fast interrupt handlers directly.
1600 * To support clock handlers, if a handler registers
1601 * with a NULL argument, then we pass it a pointer to
1602 * a trapframe as its argument.
1604 arg = ((ih->ih_argument == NULL) ? frame : ih->ih_argument);
1606 CTR5(KTR_INTR, "%s: exec %p/%p(%p) for %s", __func__,
1607 ih->ih_filter, ih->ih_handler, arg, ih->ih_name);
1609 if (ih->ih_filter != NULL)
1610 ret = ih->ih_filter(arg);
1615 KASSERT(ret == FILTER_STRAY ||
1616 ((ret & (FILTER_SCHEDULE_THREAD | FILTER_HANDLED)) != 0 &&
1617 (ret & ~(FILTER_SCHEDULE_THREAD | FILTER_HANDLED)) == 0),
1618 ("%s: incorrect return value %#x from %s", __func__, ret,
1620 if (ret & FILTER_STRAY)
1623 *ithd = ih->ih_thread;
1629 * No filters handled the interrupt and we have at least
1630 * one handler without a filter. In this case, we schedule
1631 * all of the filter-less handlers to run in the ithread.
1634 *ithd = ie->ie_thread;
1635 return (FILTER_SCHEDULE_THREAD);
1637 return (FILTER_STRAY);
1641 * Main interrupt handling body.
1644 * o ie: the event connected to this interrupt.
1645 * o frame: some archs (i.e. i386) pass a frame to some.
1646 * handlers as their main argument.
1648 * o 0: everything ok.
1649 * o EINVAL: stray interrupt.
1652 intr_event_handle(struct intr_event *ie, struct trapframe *frame)
1654 struct intr_thread *ithd;
1655 struct trapframe *oldframe;
1662 if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers))
1665 td->td_intr_nesting_level++;
1668 oldframe = td->td_intr_frame;
1669 td->td_intr_frame = frame;
1670 thread = intr_filter_loop(ie, frame, &ithd);
1671 if (thread & FILTER_HANDLED) {
1672 if (ie->ie_post_filter != NULL)
1673 ie->ie_post_filter(ie->ie_source);
1675 if (ie->ie_pre_ithread != NULL)
1676 ie->ie_pre_ithread(ie->ie_source);
1678 td->td_intr_frame = oldframe;
1681 /* Interrupt storm logic */
1682 if (thread & FILTER_STRAY) {
1684 if (ie->ie_count < intr_storm_threshold)
1685 printf("Interrupt stray detection not present\n");
1688 /* Schedule an ithread if needed. */
1689 if (thread & FILTER_SCHEDULE_THREAD) {
1690 if (intr_event_schedule_thread(ie, ithd) != 0)
1691 panic("%s: impossible stray interrupt", __func__);
1693 td->td_intr_nesting_level--;
1700 * Dump details about an interrupt handler
1703 db_dump_intrhand(struct intr_handler *ih)
1707 db_printf("\t%-10s ", ih->ih_name);
1708 switch (ih->ih_pri) {
1728 if (ih->ih_pri >= PI_SOFT)
1731 db_printf("%4u", ih->ih_pri);
1735 if (ih->ih_filter != NULL) {
1737 db_printsym((uintptr_t)ih->ih_filter, DB_STGY_PROC);
1739 if (ih->ih_handler != NULL) {
1740 if (ih->ih_filter != NULL)
1743 db_printsym((uintptr_t)ih->ih_handler, DB_STGY_PROC);
1745 db_printf("(%p)", ih->ih_argument);
1747 (ih->ih_flags & (IH_EXCLUSIVE | IH_ENTROPY | IH_DEAD |
1751 if (ih->ih_flags & IH_EXCLUSIVE) {
1757 if (ih->ih_flags & IH_ENTROPY) {
1760 db_printf("ENTROPY");
1763 if (ih->ih_flags & IH_DEAD) {
1769 if (ih->ih_flags & IH_MPSAFE) {
1772 db_printf("MPSAFE");
1786 * Dump details about a event.
1789 db_dump_intr_event(struct intr_event *ie, int handlers)
1791 struct intr_handler *ih;
1792 struct intr_thread *it;
1795 db_printf("%s ", ie->ie_fullname);
1798 db_printf("(pid %d)", it->it_thread->td_proc->p_pid);
1800 db_printf("(no thread)");
1801 if ((ie->ie_flags & (IE_SOFT | IE_ENTROPY | IE_ADDING_THREAD)) != 0 ||
1802 (it != NULL && it->it_need)) {
1805 if (ie->ie_flags & IE_SOFT) {
1809 if (ie->ie_flags & IE_ENTROPY) {
1812 db_printf("ENTROPY");
1815 if (ie->ie_flags & IE_ADDING_THREAD) {
1818 db_printf("ADDING_THREAD");
1821 if (it != NULL && it->it_need) {
1831 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next)
1832 db_dump_intrhand(ih);
1836 * Dump data about interrupt handlers
1838 DB_SHOW_COMMAND(intr, db_show_intr)
1840 struct intr_event *ie;
1843 verbose = strchr(modif, 'v') != NULL;
1844 all = strchr(modif, 'a') != NULL;
1845 TAILQ_FOREACH(ie, &event_list, ie_list) {
1846 if (!all && TAILQ_EMPTY(&ie->ie_handlers))
1848 db_dump_intr_event(ie, verbose);
1856 * Start standard software interrupt threads
1859 start_softintr(void *dummy)
1862 if (swi_add(NULL, "vm", swi_vm, NULL, SWI_VM, INTR_MPSAFE, &vm_ih))
1863 panic("died while creating vm swi ithread");
1865 SYSINIT(start_softintr, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softintr,
1869 * Sysctls used by systat and others: hw.intrnames and hw.intrcnt.
1870 * The data for this machine dependent, and the declarations are in machine
1871 * dependent code. The layout of intrnames and intrcnt however is machine
1874 * We do not know the length of intrcnt and intrnames at compile time, so
1875 * calculate things at run time.
1878 sysctl_intrnames(SYSCTL_HANDLER_ARGS)
1880 return (sysctl_handle_opaque(oidp, intrnames, sintrnames, req));
1883 SYSCTL_PROC(_hw, OID_AUTO, intrnames, CTLTYPE_OPAQUE | CTLFLAG_RD,
1884 NULL, 0, sysctl_intrnames, "", "Interrupt Names");
1887 sysctl_intrcnt(SYSCTL_HANDLER_ARGS)
1890 uint32_t *intrcnt32;
1894 if (req->flags & SCTL_MASK32) {
1896 return (sysctl_handle_opaque(oidp, NULL, sintrcnt / 2, req));
1897 intrcnt32 = malloc(sintrcnt / 2, M_TEMP, M_NOWAIT);
1898 if (intrcnt32 == NULL)
1900 for (i = 0; i < sintrcnt / sizeof (u_long); i++)
1901 intrcnt32[i] = intrcnt[i];
1902 error = sysctl_handle_opaque(oidp, intrcnt32, sintrcnt / 2, req);
1903 free(intrcnt32, M_TEMP);
1907 return (sysctl_handle_opaque(oidp, intrcnt, sintrcnt, req));
1910 SYSCTL_PROC(_hw, OID_AUTO, intrcnt, CTLTYPE_OPAQUE | CTLFLAG_RD,
1911 NULL, 0, sysctl_intrcnt, "", "Interrupt Counts");
1915 * DDB command to dump the interrupt statistics.
1917 DB_SHOW_COMMAND(intrcnt, db_show_intrcnt)
1925 for (i = intrcnt; j < (sintrcnt / sizeof(u_long)) && !db_pager_quit;
1930 db_printf("%s\t%lu\n", cp, *i);
1931 cp += strlen(cp) + 1;