Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Replace few simple_lock and ltsleep/wakeup uses with...



details:   https://anonhg.NetBSD.org/src/rev/f68559eac22f
branches:  trunk
changeset: 764375:f68559eac22f
user:      rmind <rmind%NetBSD.org@localhost>
date:      Mon Apr 18 01:47:28 2011 +0000

description:
Replace few simple_lock and ltsleep/wakeup uses with mutex(9) and condvar(9).

Note to all: please replace old primitives in your code! Thanks.

diffstat:

 sys/dev/ata/ata.c         |  79 +++++++++++++++++++++++++---------------------
 sys/dev/ata/atavar.h      |   8 +----
 sys/dev/scsipi/scsiconf.c |  40 +++++++++++++++--------
 3 files changed, 70 insertions(+), 57 deletions(-)

diffs (truncated from 315 to 300 lines):

diff -r 751da6aa26f0 -r f68559eac22f sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Mon Apr 18 01:36:24 2011 +0000
+++ b/sys/dev/ata/ata.c Mon Apr 18 01:47:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata.c,v 1.113 2010/03/28 20:46:18 snj Exp $    */
+/*     $NetBSD: ata.c,v 1.114 2011/04/18 01:47:28 rmind Exp $  */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.113 2010/03/28 20:46:18 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.114 2011/04/18 01:47:28 rmind Exp $");
 
 #include "opt_ata.h"
 
@@ -42,7 +42,6 @@
 #include <sys/errno.h>
 #include <sys/ataio.h>
 #include <sys/kmem.h>
-#include <sys/simplelock.h>
 #include <sys/intr.h>
 #include <sys/bus.h>
 #include <sys/once.h>
@@ -74,18 +73,18 @@
 #define ATADEBUG_PRINT(args, level)
 #endif
 
+static ONCE_DECL(ata_init_ctrl);
 static struct pool ata_xfer_pool;
 
 /*
  * A queue of atabus instances, used to ensure the same bus probe order
- * for a given hardware configuration at each boot.
+ * for a given hardware configuration at each boot.  Kthread probing
+ * devices on a atabus.  Only one probing at once. 
  */
-struct atabus_initq_head atabus_initq_head =
-    TAILQ_HEAD_INITIALIZER(atabus_initq_head);
-struct simplelock atabus_interlock = SIMPLELOCK_INITIALIZER;
-
-/* kernel thread probing devices on a atabus. Only one probing at once */
-struct lwp *atabus_configlwp;
+static TAILQ_HEAD(, atabus_initq)      atabus_initq_head;
+static kmutex_t                                atabus_qlock;
+static kcondvar_t                      atabus_qcv;
+static lwp_t *                         atabus_cfg_lwp;
 
 /*****************************************************************************
  * ATA bus layer.
@@ -111,6 +110,23 @@
 static void atabusconfig_thread(void *);
 
 /*
+ * atabus_init:
+ *
+ *     Initialize ATA subsystem structures.
+ */
+static int
+atabus_init(void)
+{
+
+       pool_init(&ata_xfer_pool, sizeof(struct ata_xfer), 0, 0, 0,
+           "ataspl", NULL, IPL_BIO);
+       TAILQ_INIT(&atabus_initq_head);
+       mutex_init(&atabus_qlock, MUTEX_DEFAULT, IPL_NONE);
+       cv_init(&atabus_qcv, "atainitq");
+       return 0;
+}
+
+/*
  * atabusprint:
  *
  *     Autoconfiguration print routine used by ATA controllers when
@@ -196,15 +212,14 @@
        splx(s);
 
        /* Make sure the devices probe in atabus order to avoid jitter. */
-       simple_lock(&atabus_interlock);
-       while(1) {
+       mutex_enter(&atabus_qlock);
+       for (;;) {
                atabus_initq = TAILQ_FIRST(&atabus_initq_head);
                if (atabus_initq->atabus_sc == atabus_sc)
                        break;
-               ltsleep(&atabus_initq_head, PRIBIO, "ata_initq", 0,
-                   &atabus_interlock);
+               cv_wait(&atabus_qcv, &atabus_qlock);
        }
-       simple_unlock(&atabus_interlock);
+       mutex_exit(&atabus_qlock);
 
        /* If no drives, abort here */
        for (i = 0; i < chp->ch_ndrive; i++)
@@ -219,19 +234,19 @@
 
 
        if ((error = kthread_create(PRI_NONE, 0, NULL, atabusconfig_thread,
-           atabus_sc, &atabus_configlwp,
+           atabus_sc, &atabus_cfg_lwp,
            "%scnf", device_xname(atac->atac_dev))) != 0)
                aprint_error_dev(atac->atac_dev,
                    "unable to create config thread: error %d\n", error);
        return;
 
  out:
-       simple_lock(&atabus_interlock);
+       mutex_enter(&atabus_qlock);
        TAILQ_REMOVE(&atabus_initq_head, atabus_initq, atabus_initq);
-       simple_unlock(&atabus_interlock);
+       cv_broadcast(&atabus_qcv);
+       mutex_exit(&atabus_qlock);
 
        free(atabus_initq, M_DEVBUF);
-       wakeup(&atabus_initq_head);
 
        ata_delref(chp);
 
@@ -248,13 +263,15 @@
        struct atabus_softc *atabus_sc = arg;
        struct ata_channel *chp = atabus_sc->sc_chan;
        struct atac_softc *atac = chp->ch_atac;
+       struct atabus_initq *atabus_initq = NULL;
        int i, s;
-       struct atabus_initq *atabus_initq = NULL;
 
-       simple_lock(&atabus_interlock);
+       /* XXX seems wrong */
+       mutex_enter(&atabus_qlock);
        atabus_initq = TAILQ_FIRST(&atabus_initq_head);
-       simple_unlock(&atabus_interlock);
        KASSERT(atabus_initq->atabus_sc == atabus_sc);
+       mutex_exit(&atabus_qlock);
+
        /*
         * Attach an ATAPI bus, if needed.
         */
@@ -326,12 +343,12 @@
        }
        splx(s);
 
