Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/raidframe prepare to convert more raidframe old lock...



details:   https://anonhg.NetBSD.org/src/rev/255e59cca919
branches:  trunk
changeset: 764556:255e59cca919
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Apr 27 07:55:14 2011 +0000

description:
prepare to convert more raidframe old lock/sleep APIs to mutex/condvar:

- remove RF_DECLARE_EXTERN_MUTEX and RF_DECLARE_STATIC_MUTEX, the qualifier
  can be provided at the use point with the normal define
- rename the *LGMGR_MUTEX() macros to *mutex2() names, and add some more
  defines for use:
        rf_declare_mutex2()
        rf_declare_cond2()
        rf_lock_mutex2()
        rf_unlock_mutex2()
        rf_init_mutex2()
        rf_destroy_mutex2()
        rf_init_cond2()
        rf_destroy_cond2()
        rf_wait_cond2()
        rf_signal_cond2()
        rf_broadcast_cond2()
- use the new names for the configureMutex(), which previous used some combo
  of direct mutex* calls and macros
- convert the node_queue to use a mutex/cv combo
- in rf_ShutdownEngine() and DAGExecutionThread(), also signal the former from
  the latter when it is done and about to exit
- convert iodone_lock to use the new macros

diffstat:

 sys/dev/raidframe/rf_acctrace.h    |   4 +-
 sys/dev/raidframe/rf_driver.c      |  20 ++++----
 sys/dev/raidframe/rf_driver.h      |   4 +-
 sys/dev/raidframe/rf_engine.c      |  80 +++++++++++++++++++-------------------
 sys/dev/raidframe/rf_netbsdkintf.c |  20 ++++----
 sys/dev/raidframe/rf_paritymap.c   |  14 +++---
 sys/dev/raidframe/rf_raid.h        |   9 ++-
 sys/dev/raidframe/rf_states.c      |  10 ++--
 sys/dev/raidframe/rf_threadstuff.h |  39 ++++++++++-------
 9 files changed, 104 insertions(+), 96 deletions(-)

diffs (truncated from 569 to 300 lines):

diff -r bf8d61811bd1 -r 255e59cca919 sys/dev/raidframe/rf_acctrace.h
--- a/sys/dev/raidframe/rf_acctrace.h   Wed Apr 27 07:47:33 2011 +0000
+++ b/sys/dev/raidframe/rf_acctrace.h   Wed Apr 27 07:55:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_acctrace.h,v 1.8 2005/12/11 12:23:37 christos Exp $ */
+/*     $NetBSD: rf_acctrace.h,v 1.9 2011/04/27 07:55:14 mrg Exp $      */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -123,7 +123,7 @@
        RF_Hist_t tot_hist[RF_HIST_NUM_BUCKETS];
 }       RF_AccTotals_t;
 
-RF_DECLARE_EXTERN_MUTEX(rf_tracing_mutex)
+extern RF_DECLARE_MUTEX(rf_tracing_mutex);
 
 
 int     rf_ConfigureAccessTrace(RF_ShutdownList_t ** listp);
diff -r bf8d61811bd1 -r 255e59cca919 sys/dev/raidframe/rf_driver.c
--- a/sys/dev/raidframe/rf_driver.c     Wed Apr 27 07:47:33 2011 +0000
+++ b/sys/dev/raidframe/rf_driver.c     Wed Apr 27 07:55:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_driver.c,v 1.124 2011/04/23 22:22:46 mrg Exp $      */
+/*     $NetBSD: rf_driver.c,v 1.125 2011/04/27 07:55:14 mrg Exp $      */
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -66,7 +66,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.124 2011/04/23 22:22:46 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.125 2011/04/27 07:55:14 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_raid_diagnostic.h"
@@ -145,8 +145,8 @@
 static int configureCount = 0; /* number of active configurations */
 static int isconfigged = 0;    /* is basic raidframe (non per-array)
                                 * stuff configured */
-RF_DECLARE_LKMGR_STATIC_MUTEX(configureMutex)  /* used to lock the configuration
-                                        * stuff */
+static rf_declare_mutex2(configureMutex); /* used to lock the configuration
+                                          * stuff */
 static RF_ShutdownList_t *globalShutdown;      /* non array-specific
                                                 * stuff */
 
@@ -162,7 +162,7 @@
        if (raidframe_booted)
                return (EBUSY);
        raidframe_booted = 1;
-       mutex_init(&configureMutex, MUTEX_DEFAULT, IPL_NONE);
+       rf_init_mutex2(configureMutex, IPL_NONE);
        configureCount = 0;
        isconfigged = 0;
        globalShutdown = NULL;
