Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha Changes to make interrupt {,dis}establish MP-...



details:   https://anonhg.NetBSD.org/src/rev/afdec7e6bce2
branches:  trunk
changeset: 939078:afdec7e6bce2
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Sep 25 03:40:11 2020 +0000

description:
Changes to make interrupt {,dis}establish MP-safe on Alpha:
- Protect all of the system interrupt linkage with the cpu_lock mutex.
- Re-order some of the stores to the SCB vector table to make it safe
  in the face of lockless interrupt dispatch.
- Add a framework for routing interrupts to specific CPUs.  Interrupts
  are still funneled only to the primary CPU, but that will change for
  some systems soon.  Ensure that interrupt handler lists are manipulated
  only on the CPUs that handle that specific interrupt source.  This required
  a re-factor of the alpha_shared_intr_*() family of functions.
- Enable __HAVE_INTR_CONTROL, although interrupt redistribution is still
  a no-op.
- Reduce code duplication in the Jenson direct-SCB interrupt handlers.

diffstat:

 sys/arch/alpha/alpha/interrupt.c         |   55 +++++---
 sys/arch/alpha/common/shared_intr.c      |  194 ++++++++++++++++++++++++------
 sys/arch/alpha/include/cpu.h             |    3 +-
 sys/arch/alpha/include/intr.h            |   22 ++-
 sys/arch/alpha/include/types.h           |    3 +-
 sys/arch/alpha/jensenio/com_jensenio.c   |   29 +---
 sys/arch/alpha/jensenio/jensenio_intr.c  |   95 ++++++++++++--
 sys/arch/alpha/jensenio/jenseniovar.h    |   19 ++-
 sys/arch/alpha/jensenio/pckbc_jensenio.c |   42 +-----
 sys/arch/alpha/pci/dwlpx.c               |    7 +-
 sys/arch/alpha/pci/pci_2100_a500.c       |   77 ++++++++---
 sys/arch/alpha/pci/pci_kn300.c           |   30 +++-
 sys/arch/alpha/pci/pci_kn8ae.c           |   37 +++--
 sys/arch/alpha/pci/pci_machdep.c         |   40 ++++-
 sys/arch/alpha/pci/sio_pic.c             |   41 ++++--
 sys/arch/alpha/tc/tc_3000_300.c          |   20 ++-
 sys/arch/alpha/tc/tc_3000_500.c          |   20 ++-
 sys/arch/alpha/tc/tcasic.c               |    7 +-
 18 files changed, 523 insertions(+), 218 deletions(-)

diffs (truncated from 1599 to 300 lines):

diff -r c39537eb4ece -r afdec7e6bce2 sys/arch/alpha/alpha/interrupt.c
--- a/sys/arch/alpha/alpha/interrupt.c  Thu Sep 24 17:20:53 2020 +0000
+++ b/sys/arch/alpha/alpha/interrupt.c  Fri Sep 25 03:40:11 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: interrupt.c,v 1.89 2020/09/22 15:24:01 thorpej Exp $ */
+/* $NetBSD: interrupt.c,v 1.90 2020/09/25 03:40:11 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.89 2020/09/22 15:24:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.90 2020/09/25 03:40:11 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -88,11 +88,10 @@
 #include <machine/cpuconf.h>
 #include <machine/alpha.h>
 
+/* Protected by cpu_lock */
 struct scbvec scb_iovectab[SCB_VECTOIDX(SCB_SIZE - SCB_IOVECBASE)]
                                                        __read_mostly;
 
-void   netintr(void);
-
 void   scb_stray(void *, u_long);
 
 void
