Source-Changes-HG archive

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

[src/jmcneill-usbmp]: src/sys/dev - make pipe->close method take the thread lock



details:   https://anonhg.NetBSD.org/src/rev/7b6a18e5f6b8
branches:  jmcneill-usbmp
changeset: 771788:7b6a18e5f6b8
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Dec 09 01:52:59 2011 +0000

description:
- make pipe->close method take the thread lock

- convert usb_taskq to use mutex/cv

- convert needs_explore usage into a cv on the thread lock

- remove KERNEL_*LOCK from uaudio and umidi, since we're supposedly
  MPSAFE here now

- use IPL_SCHED instead of IPL_USB (aka biglocked) interrupts

- drop the audio thread lock when calling into usb when it may sleep,
  avoiding a deadlock between audiowrite and audioioctl.  this fixes
  mixerctl -a vs. playing hanging the system
  XXX probably need to check this in a bunch more places.

diffstat:

 sys/dev/pci/ehci_pci.c |   6 +-
 sys/dev/pci/ohci_pci.c |   6 +-
 sys/dev/pci/uhci_pci.c |   6 +-
 sys/dev/usb/ehci.c     |  20 ++++++-----
 sys/dev/usb/ohci.c     |  24 +++++++------
 sys/dev/usb/uaudio.c   |  32 ++++-------------
 sys/dev/usb/uhci.c     |  18 ++++++---
 sys/dev/usb/umidi.c    |  10 +----
 sys/dev/usb/usb.c      |  88 ++++++++++++++++++++++++++++++++++++++-----------
 sys/dev/usb/usb_subr.c |   9 +++-
 sys/dev/usb/usbdi.c    |  15 ++++++--
 sys/dev/usb/usbdivar.h |  23 ++++++++----
 12 files changed, 154 insertions(+), 103 deletions(-)

diffs (truncated from 957 to 300 lines):

diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/pci/ehci_pci.c
--- a/sys/dev/pci/ehci_pci.c    Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/pci/ehci_pci.c    Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ehci_pci.c,v 1.53.6.1 2011/12/04 13:23:16 jmcneill Exp $       */
+/*     $NetBSD: ehci_pci.c,v 1.53.6.2 2011/12/09 01:52:59 mrg Exp $    */
 
 /*
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.53.6.1 2011/12/04 13:23:16 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.53.6.2 2011/12/09 01:52:59 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -182,7 +182,7 @@
         * Allocate IRQ
         */
        intrstr = pci_intr_string(pc, ih);