@@ -176,7 +176,7 @@
 rf_UnconfigureArray(void)
 {
 
-       RF_LOCK_LKMGR_MUTEX(configureMutex);
+       rf_lock_mutex2(configureMutex);
        if (--configureCount == 0) {    /* if no active configurations, shut
                                         * everything down */
                isconfigged = 0;
@@ -191,7 +191,7 @@
                        rf_print_unfreed();
 #endif
        }
-       RF_UNLOCK_LKMGR_MUTEX(configureMutex);
+       rf_unlock_mutex2(configureMutex);
 }
 
 /*
@@ -265,7 +265,7 @@
                RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
                rf_ShutdownList(&globalShutdown); \
                configureCount--; \
-               RF_UNLOCK_LKMGR_MUTEX(configureMutex); \
+               rf_unlock_mutex2(configureMutex); \
                return(rc); \
        } \
 }
@@ -296,7 +296,7 @@
        RF_RowCol_t col;
        int rc;
 
-       RF_LOCK_LKMGR_MUTEX(configureMutex);
+       rf_lock_mutex2(configureMutex);
        configureCount++;
        if (isconfigged == 0) {
                rf_mutex_init(&rf_printf_mutex);
@@ -329,7 +329,7 @@
                DO_INIT_CONFIGURE(rf_ConfigurePSStatus);
                isconfigged = 1;
        }
-       RF_UNLOCK_LKMGR_MUTEX(configureMutex);
+       rf_unlock_mutex2(configureMutex);
 
        DO_RAID_MUTEX(&raidPtr->mutex);
        /* set up the cleanup list.  Do this after ConfigureDebug so that
diff -r bf8d61811bd1 -r 255e59cca919 sys/dev/raidframe/rf_driver.h
--- a/sys/dev/raidframe/rf_driver.h     Wed Apr 27 07:47:33 2011 +0000
+++ b/sys/dev/raidframe/rf_driver.h     Wed Apr 27 07:55:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_driver.h,v 1.17 2007/03/04 06:02:38 christos Exp $  */
+/*     $NetBSD: rf_driver.h,v 1.18 2011/04/27 07:55:15 mrg Exp $       */
 /*
  * rf_driver.h
  */
@@ -41,7 +41,7 @@
 #define RF_RETRY_THRESHOLD 5
 #endif
 
-RF_DECLARE_EXTERN_MUTEX(rf_printf_mutex)
+extern RF_DECLARE_MUTEX(rf_printf_mutex);
 int rf_BootRaidframe(void);
 int rf_UnbootRaidframe(void);
 int rf_Shutdown(RF_Raid_t *);
diff -r bf8d61811bd1 -r 255e59cca919 sys/dev/raidframe/rf_engine.c
--- a/sys/dev/raidframe/rf_engine.c     Wed Apr 27 07:47:33 2011 +0000
+++ b/sys/dev/raidframe/rf_engine.c     Wed Apr 27 07:55:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_engine.c,v 1.43 2011/04/23 22:22:46 mrg Exp $       */
+/*     $NetBSD: rf_engine.c,v 1.44 2011/04/27 07:55:15 mrg Exp $       */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -55,7 +55,7 @@
  ****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.43 2011/04/23 22:22:46 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.44 2011/04/27 07:55:15 mrg Exp $");
 
 #include <sys/errno.h>
 
@@ -77,51 +77,52 @@
 /* synchronization primitives for this file.  DO_WAIT should be enclosed in a while loop. */
 
 #define DO_LOCK(_r_) \
-do { \
-       ks = splbio(); \
-       RF_LOCK_MUTEX((_r_)->node_queue_mutex); \
-} while (0)
+       rf_lock_mutex2((_r_)->node_queue_mutex)
 
 #define DO_UNLOCK(_r_) \
-do { \
-       RF_UNLOCK_MUTEX((_r_)->node_queue_mutex); \
-       splx(ks); \
-} while (0)
+       rf_unlock_mutex2((_r_)->node_queue_mutex)
 
 #define        DO_WAIT(_r_) \
-       RF_WAIT_COND((_r_)->node_queue, (_r_)->node_queue_mutex)
+       rf_wait_cond2((_r_)->node_queue_cv, (_r_)->node_queue_mutex)
 
 #define        DO_SIGNAL(_r_) \
-       RF_BROADCAST_COND((_r_)->node_queue)    /* XXX RF_SIGNAL_COND? */
+       rf_broadcast_cond2((_r_)->node_queue_cv)        /* XXX RF_SIGNAL_COND? */
 
 static void
 rf_ShutdownEngine(void *arg)
 {
        RF_Raid_t *raidPtr;
-       int ks;
 
        raidPtr = (RF_Raid_t *) arg;
 
        /* Tell the rf_RaidIOThread to shutdown */
-       mutex_enter(&raidPtr->iodone_lock);
+       rf_lock_mutex2(raidPtr->iodone_lock);
 
        raidPtr->shutdown_raidio = 1;
-       cv_signal(&raidPtr->iodone_cv);
+       rf_signal_cond2(raidPtr->iodone_cv);
 
        /* ...and wait for it to tell us it has finished */
        while (raidPtr->shutdown_raidio)
-               cv_wait(&raidPtr->iodone_cv, &raidPtr->iodone_lock);
+               rf_wait_cond2(raidPtr->iodone_cv, raidPtr->iodone_lock);
 
-       mutex_exit(&raidPtr->iodone_lock);
+       rf_unlock_mutex2(raidPtr->iodone_lock);
 
        /* Now shut down the DAG execution engine. */
        DO_LOCK(raidPtr);
        raidPtr->shutdown_engine = 1;
        DO_SIGNAL(raidPtr);
+
+       /* ...and wait for it to tell us it has finished */
+       while (raidPtr->shutdown_engine)
+               DO_WAIT(raidPtr);
+
        DO_UNLOCK(raidPtr);
 
-       mutex_destroy(&raidPtr->iodone_lock);
-       cv_destroy(&raidPtr->iodone_cv);
+       rf_destroy_mutex2(raidPtr->node_queue_mutex);
+       rf_destroy_cond2(raidPtr->node_queue_cv);
+
+       rf_destroy_mutex2(raidPtr->iodone_lock);
+       rf_destroy_cond2(raidPtr->iodone_cv);
 }
 
 int