@@ -117,9 +116,8 @@
 scb_set(u_long vec, void (*func)(void *, u_long), void *arg)
 {
        u_long idx;
-       int s;
 
-       s = splhigh();
+       KASSERT(mutex_owned(&cpu_lock));
 
        if (vec < SCB_IOVECBASE || vec >= SCB_SIZE ||
            (vec & (SCB_VECSIZE - 1)) != 0)
@@ -130,19 +128,18 @@
        if (scb_iovectab[idx].scb_func != scb_stray)
                panic("scb_set: vector 0x%lx already occupied", vec);
 
+       scb_iovectab[idx].scb_arg = arg;
+       alpha_mb();
        scb_iovectab[idx].scb_func = func;
-       scb_iovectab[idx].scb_arg = arg;
-
-       splx(s);
+       alpha_mb();
 }
 
 u_long
 scb_alloc(void (*func)(void *, u_long), void *arg)
 {
        u_long vec, idx;
-       int s;
 
-       s = splhigh();
+       KASSERT(mutex_owned(&cpu_lock));
 
        /*
         * Allocate "downwards", to avoid bumping into
@@ -153,15 +150,14 @@
             vec >= SCB_IOVECBASE; vec -= SCB_VECSIZE) {
                idx = SCB_VECTOIDX(vec - SCB_IOVECBASE);
                if (scb_iovectab[idx].scb_func == scb_stray) {
+                       scb_iovectab[idx].scb_arg = arg;
+                       alpha_mb();
                        scb_iovectab[idx].scb_func = func;
-                       scb_iovectab[idx].scb_arg = arg;
-                       splx(s);
+                       alpha_mb();
                        return (vec);
                }
        }
 
-       splx(s);
-
        return (SCB_ALLOC_FAILED);
 }
 
@@ -169,9 +165,8 @@
 scb_free(u_long vec)
 {
        u_long idx;
-       int s;
 
-       s = splhigh();
+       KASSERT(mutex_owned(&cpu_lock));
 
        if (vec < SCB_IOVECBASE || vec >= SCB_SIZE ||
            (vec & (SCB_VECSIZE - 1)) != 0)
@@ -183,9 +178,9 @@
                panic("scb_free: vector 0x%lx is empty", vec);
 
        scb_iovectab[idx].scb_func = scb_stray;
+       alpha_mb();
        scb_iovectab[idx].scb_arg = (void *) vec;
-
-       splx(s);
+       alpha_mb();
 }
 
 void
@@ -581,6 +576,28 @@
 }
 
 /*
+ * cpu_intr_redistribute:
+ *
+ *     Redistribute interrupts amongst CPUs eligible to handle them.
+ */
+void
+cpu_intr_redistribute(void)
+{
+       /* XXX Nothing, yet. */
+}
+
+/*
+ * cpu_intr_count:
+ *
+ *     Return the number of device interrupts this CPU handles.
+ */
+unsigned int
+cpu_intr_count(struct cpu_info * const ci)
+{
+       return ci->ci_nintrhand;
+}
+
+/*
  * Security sensitive rate limiting printf
  */
 void
diff -r c39537eb4ece -r afdec7e6bce2 sys/arch/alpha/common/shared_intr.c
--- a/sys/arch/alpha/common/shared_intr.c       Thu Sep 24 17:20:53 2020 +0000
+++ b/sys/arch/alpha/common/shared_intr.c       Fri Sep 25 03:40:11 2020 +0000
@@ -1,4 +1,33 @@
-/* $NetBSD: shared_intr.c,v 1.24 2020/09/23 18:46:02 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.25 2020/09/25 03:40:11 thorpej Exp $ */
+
+/*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -33,16 +62,19 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.24 2020/09/23 18:46:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.25 2020/09/25 03:40:11 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
+#include <sys/cpu.h>
+#include <sys/kmem.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
-#include <sys/malloc.h>
 #include <sys/syslog.h>
 #include <sys/queue.h>
 #include <sys/atomic.h>
 #include <sys/intr.h>
+#include <sys/xcall.h>
 
 static const char *intr_typename(int);
 
@@ -71,8 +103,7 @@
        struct alpha_shared_intr *intr;
        unsigned int i;
 
-       intr = malloc(n * sizeof (struct alpha_shared_intr), M_DEVBUF,
-           M_WAITOK);
+       intr = kmem_alloc(n * sizeof(*intr), KM_SLEEP);
        for (i = 0; i < n; i++) {
                TAILQ_INIT(&intr[i].intr_q);
                intr[i].intr_sharetype = IST_NONE;
@@ -80,11 +111,12 @@
                intr[i].intr_nstrays = 0;
                intr[i].intr_maxstrays = 5;
                intr[i].intr_private = NULL;
+               intr[i].intr_cpu = NULL;
                if (namesize != 0) {
-                       intr[i].intr_string = malloc(namesize, M_DEVBUF,
-                           M_WAITOK);
-               } else
+                       intr[i].intr_string = kmem_zalloc(namesize, KM_SLEEP);
+               } else {
                        intr[i].intr_string = NULL;
+               }
        }
 
        return (intr);
@@ -132,24 +164,82 @@
        return rv;
 }
 
-void *
-alpha_shared_intr_establish(struct alpha_shared_intr *intr, unsigned int num,
-    int type, int level, int flags,
+struct alpha_shared_intrhand *
+alpha_shared_intr_alloc_intrhand(struct alpha_shared_intr *intr,
+    unsigned int num, int type, int level, int flags,
     int (*fn)(void *), void *arg, const char *basename)
 {
        struct alpha_shared_intrhand *ih;
 
        if (intr[num].intr_sharetype == IST_UNUSABLE) {
-               printf("alpha_shared_intr_establish: %s %d: unusable\n",
+               printf("%s: %s %d: unusable\n", __func__,
                    basename, num);
                return NULL;
        }
 
-       ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
-#ifdef DIAGNOSTIC
-       if (type == IST_NONE)
-               panic("alpha_shared_intr_establish: bogus type");
-#endif
+       KASSERT(type != IST_NONE);
+
+       ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
+
+       ih->ih_intrhead = intr;
+       ih->ih_fn = ih->ih_real_fn = fn;
+       ih->ih_arg = ih->ih_real_arg = arg;
+       ih->ih_level = level;
+       ih->ih_type = type;
+       ih->ih_num = num;
+
+       /*
+        * Non-MPSAFE interrupts get a wrapper that takes the
+        * KERNEL_LOCK.
+        */
+       if ((flags & ALPHA_INTR_MPSAFE) == 0) {
+               ih->ih_fn = alpha_shared_intr_wrapper;
+               ih->ih_arg = ih;
+       }
+
+       return (ih);
+}
+
+void
+alpha_shared_intr_free_intrhand(struct alpha_shared_intrhand *ih)
+{
+
+       kmem_free(ih, sizeof(*ih));
+}
+
+static void
+alpha_shared_intr_link_unlink_xcall(void *arg1, void *arg2)
+{
+       struct alpha_shared_intrhand *ih = arg1;
+       struct alpha_shared_intr *intr = ih->ih_intrhead;
+       struct cpu_info *ci = intr->intr_cpu;
+       unsigned int num = ih->ih_num;
+
+       KASSERT(ci == curcpu() || !mp_online);
+       KASSERT(!cpu_intr_p());
+
+       const unsigned long psl = alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
+
+       if (arg2 != NULL) {
+               TAILQ_INSERT_TAIL(&intr[num].intr_q, ih, ih_q);
+               ci->ci_nintrhand++;
+       } else {
+               TAILQ_REMOVE(&intr[num].intr_q, ih, ih_q);
+               ci->ci_nintrhand--;
+       }
+



Home | Main Index | Thread Index | Old Index