-       sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ehci_intr, sc);
+       sc->sc_ih = pci_intr_establish(pc, ih, IPL_SCHED, ehci_intr, sc);
        if (sc->sc_ih == NULL) {
                aprint_error_dev(self, "couldn't establish interrupt");
                if (intrstr != NULL)
diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/pci/ohci_pci.c
--- a/sys/dev/pci/ohci_pci.c    Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/pci/ohci_pci.c    Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci_pci.c,v 1.47 2011/04/04 22:48:15 dyoung Exp $     */
+/*     $NetBSD: ohci_pci.c,v 1.47.8.1 2011/12/09 01:52:59 mrg Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.47 2011/04/04 22:48:15 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.47.8.1 2011/12/09 01:52:59 mrg Exp $");
 
 #include "ehci.h"
 
@@ -131,7 +131,7 @@
         * Allocate IRQ
         */
        intrstr = pci_intr_string(pc, ih);
-       sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ohci_intr, sc);
+       sc->sc_ih = pci_intr_establish(pc, ih, IPL_SCHED, ohci_intr, sc);
        if (sc->sc_ih == NULL) {
                aprint_error_dev(self, "couldn't establish interrupt");
                if (intrstr != NULL)
diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/pci/uhci_pci.c
--- a/sys/dev/pci/uhci_pci.c    Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/pci/uhci_pci.c    Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci_pci.c,v 1.53 2011/04/04 22:48:15 dyoung Exp $     */
+/*     $NetBSD: uhci_pci.c,v 1.53.8.1 2011/12/09 01:52:59 mrg Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.53 2011/04/04 22:48:15 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.53.8.1 2011/12/09 01:52:59 mrg Exp $");
 
 #include "ehci.h"
 
@@ -134,7 +134,7 @@
                return;
        }
        intrstr = pci_intr_string(pc, ih);
-       sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, uhci_intr, sc);
+       sc->sc_ih = pci_intr_establish(pc, ih, IPL_SCHED, uhci_intr, sc);
        if (sc->sc_ih == NULL) {
                aprint_error_dev(self, "couldn't establish interrupt");
                if (intrstr != NULL)
diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c        Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/usb/ehci.c        Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ehci.c,v 1.181.6.4 2011/12/08 02:51:07 mrg Exp $ */
+/*     $NetBSD: ehci.c,v 1.181.6.5 2011/12/09 01:52:59 mrg Exp $ */
 
 /*
  * Copyright (c) 2004-2011 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.181.6.4 2011/12/08 02:51:07 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.181.6.5 2011/12/09 01:52:59 mrg Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -352,7 +352,7 @@
 #endif
 
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
-       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB);
+       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
        cv_init(&sc->sc_softwake_cv, "ehciab");
        cv_init(&sc->sc_doorbell, "ehcidi");
 
@@ -2616,11 +2616,11 @@
 {
        ehci_softc_t *sc = pipe->device->bus->hci_private;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ehci_root_intr_close\n"));
 
-       mutex_enter(&sc->sc_lock);
        sc->sc_intrxfer = NULL;
-       mutex_exit(&sc->sc_lock);
 }
 
 Static void
@@ -3346,11 +3346,11 @@
        ehci_softc_t *sc = pipe->device->bus->hci_private;
        /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ehci_device_ctrl_close: pipe=%p\n", pipe));
 
-       mutex_enter(&sc->sc_lock);
        ehci_close_pipe(pipe, sc->sc_async_head);
-       mutex_exit(&sc->sc_lock);
 }
 
 Static usbd_status
@@ -3663,11 +3663,11 @@
        ehci_softc_t *sc = pipe->device->bus->hci_private;
        struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ehci_device_bulk_close: pipe=%p\n", pipe));
-       mutex_enter(&sc->sc_lock);
        pipe->endpoint->datatoggle = epipe->nexttoggle;
        ehci_close_pipe(pipe, sc->sc_async_head);
-       mutex_exit(&sc->sc_lock);
 }
 
 Static void
@@ -3848,6 +3848,8 @@
        struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
        struct ehci_soft_islot *isp;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        isp = &sc->sc_islots[epipe->sqh->islot];
        ehci_close_pipe(pipe, isp->sqh);
 }
diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/usb/ohci.c        Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.218.6.7 2011/12/08 22:38:47 mrg Exp $       */
+/*     $NetBSD: ohci.c,v 1.218.6.8 2011/12/09 01:53:00 mrg Exp $       */
 /*     $FreeBSD: src/sys/dev/usb/ohci.c,v 1.22 1999/11/17 22:33:40 n_hibma Exp $       */
 
 /*
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.218.6.7 2011/12/08 22:38:47 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.218.6.8 2011/12/09 01:53:00 mrg Exp $");
 
 #include "opt_usb.h"
 
@@ -665,7 +665,7 @@
        callout_init(&sc->sc_tmo_rhsc, CALLOUT_MPSAFE);
 
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
-       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB);
+       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
        cv_init(&sc->sc_softwake_cv, "ohciab");
 
        sc->sc_rhsc_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
@@ -2895,6 +2895,8 @@
 {
        ohci_softc_t *sc = pipe->device->bus->hci_private;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ohci_root_intr_close\n"));
 
        sc->sc_intrxfer = NULL;
@@ -2962,11 +2964,11 @@
        struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
        ohci_softc_t *sc = pipe->device->bus->hci_private;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ohci_device_ctrl_close: pipe=%p\n", pipe));
-       mutex_enter(&sc->sc_lock);
        ohci_close_pipe(pipe, sc->sc_ctrl_head);
        ohci_free_std(sc, opipe->tail.td);
-       mutex_exit(&sc->sc_lock);
 }
 
 /************************/
@@ -3126,11 +3128,11 @@
        struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
        ohci_softc_t *sc = pipe->device->bus->hci_private;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ohci_device_bulk_close: pipe=%p\n", pipe));
-       mutex_enter(&sc->sc_lock);
        ohci_close_pipe(pipe, sc->sc_bulk_head);
        ohci_free_std(sc, opipe->tail.td);
-       mutex_exit(&sc->sc_lock);
 }
 
 /************************/
