Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Use two different mutexes for tx and rx



details:   https://anonhg.NetBSD.org/src/rev/f0598c4d3ab4
branches:  trunk
changeset: 331038:f0598c4d3ab4
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Jul 28 06:36:09 2014 +0000

description:
Use two different mutexes for tx and rx

This change splits the mutex of wm into two: one for tx and the other
for rx. By doing so, lock contentions can be reduced. We lock both for
other operations that need locking, e.g., init, stop and ioctl.

The modification doesn't change the behavior of the driver.

diffstat:

 sys/dev/pci/if_wm.c |  117 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 65 insertions(+), 52 deletions(-)

diffs (truncated from 393 to 300 lines):

diff -r 04951fb14272 -r f0598c4d3ab4 sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Mon Jul 28 00:02:50 2014 +0000
+++ b/sys/dev/pci/if_wm.c       Mon Jul 28 06:36:09 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.282 2014/07/25 18:28:03 msaitoh Exp $      */
+/*     $NetBSD: if_wm.c,v 1.283 2014/07/28 06:36:09 ozaki-r Exp $      */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.282 2014/07/25 18:28:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.283 2014/07/28 06:36:09 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -382,13 +382,19 @@
 
        krndsource_t rnd_source;        /* random source */
 
-       kmutex_t *sc_txrx_lock;         /* lock for tx/rx operations */
-                                       /* XXX need separation? */
+       kmutex_t *sc_tx_lock;           /* lock for tx operations */
+       kmutex_t *sc_rx_lock;           /* lock for rx operations */
 };
 
-#define WM_LOCK(_sc)   if ((_sc)->sc_txrx_lock) mutex_enter((_sc)->sc_txrx_lock)
-#define WM_UNLOCK(_sc) if ((_sc)->sc_txrx_lock) mutex_exit((_sc)->sc_txrx_lock)
-#define WM_LOCKED(_sc) (!(_sc)->sc_txrx_lock || mutex_owned((_sc)->sc_txrx_lock))
+#define WM_TX_LOCK(_sc)                if ((_sc)->sc_tx_lock) mutex_enter((_sc)->sc_tx_lock)
+#define WM_TX_UNLOCK(_sc)      if ((_sc)->sc_tx_lock) mutex_exit((_sc)->sc_tx_lock)
+#define WM_TX_LOCKED(_sc)      (!(_sc)->sc_tx_lock || mutex_owned((_sc)->sc_tx_lock))
+#define WM_RX_LOCK(_sc)                if ((_sc)->sc_rx_lock) mutex_enter((_sc)->sc_rx_lock)
+#define WM_RX_UNLOCK(_sc)      if ((_sc)->sc_rx_lock) mutex_exit((_sc)->sc_rx_lock)
+#define WM_RX_LOCKED(_sc)      (!(_sc)->sc_rx_lock || mutex_owned((_sc)->sc_rx_lock))
+#define WM_BOTH_LOCK(_sc)      do {WM_TX_LOCK(_sc); WM_RX_LOCK(_sc);} while (0)
+#define WM_BOTH_UNLOCK(_sc)    do {WM_RX_UNLOCK(_sc); WM_TX_UNLOCK(_sc);} while (0)
+#define WM_BOTH_LOCKED(_sc)    (WM_TX_LOCKED(_sc) && WM_RX_LOCKED(_sc))
 
 #ifdef WM_MPSAFE
 #define CALLOUT_FLAGS  CALLOUT_MPSAFE
@@ -2159,9 +2165,11 @@
        }
 
 #ifdef WM_MPSAFE
-       sc->sc_txrx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
+       sc->sc_tx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
+       sc->sc_rx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
 #else
-       sc->sc_txrx_lock = NULL;
+       sc->sc_tx_lock = NULL;
+       sc->sc_rx_lock = NULL;
 #endif
 
        /* Attach the interface. */
@@ -2287,10 +2295,10 @@
        pmf_device_deregister(self);
 
        /* Tell the firmware about the release */
-       WM_LOCK(sc);
+       WM_BOTH_LOCK(sc);
        wm_release_manageability(sc);
        wm_release_hw_control(sc);
-       WM_UNLOCK(sc);
+       WM_BOTH_UNLOCK(sc);
 
        mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
 
@@ -2302,9 +2310,9 @@
 
 
        /* Unload RX dmamaps and free mbufs */
-       WM_LOCK(sc);
+       WM_RX_LOCK(sc);
        wm_rxdrain(sc);
-       WM_UNLOCK(sc);
+       WM_RX_UNLOCK(sc);
        /* Must unlock here */
 
        /* Free dmamap. It's the same as the end of the wm_attach() function */
@@ -2341,8 +2349,10 @@
                sc->sc_ios = 0;
        }
 
-       if (sc->sc_txrx_lock)
-               mutex_obj_free(sc->sc_txrx_lock);
+       if (sc->sc_tx_lock)
+               mutex_obj_free(sc->sc_tx_lock);
+       if (sc->sc_rx_lock)
+               mutex_obj_free(sc->sc_rx_lock);
 
        return 0;
 }
@@ -2385,9 +2395,9 @@
         * Since we're using delayed interrupts, sweep up
         * before we report an error.
         */
-       WM_LOCK(sc);
+       WM_TX_LOCK(sc);
        wm_txintr(sc);
