intr: Pass cpuid to register_int and unregister_int
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 28 Oct 2011 15:33:11 +0000 (23:33 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 28 Oct 2011 15:33:11 +0000 (23:33 +0800)
16 files changed:
sys/kern/kern_intr.c
sys/platform/pc32/acpica5/acpi_fadt.c
sys/platform/pc32/i386/nexus.c
sys/platform/pc32/isa/clock.c
sys/platform/pc64/acpica5/acpi_fadt.c
sys/platform/pc64/isa/clock.c
sys/platform/pc64/x86_64/nexus.c
sys/platform/vkernel/platform/console.c
sys/platform/vkernel/platform/cothread.c
sys/platform/vkernel/platform/kqueue.c
sys/platform/vkernel/platform/shutdown.c
sys/platform/vkernel64/platform/console.c
sys/platform/vkernel64/platform/cothread.c
sys/platform/vkernel64/platform/kqueue.c
sys/platform/vkernel64/platform/shutdown.c
sys/sys/interrupt.h

index 101bc88..e0ad8fa 100644 (file)
@@ -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
index c160a90..d49013e 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/kernel.h>
 #include <sys/machintr.h>
 #include <sys/systm.h>
+#include <sys/thread2.h>
 
 #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;
index c36a279..a31fce5 100644 (file)
@@ -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);
index 38362ee..633e335 100644 (file)
@@ -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;
                        }
                }
index c160a90..d49013e 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/kernel.h>
 #include <sys/machintr.h>
 #include <sys/systm.h>
+#include <sys/thread2.h>
 
 #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;
index 2ae238d..308377a 100644 (file)
@@ -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;
                        }
                }
index ee39693..b920de0 100644 (file)
@@ -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);
index cfe3ebe..f21c6c3 100644 (file)
@@ -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;
index 6ba425a..9b304cd 100644 (file)
@@ -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();
index f16be3f..27dee77 100644 (file)
@@ -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;
index 1da160b..b1f0c01 100644 (file)
@@ -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
index 98b12d0..163ab74 100644 (file)
@@ -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;
index dce5a2b..88875b7 100644 (file)
@@ -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();
index 1942403..f5f03ba 100644 (file)
@@ -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;
index 9d49e9d..a4a0588 100644 (file)
@@ -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
index 095c861..9157649 100644 (file)
@@ -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);