diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -290,7 +290,8 @@ /* The flags valid during creation are IE_SOFT and IE_MULTIPROC. */ if ((flags & ~(IE_SOFT | IE_MULTIPROC)) != 0) return (EINVAL); - ie = malloc(sizeof(struct intr_event), M_ITHREAD, M_WAITOK | M_ZERO); + ie = malloc(sizeof(struct intr_event) + (flags & IE_MULTIPROC ? + sizeof(u_long) * (mp_ncpus - 1) : 0), M_ITHREAD, M_WAITOK | M_ZERO); ie->ie_source = source; ie->ie_pre_ithread = pre_ithread; ie->ie_post_ithread = post_ithread; @@ -299,6 +300,7 @@ ie->ie_flags = flags; ie->ie_irq = irq; ie->ie_cpu = NOCPU; + /* ->ie_stray and ->ie_intrcnt[] handled by M_ZERO */ CK_SLIST_INIT(&ie->ie_handlers); mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF); @@ -1388,9 +1390,29 @@ intr_prof_stack_use(td, frame); #endif - /* An interrupt with no event or handlers is a stray interrupt. */ - if (ie == NULL || CK_SLIST_EMPTY(&ie->ie_handlers)) + /* An interrupt with no event is a stray interrupt. */ + if (ie == NULL) + return (EINVAL); + + /* + * Note about interrupt counters. Having per-processor counters avoids + * the need for atomic increment of counters. Whereas other interrupt + * types will be bound to a single processor and not need atomics. + * Per-processor interrupts are *never* flagged as stray, so stray + * counters don't need atomic increment. + */ + + /* Increment the interrupt counter. */ + if (__predict_false(ie->ie_flags & IE_MULTIPROC)) + ++ie->ie_intrcnt[curcpu]; + else + ++ie->ie_intrcnt[0]; + + /* An interrupt with no handlers is a stray interrupt. */ + if (CK_SLIST_EMPTY(&ie->ie_handlers)) { + ++ie->ie_stray; return (EINVAL); + } /* * Execute fast interrupt handlers directly. @@ -1491,8 +1513,10 @@ td->td_intr_nesting_level--; #ifdef notyet /* The interrupt is not aknowledged by any filter and has no ithread. */ - if (!thread && !filter) + if (!thread && !filter) { + ++ie->ie_stray; return (EINVAL); + } #endif return (0); } diff --git a/sys/sys/interrupt.h b/sys/sys/interrupt.h --- a/sys/sys/interrupt.h +++ b/sys/sys/interrupt.h @@ -127,6 +127,8 @@ int ie_cpu; /* CPU this event is bound to. */ volatile int ie_phase; /* Switched to establish a barrier. */ volatile int ie_active[2]; /* Filters in ISR context. */ + u_long ie_stray; /* Stray interrupt counter */ + u_long ie_intrcnt[1]; /* Interrupt counter(s) */ }; /* Interrupt event flags kept in ie_flags. */