-       WM_UNLOCK(sc);
+       WM_TX_UNLOCK(sc);
 
        if (sc->sc_txfree != WM_NTXDESC(sc)) {
 #ifdef WM_DEBUG
@@ -2442,7 +2452,7 @@
        s = splnet();
 #endif
 
-       WM_LOCK(sc);
+       WM_TX_LOCK(sc);
 
        if (sc->sc_stopping)
                goto out;
@@ -2472,7 +2482,7 @@
                wm_tbi_check_link(sc);
 
 out:
-       WM_UNLOCK(sc);
+       WM_TX_UNLOCK(sc);
 #ifndef WM_MPSAFE
        splx(s);
 #endif
@@ -2489,7 +2499,7 @@
        int change = ifp->if_flags ^ sc->sc_if_flags;
        int rc = 0;
 
-       WM_LOCK(sc);
+       WM_BOTH_LOCK(sc);
 
        if (change != 0)
                sc->sc_if_flags = ifp->if_flags;
@@ -2505,7 +2515,7 @@
        wm_set_vlan(sc);
 
 out:
-       WM_UNLOCK(sc);
+       WM_BOTH_UNLOCK(sc);
 
        return rc;
 }
@@ -2527,7 +2537,7 @@
 #ifndef WM_MPSAFE
        s = splnet();
 #endif
-       WM_LOCK(sc);
+       WM_BOTH_LOCK(sc);
 
        switch (cmd) {
        case SIOCSIFMEDIA:
@@ -2558,7 +2568,7 @@
                }
                /*FALLTHROUGH*/
        default:
-               WM_UNLOCK(sc);
+               WM_BOTH_UNLOCK(sc);
 #ifdef WM_MPSAFE
                s = splnet();
 #endif
@@ -2567,7 +2577,7 @@
 #ifdef WM_MPSAFE
                splx(s);
 #endif
-               WM_LOCK(sc);
+               WM_BOTH_LOCK(sc);
 
                if (error != ENETRESET)
                        break;
@@ -2575,9 +2585,9 @@
                error = 0;
 
                if (cmd == SIOCSIFCAP) {
-                       WM_UNLOCK(sc);
+                       WM_BOTH_UNLOCK(sc);
                        error = (*ifp->if_init)(ifp);
-                       WM_LOCK(sc);
+                       WM_BOTH_LOCK(sc);
                } else if (cmd != SIOCADDMULTI && cmd != SIOCDELMULTI)
                        ;
                else if (ifp->if_flags & IFF_RUNNING) {
@@ -2590,7 +2600,7 @@
                break;
        }
 
-       WM_UNLOCK(sc);
+       WM_BOTH_UNLOCK(sc);
 
        /* Try to get more packets going. */
        ifp->if_start(ifp);
@@ -3474,7 +3484,7 @@
        struct mbuf *m;
        int error;
 
-       KASSERT(WM_LOCKED(sc));
+       KASSERT(WM_RX_LOCKED(sc));
 
        MGETHDR(m, M_DONTWAIT, MT_DATA);
        if (m == NULL)
@@ -3525,7 +3535,7 @@
        struct wm_rxsoft *rxs;
        int i;
 
-       KASSERT(WM_LOCKED(sc));
+       KASSERT(WM_RX_LOCKED(sc));
 
        for (i = 0; i < WM_NRXDESC; i++) {
                rxs = &sc->sc_rxsoft[i];
@@ -3548,9 +3558,9 @@
        struct wm_softc *sc = ifp->if_softc;
        int ret;
 
-       WM_LOCK(sc);
+       WM_BOTH_LOCK(sc);
        ret = wm_init_locked(ifp);
-       WM_UNLOCK(sc);
+       WM_BOTH_UNLOCK(sc);
 
        return ret;
 }
@@ -3563,7 +3573,7 @@
        int i, j, trynum, error = 0;
        uint32_t reg;
 
-       KASSERT(WM_LOCKED(sc));
+       KASSERT(WM_BOTH_LOCKED(sc));
        /*
         * *_HDR_ALIGNED_P is constant 1 if __NO_STRICT_ALIGMENT is set.
         * There is a small but measurable benefit to avoiding the adjusment
@@ -4022,9 +4032,9 @@
 {
        struct wm_softc *sc = ifp->if_softc;
 
-       WM_LOCK(sc);
+       WM_BOTH_LOCK(sc);
        wm_stop_locked(ifp, disable);
-       WM_UNLOCK(sc);
+       WM_BOTH_UNLOCK(sc);
 }
 
 static void
@@ -4034,7 +4044,7 @@
        struct wm_txsoft *txs;
        int i;
 
-       KASSERT(WM_LOCKED(sc));
+       KASSERT(WM_BOTH_LOCKED(sc));
 
        sc->sc_stopping = true;
 
@@ -4317,7 +4327,7 @@
 
        s = splnet();
 #endif
-       WM_LOCK(sc);
+       WM_TX_LOCK(sc);
 
        if (sc->sc_stopping)
                goto out;
@@ -4353,7 +4363,7 @@
        }
 
 out:
-       WM_UNLOCK(sc);
+       WM_TX_UNLOCK(sc);
 #ifndef WM_MPSAFE
        splx(s);
 #endif
@@ -4413,10 +4423,10 @@
 {
        struct wm_softc *sc = ifp->if_softc;
 
-       WM_LOCK(sc);
+       WM_TX_LOCK(sc);
        if (!sc->sc_stopping)
                wm_start_locked(ifp);
-       WM_UNLOCK(sc);
+       WM_TX_UNLOCK(sc);
 }
 
 static void
@@ -4433,7 +4443,7 @@
        uint32_t cksumcmd;
        uint8_t cksumfields;
 
-       KASSERT(WM_LOCKED(sc));
+       KASSERT(WM_TX_LOCKED(sc));
 
        if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
                return;
@@ -4929,10 +4939,10 @@
 {
        struct wm_softc *sc = ifp->if_softc;
 
-       WM_LOCK(sc);
+       WM_TX_LOCK(sc);
        if (!sc->sc_stopping)
                wm_nq_start_locked(ifp);
-       WM_UNLOCK(sc);



Home | Main Index | Thread Index | Old Index