@@ -133,10 +134,11 @@
         * Initialise iodone for the IO thread.
         */
        TAILQ_INIT(&(raidPtr->iodone));
-       mutex_init(&raidPtr->iodone_lock, MUTEX_DEFAULT, IPL_VM);
-       cv_init(&raidPtr->iodone_cv, "raidiow");
+       rf_init_mutex2(raidPtr->iodone_lock, IPL_VM);
+       rf_init_cond2(raidPtr->iodone_cv, "raidiow");
 
-       rf_mutex_init(&raidPtr->node_queue_mutex);
+       rf_init_mutex2(raidPtr->node_queue_mutex, IPL_VM);
+       rf_init_cond2(raidPtr->node_queue_cv, "rfwcond");
        raidPtr->node_queue = NULL;
        raidPtr->dags_in_flight = 0;
 
@@ -425,7 +427,7 @@
 {
        RF_DagNode_t *s, *a;
        RF_Raid_t *raidPtr;
-       int     i, ks;
+       int     i;
        RF_DagNode_t *finishlist = NULL;        /* a list of NIL nodes to be
                                                 * finished */
        RF_DagNode_t *skiplist = NULL;  /* list of nodes with failed truedata
@@ -750,8 +752,6 @@
 {
        RF_DagNode_t *nd, *local_nq, *term_nq, *fire_nq;
        RF_Raid_t *raidPtr;
-       int     ks;
-       int     s;
 
        raidPtr = (RF_Raid_t *) arg;
 
@@ -760,7 +760,6 @@
                printf("raid%d: Engine thread is running\n", raidPtr->raidid);
        }
 #endif
-       s = splbio();
 
        DO_LOCK(raidPtr);
        while (!raidPtr->shutdown_engine) {
@@ -830,9 +829,13 @@
                        DO_WAIT(raidPtr);
                }
        }
+
+       /* Let rf_ShutdownEngine know that we're done... */
+       raidPtr->shutdown_engine = 0;
+       DO_SIGNAL(raidPtr);
+
        DO_UNLOCK(raidPtr);
 
-       splx(s);
        kthread_exit(0);
 }
 
@@ -851,49 +854,46 @@
 {
        RF_Raid_t *raidPtr;
        RF_DiskQueueData_t *req;
-       int s;
 
        raidPtr = (RF_Raid_t *) arg;
 
-       s = splbio();
-       mutex_enter(&raidPtr->iodone_lock);
+       rf_lock_mutex2(raidPtr->iodone_lock);
 
        while (!raidPtr->shutdown_raidio) {
                /* if there is nothing to do, then snooze. */
                if (TAILQ_EMPTY(&(raidPtr->iodone)) &&
                    rf_buf_queue_check(raidPtr->raidid)) {
-                       cv_wait(&raidPtr->iodone_cv, &raidPtr->iodone_lock);
+                       rf_wait_cond2(raidPtr->iodone_cv, raidPtr->iodone_lock);
                }
 
                /* Check for deferred parity-map-related work. */
                if (raidPtr->parity_map != NULL) {
-                       mutex_exit(&raidPtr->iodone_lock);
+                       rf_unlock_mutex2(raidPtr->iodone_lock);
                        rf_paritymap_checkwork(raidPtr->parity_map);
-                       mutex_enter(&raidPtr->iodone_lock);
+                       rf_lock_mutex2(raidPtr->iodone_lock);
                }
 
                /* See what I/Os, if any, have arrived */
                while ((req = TAILQ_FIRST(&(raidPtr->iodone))) != NULL) {
                        TAILQ_REMOVE(&(raidPtr->iodone), req, iodone_entries);
-                       mutex_exit(&raidPtr->iodone_lock);
+                       rf_unlock_mutex2(raidPtr->iodone_lock);
                        rf_DiskIOComplete(req->queue, req, req->error);
                        (req->CompleteFunc) (req->argument, req->error);
-                       mutex_enter(&raidPtr->iodone_lock);



Home | Main Index | Thread Index | Old Index