Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Don't take the bus lock in usbd_transfer_complet...



details:   https://anonhg.NetBSD.org/src/rev/d892bea53aab
branches:  trunk
changeset: 785885:d892bea53aab
user:      skrll <skrll%NetBSD.org@localhost>
date:      Thu Apr 04 13:27:55 2013 +0000

description:
Don't take the bus lock in usbd_transfer_complete when polling.

Sprinkle || polling in KASSERTsw

diffstat:

 sys/dev/usb/ehci.c  |  14 +++++++-------
 sys/dev/usb/ohci.c  |  17 +++++++++--------
 sys/dev/usb/uhci.c  |   8 ++++----
 sys/dev/usb/usbdi.c |  19 ++++++++++---------
 4 files changed, 30 insertions(+), 28 deletions(-)

diffs (256 lines):

diff -r a588cfb3b5f4 -r d892bea53aab sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c        Thu Apr 04 13:23:50 2013 +0000
+++ b/sys/dev/usb/ehci.c        Thu Apr 04 13:27:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ehci.c,v 1.205 2013/02/01 12:53:47 tsutsui Exp $ */
+/*     $NetBSD: ehci.c,v 1.206 2013/04/04 13:27:55 skrll Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.205 2013/02/01 12:53:47 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.206 2013/04/04 13:27:55 skrll Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -776,7 +776,7 @@
 
        DPRINTFN(/*15*/2, ("ehci_check_intr: ex=%p\n", ex));
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        attr = ex->xfer.pipe->endpoint->edesc->bmAttributes;
        if (UE_GET_XFERTYPE(attr) == UE_ISOCHRONOUS)