@@ -3262,9 +3264,10 @@
        int j;
        ohci_soft_ed_t *p, *sed = opipe->sed;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTFN(1,("ohci_device_intr_close: pipe=%p nslots=%d pos=%d\n",
                    pipe, nslots, pos));
-       mutex_enter(&sc->sc_lock);
        usb_syncmem(&sed->dma, sed->offs,
            sizeof(sed->ed), BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
        sed->ed.ed_flags |= HTOO32(OHCI_ED_SKIP);
@@ -3286,7 +3289,6 @@
        usb_syncmem(&p->dma, p->offs + offsetof(ohci_ed_t, ed_nexted),
            sizeof(p->ed.ed_nexted),
            BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
-       mutex_exit(&sc->sc_lock);
 
        for (j = 0; j < nslots; j++)
                --sc->sc_bws[(pos * nslots + j) % OHCI_NO_INTRS];
@@ -3648,12 +3650,12 @@
        struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
        ohci_softc_t *sc = pipe->device->bus->hci_private;
 
+       KASSERT(mutex_owned(&sc->sc_lock));
+
        DPRINTF(("ohci_device_isoc_close: pipe=%p\n", pipe));
-       mutex_enter(&sc->sc_lock);
        ohci_close_pipe(pipe, sc->sc_isoc_head);
 #ifdef DIAGNOSTIC
        opipe->tail.itd->isdone = 1;
 #endif
        ohci_free_sitd(sc, opipe->tail.itd);
-       mutex_exit(&sc->sc_lock);
 }
diff -r 395398be204b -r 7b6a18e5f6b8 sys/dev/usb/uaudio.c
--- a/sys/dev/usb/uaudio.c      Thu Dec 08 22:38:47 2011 +0000
+++ b/sys/dev/usb/uaudio.c      Fri Dec 09 01:52:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uaudio.c,v 1.124 2011/11/27 07:36:54 mrg Exp $ */
+/*     $NetBSD: uaudio.c,v 1.124.2.1 2011/12/09 01:53:00 mrg Exp $     */
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.124 2011/11/27 07:36:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.124.2.1 2011/12/09 01:53:00 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -421,7 +421,7 @@
        sc->sc_dev = self;
        sc->sc_udev = uaa->device;
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
-       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB);
+       mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
 
        strlcpy(sc->sc_adev.name, "USB audio", sizeof(sc->sc_adev.name));
        strlcpy(sc->sc_adev.version, "", sizeof(sc->sc_adev.version));
@@ -2097,7 +2097,7 @@
        struct mixerctl *mc;
        int n, nctls, i;
 
-       DPRINTFN(2, "index=%d\n", mi->index);
+       DPRINTFN(7, "index=%d\n", mi->index);
        sc = addr;
        if (sc->sc_dying)
                return EIO;
@@ -2220,7 +2220,6 @@
 
        DPRINTF("%s", "enter\n");
 
-       KERNEL_LOCK(1, curlwp);
        mutex_spin_exit(&sc->sc_intr_lock);



Home | Main Index | Thread Index | Old Index