Source-Changes-HG archive

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

[src/trunk]: src/sys/dev replace spl and tsleep with mutex and condvar.



details:   https://anonhg.NetBSD.org/src/rev/3d776d82b0b4
branches:  trunk
changeset: 810039:3d776d82b0b4
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Aug 16 14:02:52 2015 +0000

description:
replace spl and tsleep with mutex and condvar.

diffstat:

 sys/dev/ld.c    |  38 +++++++++++++++++++-------------------
 sys/dev/ldvar.h |   3 ++-
 2 files changed, 21 insertions(+), 20 deletions(-)

diffs (133 lines):

diff -r 9b8412551651 -r 3d776d82b0b4 sys/dev/ld.c
--- a/sys/dev/ld.c      Sun Aug 16 11:37:39 2015 +0000
+++ b/sys/dev/ld.c      Sun Aug 16 14:02:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld.c,v 1.84 2015/07/22 10:32:16 skrll Exp $    */
+/*     $NetBSD: ld.c,v 1.85 2015/08/16 14:02:52 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.84 2015/07/22 10:32:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.85 2015/08/16 14:02:52 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -126,6 +126,7 @@
        struct dk_softc *dksc = &sc->sc_dksc;
 
        mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_VM);
+       cv_init(&sc->sc_drain, "lddrain");
 
        if ((sc->sc_flags & LDF_ENABLED) == 0) {
                return;
@@ -168,11 +169,10 @@
 int
 ldadjqparam(struct ld_softc *sc, int xmax)
 {
-       int s;
 
-       s = splbio();
+       mutex_enter(&sc->sc_mutex);
        sc->sc_maxqueuecnt = xmax;
-       splx(s);
+       mutex_exit(&sc->sc_mutex);
 
        return (0);
 }
@@ -181,7 +181,7 @@
 ldbegindetach(struct ld_softc *sc, int flags)
 {
        struct dk_softc *dksc = &sc->sc_dksc;
-       int s, rv = 0;
+       int rv = 0;
 
        if ((sc->sc_flags & LDF_ENABLED) == 0)
                return (0);
@@ -191,18 +191,16 @@
        if (rv != 0)
                return rv;
 
-       s = splbio();
+       mutex_enter(&sc->sc_mutex);
        sc->sc_maxqueuecnt = 0;
 
        dk_detach(dksc);
 
        while (sc->sc_queuecnt > 0) {
                sc->sc_flags |= LDF_DRAIN;
-               rv = tsleep(&sc->sc_queuecnt, PRIBIO, "lddrn", 0);
-               if (rv)
-                       break;
+               cv_wait(&sc->sc_drain, &sc->sc_mutex);
        }
-       splx(s);
+       mutex_exit(&sc->sc_mutex);
 
        return (rv);
 }
@@ -211,27 +209,28 @@
 ldenddetach(struct ld_softc *sc)
 {
        struct dk_softc *dksc = &sc->sc_dksc;
-       int s, bmaj, cmaj, i, mn;
+       int bmaj, cmaj, i, mn;
 
        if ((sc->sc_flags & LDF_ENABLED) == 0)
                return;
 
+       mutex_enter(&sc->sc_mutex);
+
        /* Wait for commands queued with the hardware to complete. */
        if (sc->sc_queuecnt != 0)
                if (tsleep(&sc->sc_queuecnt, PRIBIO, "lddtch", 30 * hz))
                        printf("%s: not drained\n", dksc->sc_xname);
 
+       /* Kill off any queued buffers. */
+       bufq_drain(dksc->sc_bufq);
+       mutex_exit(&sc->sc_mutex);
+
+       bufq_free(dksc->sc_bufq);
+
        /* Locate the major numbers. */
        bmaj = bdevsw_lookup_major(&ld_bdevsw);
        cmaj = cdevsw_lookup_major(&ld_cdevsw);
 
-       /* Kill off any queued buffers. */
-       s = splbio();
-       bufq_drain(dksc->sc_bufq);
-       splx(s);
-
-       bufq_free(dksc->sc_bufq);
-
        /* Nuke the vnodes for any open instances. */
        for (i = 0; i < MAXPARTITIONS; i++) {
                mn = DISKMINOR(device_unit(dksc->sc_dev), i);
@@ -263,6 +262,7 @@
                if ((*sc->sc_flush)(sc, 0) != 0)
                        aprint_error_dev(dksc->sc_dev, "unable to flush cache\n");
 #endif
+       cv_destroy(&sc->sc_drain);
        mutex_destroy(&sc->sc_mutex);
 }
 
diff -r 9b8412551651 -r 3d776d82b0b4 sys/dev/ldvar.h
--- a/sys/dev/ldvar.h   Sun Aug 16 11:37:39 2015 +0000
+++ b/sys/dev/ldvar.h   Sun Aug 16 14:02:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ldvar.h,v 1.24 2015/07/26 07:23:10 skrll Exp $ */
+/*     $NetBSD: ldvar.h,v 1.25 2015/08/16 14:02:52 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 struct ld_softc {
        struct dk_softc sc_dksc;
        kmutex_t        sc_mutex;
+       kcondvar_t      sc_drain;
        krndsource_t    sc_rnd_source;
 
        int             sc_queuecnt;    /* current h/w queue depth */



Home | Main Index | Thread Index | Old Index