From: Sepherosa Ziehau Date: Fri, 28 Oct 2011 15:33:11 +0000 (+0800) Subject: intr: Pass cpuid to register_int and unregister_int X-Git-Url: https://gitweb.dragonflybsd.org/~mneumann/dragonfly.git/commitdiff_plain/6355d931731b539fa8e3a95867975267f1dc00ed?ds=sidebyside intr: Pass cpuid to register_int and unregister_int --- diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c index 101bc88a27..e0ad8fa56c 100644 --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -119,7 +119,7 @@ static void emergency_intr_timer_callback(systimer_t, int, struct intrframe *); static void ithread_handler(void *arg); static void ithread_emergency(void *arg); static void report_stray_interrupt(int intr, struct intr_info *info); -static void int_moveto_destcpu(int *, int *, int); +static void int_moveto_destcpu(int *, int); static void int_moveto_origcpu(int, int); int intr_info_size = NELEM(intr_info_ary); @@ -206,7 +206,7 @@ register_swi(int intr, inthand2_t *handler, void *arg, const char *name, { if (intr < FIRST_SOFTINT || intr >= MAX_INTS) panic("register_swi: bad intr %d", intr); - return(register_int(intr, handler, arg, name, serializer, 0)); + return(register_int(intr, handler, arg, name, serializer, 0, 0)); } void * @@ -215,17 +215,19 @@ register_swi_mp(int intr, inthand2_t *handler, void *arg, const char *name, { if (intr < FIRST_SOFTINT || intr >= MAX_INTS) panic("register_swi: bad intr %d", intr); - return(register_int(intr, handler, arg, name, serializer, INTR_MPSAFE)); + return(register_int(intr, handler, arg, name, serializer, INTR_MPSAFE, 0)); } void * register_int(int intr, inthand2_t *handler, void *arg, const char *name, - struct lwkt_serialize *serializer, int intr_flags) + struct lwkt_serialize *serializer, int intr_flags, int cpuid) { struct intr_info *info; struct intrec **list; intrec_t rec; - int orig_cpuid, cpuid; + int orig_cpuid; + + KKASSERT(cpuid >= 0 && cpuid < ncpus); if (intr < 0 || intr >= MAX_INTS) panic("register_int: bad intr %d", intr); @@ -260,18 +262,16 @@ register_int(int intr, inthand2_t *handler, void *arg, const char *name, (emergency_intr_enable ? emergency_intr_freq : 1)); } - int_moveto_destcpu(&orig_cpuid, &cpuid, intr); + int_moveto_destcpu(&orig_cpuid, cpuid); /* * Create an interrupt thread if necessary, leave it in an unscheduled * state. - * - * Put it on cpu 0 for now, other work is pending related to this. */ if (info->i_state == ISTATE_NOTHREAD) { info->i_state = ISTATE_NORMAL; lwkt_create(ithread_handler, (void *)(intptr_t)intr, NULL, - &info->i_thread, TDF_STOPREQ | TDF_INTTHREAD, 0, + &info->i_thread, TDF_STOPREQ | TDF_INTTHREAD, cpuid, "ithread %d", intr); if (intr >= FIRST_SOFTINT) lwkt_setpri(&info->i_thread, TDPRI_SOFT_NORM); @@ -337,16 +337,18 @@ register_int(int intr, inthand2_t *handler, void *arg, const char *name, void unregister_swi(void *id) { - unregister_int(id); + unregister_int(id, 0); } void -unregister_int(void *id) +unregister_int(void *id, int cpuid) { struct intr_info *info; struct intrec **list; intrec_t rec; - int intr, orig_cpuid, cpuid; + int intr, orig_cpuid; + + KKASSERT(cpuid >= 0 && cpuid < ncpus); intr = ((intrec_t)id)->intr; @@ -355,7 +357,7 @@ unregister_int(void *id) info = &intr_info_ary[intr]; - int_moveto_destcpu(&orig_cpuid, &cpuid, intr); + int_moveto_destcpu(&orig_cpuid, cpuid); /* * Remove the interrupt descriptor, adjust the descriptor count, @@ -1099,22 +1101,14 @@ SYSCTL_PROC(_hw, OID_AUTO, intrcnt_all, CTLTYPE_OPAQUE | CTLFLAG_RD, NULL, 0, sysctl_intrcnt_all, "", "Interrupt Counts"); static void -int_moveto_destcpu(int *orig_cpuid0, int *cpuid0, int intr) +int_moveto_destcpu(int *orig_cpuid0, int cpuid) { - int orig_cpuid = mycpuid, cpuid; - char envpath[32]; - - cpuid = orig_cpuid; - ksnprintf(envpath, sizeof(envpath), "hw.irq.%d.dest", intr); - kgetenv_int(envpath, &cpuid); - if (cpuid >= ncpus) - cpuid = orig_cpuid; + int orig_cpuid = mycpuid; if (cpuid != orig_cpuid) lwkt_migratecpu(cpuid); *orig_cpuid0 = orig_cpuid; - *cpuid0 = cpuid; } static void diff --git a/sys/platform/pc32/acpica5/acpi_fadt.c b/sys/platform/pc32/acpica5/acpi_fadt.c index c160a908e9..d49013e333 100644 --- a/sys/platform/pc32/acpica5/acpi_fadt.c +++ b/sys/platform/pc32/acpica5/acpi_fadt.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "acpi_sdt.h" #include "acpi_sdt_var.h" @@ -181,6 +182,8 @@ acpi_sci_config(void) { const struct acpi_sci_mode *mode; + KKASSERT(mycpuid == 0); + if (acpi_sci_irq < 0) return; @@ -209,11 +212,11 @@ acpi_sci_config(void) sci_desc = register_int(acpi_sci_irq, acpi_sci_dummy_intr, NULL, "sci", NULL, INTR_EXCL | INTR_CLOCK | - INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY); + INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY, 0); DELAY(100 * 1000); - unregister_int(sci_desc); + unregister_int(sci_desc, 0); if (get_interrupt_counter(acpi_sci_irq) - last_cnt < 20) { acpi_sci_trig = mode->sci_trig; diff --git a/sys/platform/pc32/i386/nexus.c b/sys/platform/pc32/i386/nexus.c index c36a2797d0..a31fce5e75 100644 --- a/sys/platform/pc32/i386/nexus.c +++ b/sys/platform/pc32/i386/nexus.c @@ -521,7 +521,7 @@ nexus_setup_intr(device_t bus, device_t child, struct resource *irq, */ *cookiep = register_int(irq->r_start, (inthand2_t *)ihand, arg, device_get_nameunit(child), serializer, - icflags); + icflags, rman_get_cpuid(irq)); if (*cookiep == NULL) error = EINVAL; return (error); @@ -531,7 +531,7 @@ static int nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih) { if (ih) { - unregister_int(ih); + unregister_int(ih, rman_get_cpuid(r)); return (0); } return(-1); diff --git a/sys/platform/pc32/isa/clock.c b/sys/platform/pc32/isa/clock.c index 38362ee46c..633e335cb1 100644 --- a/sys/platform/pc32/isa/clock.c +++ b/sys/platform/pc32/isa/clock.c @@ -1041,6 +1041,7 @@ i8254_intr_initclock(struct cputimer_intr *cti, boolean_t selected) void *clkdesc = NULL; int irq = 0, mixed_mode = 0, error; + KKASSERT(mycpuid == 0); callout_init(&sysbeepstop_ch); if (!selected && i8254_intr_disable) @@ -1084,12 +1085,12 @@ mixed_mode_setup: NULL, INTR_EXCL | INTR_CLOCK | INTR_NOPOLL | INTR_MPSAFE | - INTR_NOENTROPY); + INTR_NOENTROPY, 0); } else { register_int(0, clkintr, NULL, "clk", NULL, INTR_EXCL | INTR_CLOCK | INTR_NOPOLL | INTR_MPSAFE | - INTR_NOENTROPY); + INTR_NOENTROPY, 0); } /* Initialize RTC. */ @@ -1112,7 +1113,7 @@ mixed_mode_setup: } else { kprintf("IOAPIC: warning 8254 is not connected " "to the correct pin, try mixed mode\n"); - unregister_int(clkdesc); + unregister_int(clkdesc, 0); goto mixed_mode_setup; } } diff --git a/sys/platform/pc64/acpica5/acpi_fadt.c b/sys/platform/pc64/acpica5/acpi_fadt.c index c160a908e9..d49013e333 100644 --- a/sys/platform/pc64/acpica5/acpi_fadt.c +++ b/sys/platform/pc64/acpica5/acpi_fadt.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "acpi_sdt.h" #include "acpi_sdt_var.h" @@ -181,6 +182,8 @@ acpi_sci_config(void) { const struct acpi_sci_mode *mode; + KKASSERT(mycpuid == 0); + if (acpi_sci_irq < 0) return; @@ -209,11 +212,11 @@ acpi_sci_config(void) sci_desc = register_int(acpi_sci_irq, acpi_sci_dummy_intr, NULL, "sci", NULL, INTR_EXCL | INTR_CLOCK | - INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY); + INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY, 0); DELAY(100 * 1000); - unregister_int(sci_desc); + unregister_int(sci_desc, 0); if (get_interrupt_counter(acpi_sci_irq) - last_cnt < 20) { acpi_sci_trig = mode->sci_trig; diff --git a/sys/platform/pc64/isa/clock.c b/sys/platform/pc64/isa/clock.c index 2ae238dd38..308377a49a 100644 --- a/sys/platform/pc64/isa/clock.c +++ b/sys/platform/pc64/isa/clock.c @@ -1048,6 +1048,7 @@ i8254_intr_initclock(struct cputimer_intr *cti, boolean_t selected) void *clkdesc = NULL; int irq = 0, mixed_mode = 0, error; + KKASSERT(mycpuid == 0); callout_init_mp(&sysbeepstop_ch); if (!selected && i8254_intr_disable) @@ -1091,12 +1092,12 @@ mixed_mode_setup: NULL, INTR_EXCL | INTR_CLOCK | INTR_NOPOLL | INTR_MPSAFE | - INTR_NOENTROPY); + INTR_NOENTROPY, 0); } else { register_int(0, clkintr, NULL, "clk", NULL, INTR_EXCL | INTR_CLOCK | INTR_NOPOLL | INTR_MPSAFE | - INTR_NOENTROPY); + INTR_NOENTROPY, 0); } /* Initialize RTC. */ @@ -1119,7 +1120,7 @@ mixed_mode_setup: } else { kprintf("IOAPIC: warning 8254 is not connected " "to the correct pin, try mixed mode\n"); - unregister_int(clkdesc); + unregister_int(clkdesc, 0); goto mixed_mode_setup; } } diff --git a/sys/platform/pc64/x86_64/nexus.c b/sys/platform/pc64/x86_64/nexus.c index ee39693d0e..b920de03a9 100644 --- a/sys/platform/pc64/x86_64/nexus.c +++ b/sys/platform/pc64/x86_64/nexus.c @@ -517,7 +517,7 @@ nexus_setup_intr(device_t bus, device_t child, struct resource *irq, */ *cookiep = register_int(irq->r_start, (inthand2_t *)ihand, arg, device_get_nameunit(child), serializer, - icflags); + icflags, rman_get_cpuid(irq)); if (*cookiep == NULL) error = EINVAL; return (error); @@ -527,7 +527,7 @@ static int nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih) { if (ih) { - unregister_int(ih); + unregister_int(ih, rman_get_cpuid(r)); return (0); } return(-1); diff --git a/sys/platform/vkernel/platform/console.c b/sys/platform/vkernel/platform/console.c index cfe3ebea94..f21c6c3aa7 100644 --- a/sys/platform/vkernel/platform/console.c +++ b/sys/platform/vkernel/platform/console.c @@ -346,7 +346,7 @@ vconsinit_fini(struct consdev *cp) * We have to do this here rather then in early boot to be able * to use the interrupt subsystem. */ - register_int(3, vconswinch_intr, NULL, "swinch", NULL, INTR_MPSAFE); + register_int(3, vconswinch_intr, NULL, "swinch", NULL, INTR_MPSAFE, 0); bzero(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); sa.sa_handler = vconswinchsig; diff --git a/sys/platform/vkernel/platform/cothread.c b/sys/platform/vkernel/platform/cothread.c index 6ba425ac57..9b304cd079 100644 --- a/sys/platform/vkernel/platform/cothread.c +++ b/sys/platform/vkernel/platform/cothread.c @@ -93,7 +93,7 @@ cothread_create(void (*thr_func)(cothread_t cotd), cotd->pintr = pthread_self(); cotd->intr_id = register_int(1, (void *)thr_intr, cotd, name, NULL, - INTR_MPSAFE); + INTR_MPSAFE, 0); /* * The vkernel's cpu_disable_intr() masks signals. We don't want @@ -117,7 +117,7 @@ cothread_delete(cothread_t *cotdp) cothread_t cotd; if ((cotd = *cotdp) != NULL) { - unregister_int(cotd->intr_id); + unregister_int(cotd->intr_id, 0); crit_enter(); pthread_join(cotd->pthr, NULL); crit_exit(); diff --git a/sys/platform/vkernel/platform/kqueue.c b/sys/platform/vkernel/platform/kqueue.c index f16be3fa83..27dee77936 100644 --- a/sys/platform/vkernel/platform/kqueue.c +++ b/sys/platform/vkernel/platform/kqueue.c @@ -113,9 +113,10 @@ kqueue_add(int fd, void (*func)(void *, struct intrframe *), void *data) struct kqueue_info *info; struct kevent kev; - if (VIntr1 == NULL) + if (VIntr1 == NULL) { VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, - INTR_MPSAFE); + INTR_MPSAFE, 0); + } info = kmalloc(sizeof(*info), M_DEVBUF, M_ZERO|M_INTWAIT); info->func = func; @@ -135,8 +136,10 @@ kqueue_add_timer(void (*func)(void *, struct intrframe *), void *data) { struct kqueue_info *info; - if (VIntr1 == NULL) - VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, 0); + if (VIntr1 == NULL) { + VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, + 0, 0); + } info = kmalloc(sizeof(*info), M_DEVBUF, M_ZERO|M_INTWAIT); info->func = func; diff --git a/sys/platform/vkernel/platform/shutdown.c b/sys/platform/vkernel/platform/shutdown.c index 1da160bdbe..b1f0c017d7 100644 --- a/sys/platform/vkernel/platform/shutdown.c +++ b/sys/platform/vkernel/platform/shutdown.c @@ -74,7 +74,7 @@ initshutdown(void *arg __unused) sa.sa_handler = shutdownsig; sigaction(SIGTERM, &sa, NULL); - register_int(2, shutdown_intr, NULL, "shutdown", NULL, INTR_MPSAFE); + register_int(2, shutdown_intr, NULL, "shutdown", NULL, INTR_MPSAFE, 0); } static diff --git a/sys/platform/vkernel64/platform/console.c b/sys/platform/vkernel64/platform/console.c index 98b12d047f..163ab74291 100644 --- a/sys/platform/vkernel64/platform/console.c +++ b/sys/platform/vkernel64/platform/console.c @@ -346,7 +346,7 @@ vconsinit_fini(struct consdev *cp) * We have to do this here rather then in early boot to be able * to use the interrupt subsystem. */ - register_int(3, vconswinch_intr, NULL, "swinch", NULL, INTR_MPSAFE); + register_int(3, vconswinch_intr, NULL, "swinch", NULL, INTR_MPSAFE, 0); bzero(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); sa.sa_handler = vconswinchsig; diff --git a/sys/platform/vkernel64/platform/cothread.c b/sys/platform/vkernel64/platform/cothread.c index dce5a2bd51..88875b7d67 100644 --- a/sys/platform/vkernel64/platform/cothread.c +++ b/sys/platform/vkernel64/platform/cothread.c @@ -93,7 +93,7 @@ cothread_create(void (*thr_func)(cothread_t cotd), cotd->pintr = pthread_self(); cotd->intr_id = register_int(1, (void *)thr_intr, cotd, name, NULL, - INTR_MPSAFE); + INTR_MPSAFE, 0); /* * The vkernel's cpu_disable_intr() masks signals. We don't want @@ -117,7 +117,7 @@ cothread_delete(cothread_t *cotdp) cothread_t cotd; if ((cotd = *cotdp) != NULL) { - unregister_int(cotd->intr_id); + unregister_int(cotd->intr_id, 0); crit_enter(); pthread_join(cotd->pthr, NULL); crit_exit(); diff --git a/sys/platform/vkernel64/platform/kqueue.c b/sys/platform/vkernel64/platform/kqueue.c index 1942403d14..f5f03ba9a4 100644 --- a/sys/platform/vkernel64/platform/kqueue.c +++ b/sys/platform/vkernel64/platform/kqueue.c @@ -113,9 +113,10 @@ kqueue_add(int fd, void (*func)(void *, struct intrframe *), void *data) struct kqueue_info *info; struct kevent kev; - if (VIntr1 == NULL) + if (VIntr1 == NULL) { VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, - INTR_MPSAFE); + INTR_MPSAFE, 0); + } info = kmalloc(sizeof(*info), M_DEVBUF, M_ZERO|M_INTWAIT); info->func = func; @@ -135,9 +136,10 @@ kqueue_add_timer(void (*func)(void *, struct intrframe *), void *data) { struct kqueue_info *info; - if (VIntr1 == NULL) + if (VIntr1 == NULL) { VIntr1 = register_int(1, kqueue_intr, NULL, "kqueue", NULL, - INTR_MPSAFE); + INTR_MPSAFE, 0); + } info = kmalloc(sizeof(*info), M_DEVBUF, M_ZERO|M_INTWAIT); info->func = func; diff --git a/sys/platform/vkernel64/platform/shutdown.c b/sys/platform/vkernel64/platform/shutdown.c index 9d49e9db44..a4a0588418 100644 --- a/sys/platform/vkernel64/platform/shutdown.c +++ b/sys/platform/vkernel64/platform/shutdown.c @@ -74,7 +74,7 @@ initshutdown(void *arg __unused) sa.sa_handler = shutdownsig; sigaction(SIGTERM, &sa, NULL); - register_int(2, shutdown_intr, NULL, "shutdown", NULL, INTR_MPSAFE); + register_int(2, shutdown_intr, NULL, "shutdown", NULL, INTR_MPSAFE, 0); } static diff --git a/sys/sys/interrupt.h b/sys/sys/interrupt.h index 095c861c93..9157649373 100644 --- a/sys/sys/interrupt.h +++ b/sys/sys/interrupt.h @@ -114,14 +114,15 @@ void *register_swi_mp(int intr, inthand2_t *handler, void *arg, struct lwkt_serialize *serializer); void *register_int(int intr, inthand2_t *handler, void *arg, const char *name, - struct lwkt_serialize *serializer, int flags); + struct lwkt_serialize *serializer, int flags, + int cpuid); long get_interrupt_counter(int intr); int count_registered_ints(int intr); const char *get_registered_name(int intr); void swi_setpriority(int intr, int pri); void unregister_swi(void *id); -void unregister_int(void *id); +void unregister_int(void *id, int cpuid); void register_randintr(int intr); void unregister_randintr(int intr); int next_registered_randintr(int intr);