-       simple_lock(&atabus_interlock);
+       mutex_enter(&atabus_qlock);
        TAILQ_REMOVE(&atabus_initq_head, atabus_initq, atabus_initq);
-       simple_unlock(&atabus_interlock);
+       cv_broadcast(&atabus_qcv);
+       mutex_exit(&atabus_qlock);
 
        free(atabus_initq, M_DEVBUF);
-       wakeup(&atabus_initq_head);
 
        ata_delref(chp);
 
@@ -424,15 +441,6 @@
        return (1);
 }
 
-static int
-atabus_xferpool_init(void)
-{
-
-       pool_init(&ata_xfer_pool, sizeof(struct ata_xfer), 0, 0, 0, "ataspl",
-           NULL, IPL_BIO);
-       return 0;
-}
-
 /*
  * atabus_attach:
  *
@@ -444,7 +452,6 @@
        struct atabus_softc *sc = device_private(self);
        struct ata_channel *chp = aux;
        struct atabus_initq *initq;
-       static ONCE_DECL(poolinit_ctrl);
        int error;
 
        sc->sc_chan = chp;
@@ -457,7 +464,7 @@
        if (ata_addref(chp))
                return;
 
-       RUN_ONCE(&poolinit_ctrl, atabus_xferpool_init);
+       RUN_ONCE(&ata_init_ctrl, atabus_init);
 
        initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK);
        initq->atabus_sc = sc;
diff -r 751da6aa26f0 -r f68559eac22f sys/dev/ata/atavar.h
--- a/sys/dev/ata/atavar.h      Mon Apr 18 01:36:24 2011 +0000
+++ b/sys/dev/ata/atavar.h      Mon Apr 18 01:47:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atavar.h,v 1.80 2009/10/19 18:41:12 bouyer Exp $       */
+/*     $NetBSD: atavar.h,v 1.81 2011/04/18 01:47:28 rmind Exp $        */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -108,12 +108,6 @@
        struct atabus_softc *atabus_sc;
 };
 
-#ifdef _KERNEL
-TAILQ_HEAD(atabus_initq_head, atabus_initq);
-extern struct atabus_initq_head atabus_initq_head;
-extern struct simplelock atabus_interlock;
-#endif /* _KERNEL */
-
 /* High-level functions and structures used by both ATA and ATAPI devices */
 struct ataparams;
 
diff -r 751da6aa26f0 -r f68559eac22f sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Mon Apr 18 01:36:24 2011 +0000
+++ b/sys/dev/scsipi/scsiconf.c Mon Apr 18 01:47:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsiconf.c,v 1.259 2011/04/02 20:52:10 macallan Exp $  */
+/*     $NetBSD: scsiconf.c,v 1.260 2011/04/18 01:47:28 rmind Exp $     */
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.259 2011/04/02 20:52:10 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.260 2011/04/18 01:47:28 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,12 +56,13 @@
 #include <sys/proc.h>
 #include <sys/kthread.h>
 #include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <sys/once.h>
 #include <sys/device.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
 #include <sys/scsiio.h>
 #include <sys/queue.h>
-#include <sys/simplelock.h>
 
 #include <dev/scsipi/scsi_all.h>
 #include <dev/scsipi/scsipi_all.h>
@@ -81,9 +82,10 @@
        TAILQ_ENTRY(scsi_initq) scsi_initq;
 };
 
-static TAILQ_HEAD(, scsi_initq) scsi_initq_head =
-    TAILQ_HEAD_INITIALIZER(scsi_initq_head);
-static struct simplelock scsibus_interlock = SIMPLELOCK_INITIALIZER;
+static ONCE_DECL(scsi_conf_ctrl);
+static TAILQ_HEAD(, scsi_initq)        scsi_initq_head;
+static kmutex_t                        scsibus_qlock;
+static kcondvar_t              scsibus_qcv;
 
 static int     scsi_probe_device(struct scsibus_softc *, int, int);
 
@@ -119,6 +121,16 @@
        scsi_kill_pending,
 };
 
+static int
+scsibus_init(void)
+{
+
+       TAILQ_INIT(&scsi_initq_head);
+       mutex_init(&scsibus_qlock, MUTEX_DEFAULT, IPL_NONE);
+       cv_init(&scsibus_qcv, "scsinitq");
+       return 0;
+}
+
 int
 scsiprint(void *aux, const char *pnp)
 {
@@ -175,6 +187,8 @@
        if (scsipi_adapter_addref(chan->chan_adapter))
                return;
 
+       RUN_ONCE(&scsi_conf_ctrl, scsibus_init);
+
        /* Initialize the channel structure first */
        chan->chan_init_cb = scsibus_config;
        chan->chan_init_cb_arg = sc;
@@ -209,25 +223,23 @@
        }
 
        /* Make sure the devices probe in scsibus order to avoid jitter. */
-       simple_lock(&scsibus_interlock);
+       mutex_enter(&scsibus_qlock);
        for (;;) {
                scsi_initq = TAILQ_FIRST(&scsi_initq_head);
                if (scsi_initq->sc_channel == chan)
                        break;
-               ltsleep(&scsi_initq_head, PRIBIO, "scsi_initq", 0,
-                   &scsibus_interlock);
+               cv_wait(&scsibus_qcv, &scsibus_qlock);
        }
-
-       simple_unlock(&scsibus_interlock);
+       mutex_exit(&scsibus_qlock);



Home | Main Index | Thread Index | Old Index