diff options
| author | mrg <mrg@NetBSD.org> | 2011-04-27 07:55:14 +0000 |
|---|---|---|
| committer | mrg <mrg@NetBSD.org> | 2011-04-27 07:55:14 +0000 |
| commit | 2a7f34a2c758a508310cfb4c0e9d5c5b1fc4c398 (patch) | |
| tree | 23b3434931603002e7896fc3aecaebd0206500c7 /sys/dev/raidframe/rf_engine.c | |
| parent | af44b9a0f869d1cb5083eb2c41e73bc19fb55ec7 (diff) | |
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 (limited to 'sys/dev/raidframe/rf_engine.c')
| -rw-r--r-- | sys/dev/raidframe/rf_engine.c | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/sys/dev/raidframe/rf_engine.c b/sys/dev/raidframe/rf_engine.c index 1df8d3c4112..16384aac274 100644 --- a/sys/dev/raidframe/rf_engine.c +++ b/sys/dev/raidframe/rf_engine.c @@ -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 @@ static void rf_RaidIOThread(RF_ThreadArg_t arg); /* 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 @@ rf_ConfigureEngine(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, * 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 @@ PropagateResults(RF_DagNode_t *node, int context) { 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 @@ DAGExecutionThread(RF_ThreadArg_t arg) { 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 @@ DAGExecutionThread(RF_ThreadArg_t arg) printf("raid%d: Engine thread is running\n", raidPtr->raidid); } #endif - s = splbio(); DO_LOCK(raidPtr); while (!raidPtr->shutdown_engine) { @@ -830,9 +829,13 @@ DAGExecutionThread(RF_ThreadArg_t arg) 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_RaidIOThread(RF_ThreadArg_t arg) { 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); + rf_lock_mutex2(raidPtr->iodone_lock); } /* process any pending outgoing IO */ - mutex_exit(&raidPtr->iodone_lock); + rf_unlock_mutex2(raidPtr->iodone_lock); raidstart(raidPtr); - mutex_enter(&raidPtr->iodone_lock); + rf_lock_mutex2(raidPtr->iodone_lock); } /* Let rf_ShutdownEngine know that we're done... */ raidPtr->shutdown_raidio = 0; - cv_signal(&raidPtr->iodone_cv); + rf_signal_cond2(raidPtr->iodone_cv); - mutex_exit(&raidPtr->iodone_lock); - splx(s); + rf_unlock_mutex2(raidPtr->iodone_lock); kthread_exit(0); } |