@@ -793,7 +793,7 @@
        ehci_soft_qtd_t *sqtd, *lsqtd;
        __uint32_t status;
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        if (ex->sqtdstart == NULL) {
                printf("ehci_check_qh_intr: not valid sqtd\n");
@@ -911,7 +911,7 @@
        u_int32_t status = 0, nstatus = 0;
        int actlen;
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        DPRINTFN(/*12*/2, ("ehci_idone: ex=%p\n", ex));
 
@@ -2708,7 +2708,7 @@
 ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
 {
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        sqtd->nextqtd = sc->sc_freeqtds;
        sc->sc_freeqtds = sqtd;
@@ -3859,7 +3859,7 @@
        DPRINTFN(10, ("ehci_device_intr_done: xfer=%p, actlen=%d\n",
            xfer, xfer->actlen));
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        if (xfer->pipe->repeat) {
                ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
diff -r a588cfb3b5f4 -r d892bea53aab sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Thu Apr 04 13:23:50 2013 +0000
+++ b/sys/dev/usb/ohci.c        Thu Apr 04 13:27:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.239 2013/04/04 12:21:12 skrll Exp $ */
+/*     $NetBSD: ohci.c,v 1.240 2013/04/04 13:27:55 skrll Exp $ */
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.239 2013/04/04 12:21:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.240 2013/04/04 13:27:55 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -429,6 +429,8 @@
        int i, offs;
        usb_dma_t dma;
 
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
+
        if (sc->sc_freetds == NULL) {
                DPRINTFN(2, ("ohci_alloc_std: allocating chunk\n"));
                err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
@@ -459,7 +461,8 @@
 void
 ohci_free_std(ohci_softc_t *sc, ohci_soft_td_t *std)
 {
-
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
+       
        ohci_hash_rem_td(sc, std);
        std->nexttd = sc->sc_freetds;
        sc->sc_freetds = std;
@@ -1507,7 +1510,7 @@
        DPRINTFN(10,("ohci_device_intr_done: xfer=%p, actlen=%d\n",
                     xfer, xfer->actlen));
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        usb_syncmem(&xfer->dmabuf, 0, xfer->length,
            isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
@@ -1682,14 +1685,12 @@
                last = new;
        }
 #endif
-       mutex_enter(&sc->sc_lock);
        sc->sc_eintrs |= OHCI_WDH;
        if (OREAD4(sc, OHCI_INTERRUPT_STATUS) & sc->sc_eintrs) {
                mutex_spin_enter(&sc->sc_intr_lock);
                ohci_intr1(sc);
                mutex_spin_exit(&sc->sc_intr_lock);
        }
-       mutex_exit(&sc->sc_lock);
 }
 
 usbd_status
@@ -1913,7 +1914,7 @@
 {
        int h = HASH(std->physaddr);
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        LIST_INSERT_HEAD(&sc->sc_hash_tds[h], std, hnext);
 }
@@ -1923,7 +1924,7 @@
 ohci_hash_rem_td(ohci_softc_t *sc, ohci_soft_td_t *std)
 {
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        LIST_REMOVE(std, hnext);
 }
diff -r a588cfb3b5f4 -r d892bea53aab sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c        Thu Apr 04 13:23:50 2013 +0000
+++ b/sys/dev/usb/uhci.c        Thu Apr 04 13:27:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci.c,v 1.256 2013/02/01 12:53:47 tsutsui Exp $       */
+/*     $NetBSD: uhci.c,v 1.257 2013/04/04 13:27:56 skrll Exp $ */
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.256 2013/02/01 12:53:47 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.257 2013/04/04 13:27:56 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1912,7 +1912,7 @@
                      "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len,
                      upipe->pipe.device->speed, flags));
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize);
        if (maxp == 0) {
@@ -3005,7 +3005,7 @@
 
        DPRINTFN(5, ("uhci_device_intr_done: length=%d\n", xfer->actlen));
 
-       KASSERT(mutex_owned(&sc->sc_lock));
+       KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
        npoll = upipe->u.intr.npoll;
        for(i = 0; i < npoll; i++) {
diff -r a588cfb3b5f4 -r d892bea53aab sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c       Thu Apr 04 13:23:50 2013 +0000
+++ b/sys/dev/usb/usbdi.c       Thu Apr 04 13:27:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.c,v 1.151 2013/03/24 22:38:45 skrll Exp $        */
+/*     $NetBSD: usbdi.c,v 1.152 2013/04/04 13:27:56 skrll Exp $        */
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.151 2013/03/24 22:38:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.152 2013/04/04 13:27:56 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -790,12 +790,14 @@
        int sync = xfer->flags & USBD_SYNCHRONOUS;
        int erred = xfer->status == USBD_CANCELLED ||
            xfer->status == USBD_TIMEOUT;
-       int repeat, polling;
+       int polling = pipe->device->bus->use_polling;
+       int repeat;
 
        DPRINTFN(5, ("usb_transfer_complete: pipe=%p xfer=%p status=%d "
                     "actlen=%d\n", pipe, xfer, xfer->status, xfer->actlen));
 
-       KASSERT(pipe->device->bus->lock == NULL || mutex_owned(pipe->device->bus->lock));
+       KASSERT(polling || pipe->device->bus->lock == NULL ||
+           mutex_owned(pipe->device->bus->lock));
 
 #ifdef DIAGNOSTIC
        if (xfer->busy_free != XFER_ONQU) {
@@ -811,7 +813,6 @@
        }
 #endif
        repeat = pipe->repeat;
-       polling = pipe->device->bus->use_polling;
        /* XXXX */
        if (polling)
                pipe->running = 0;
@@ -868,7 +869,7 @@
 
        if (repeat) {
                if (xfer->callback) {
-                       if (pipe->device->bus->lock)
+                       if (pipe->device->bus->lock && !polling)
                                mutex_exit(pipe->device->bus->lock);
 
                        if (!(pipe->flags & USBD_MPSAFE))
@@ -877,14 +878,14 @@
                        if (!(pipe->flags & USBD_MPSAFE))
                                KERNEL_UNLOCK_ONE(curlwp);
 
-                       if (pipe->device->bus->lock)
+                       if (pipe->device->bus->lock && !polling)
                                mutex_enter(pipe->device->bus->lock);
                }
                pipe->methods->done(xfer);
        } else {
                pipe->methods->done(xfer);
                if (xfer->callback) {
-                       if (pipe->device->bus->lock)
+                       if (pipe->device->bus->lock && !polling)
                                mutex_exit(pipe->device->bus->lock);
 
                        if (!(pipe->flags & USBD_MPSAFE))
@@ -893,7 +894,7 @@
                        if (!(pipe->flags & USBD_MPSAFE))
                                KERNEL_UNLOCK_ONE(curlwp);
 
-                       if (pipe->device->bus->lock)
+                       if (pipe->device->bus->lock && !polling)
                                mutex_enter(pipe->device->bus->lock);
                }
        }



Home | Main Index | Thread Index | Old Index