Index: rf_engine.c =================================================================== RCS file: /cvsroot/src/sys/dev/raidframe/rf_engine.c,v retrieving revision 1.43 diff -p -r1.43 rf_engine.c *** rf_engine.c 23 Apr 2011 22:22:46 -0000 1.43 --- rf_engine.c 24 Apr 2011 00:29:30 -0000 *************** static void rf_ShutdownEngine(void *); *** 74,104 **** static void DAGExecutionThread(RF_ThreadArg_t arg); 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) - - #define DO_UNLOCK(_r_) \ - do { \ - RF_UNLOCK_MUTEX((_r_)->node_queue_mutex); \ - splx(ks); \ - } while (0) - - #define DO_WAIT(_r_) \ - RF_WAIT_COND((_r_)->node_queue, (_r_)->node_queue_mutex) - - #define DO_SIGNAL(_r_) \ - RF_BROADCAST_COND((_r_)->node_queue) /* XXX RF_SIGNAL_COND? */ - static void rf_ShutdownEngine(void *arg) { RF_Raid_t *raidPtr; - int ks; raidPtr = (RF_Raid_t *) arg; --- 74,83 ---- *************** rf_ShutdownEngine(void *arg) *** 115,127 **** mutex_exit(&raidPtr->iodone_lock); /* Now shut down the DAG execution engine. */ ! DO_LOCK(raidPtr); raidPtr->shutdown_engine = 1; ! DO_SIGNAL(raidPtr); ! DO_UNLOCK(raidPtr); mutex_destroy(&raidPtr->iodone_lock); cv_destroy(&raidPtr->iodone_cv); } int --- 94,109 ---- mutex_exit(&raidPtr->iodone_lock); /* Now shut down the DAG execution engine. */ ! mutex_enter(&raidPtr->node_queue_lock); raidPtr->shutdown_engine = 1; ! cv_signal(&raidPtr->node_queue_cv); ! mutex_exit(&raidPtr->node_queue_lock); mutex_destroy(&raidPtr->iodone_lock); cv_destroy(&raidPtr->iodone_cv); + + mutex_destroy(&raidPtr->node_queue_lock); + cv_destroy(&raidPtr->node_queue_cv); } int *************** rf_ConfigureEngine(RF_ShutdownList_t **l *** 136,142 **** mutex_init(&raidPtr->iodone_lock, MUTEX_DEFAULT, IPL_VM); cv_init(&raidPtr->iodone_cv, "raidiow"); ! rf_mutex_init(&raidPtr->node_queue_mutex); raidPtr->node_queue = NULL; raidPtr->dags_in_flight = 0; --- 118,126 ---- mutex_init(&raidPtr->iodone_lock, MUTEX_DEFAULT, IPL_VM); cv_init(&raidPtr->iodone_cv, "raidiow"); ! mutex_init(&raidPtr->node_queue_lock, MUTEX_DEFAULT, IPL_VM); ! cv_init(&raidPtr->node_queue_cv, "raidnqw"); ! raidPtr->node_queue = NULL; raidPtr->dags_in_flight = 0; *************** PropagateResults(RF_DagNode_t *node, int *** 425,431 **** { RF_DagNode_t *s, *a; RF_Raid_t *raidPtr; ! int i, ks; RF_DagNode_t *finishlist = NULL; /* a list of NIL nodes to be * finished */ RF_DagNode_t *skiplist = NULL; /* list of nodes with failed truedata --- 409,415 ---- { RF_DagNode_t *s, *a; RF_Raid_t *raidPtr; ! 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 *************** PropagateResults(RF_DagNode_t *node, int *** 436,442 **** raidPtr = node->dagHdr->raidPtr; ! DO_LOCK(raidPtr); /* debug - validate fire counts */ for (i = 0; i < node->numAntecedents; i++) { --- 420,426 ---- raidPtr = node->dagHdr->raidPtr; ! mutex_enter(&raidPtr->node_queue_lock); /* debug - validate fire counts */ for (i = 0; i < node->numAntecedents; i++) { *************** PropagateResults(RF_DagNode_t *node, int *** 510,518 **** /* xfer our local list of nodes to the node queue */ q->next = raidPtr->node_queue; raidPtr->node_queue = qh; ! DO_SIGNAL(raidPtr); } ! DO_UNLOCK(raidPtr); for (; skiplist; skiplist = next) { next = skiplist->next; --- 494,502 ---- /* xfer our local list of nodes to the node queue */ q->next = raidPtr->node_queue; raidPtr->node_queue = qh; ! cv_signal(&raidPtr->node_queue_cv); } ! mutex_exit(&raidPtr->node_queue_lock); for (; skiplist; skiplist = next) { next = skiplist->next; *************** PropagateResults(RF_DagNode_t *node, int *** 591,599 **** /* xfer our local list of nodes to the node queue */ q->next = raidPtr->node_queue; raidPtr->node_queue = qh; ! DO_SIGNAL(raidPtr); } ! DO_UNLOCK(raidPtr); for (; finishlist; finishlist = next) { /* NIL nodes: no need to fire them */ next = finishlist->next; --- 575,583 ---- /* xfer our local list of nodes to the node queue */ q->next = raidPtr->node_queue; raidPtr->node_queue = qh; ! cv_signal(&raidPtr->node_queue_cv); } ! mutex_exit(&raidPtr->node_queue_lock); for (; finishlist; finishlist = next) { /* NIL nodes: no need to fire them */ next = finishlist->next; *************** DAGExecutionThread(RF_ThreadArg_t arg) *** 750,757 **** { RF_DagNode_t *nd, *local_nq, *term_nq, *fire_nq; RF_Raid_t *raidPtr; - int ks; - int s; raidPtr = (RF_Raid_t *) arg; --- 734,739 ---- *************** DAGExecutionThread(RF_ThreadArg_t arg) *** 760,768 **** printf("raid%d: Engine thread is running\n", raidPtr->raidid); } #endif ! s = splbio(); ! ! DO_LOCK(raidPtr); while (!raidPtr->shutdown_engine) { while (raidPtr->node_queue != NULL) { --- 742,748 ---- printf("raid%d: Engine thread is running\n", raidPtr->raidid); } #endif ! mutex_enter(&raidPtr->node_queue_lock); while (!raidPtr->shutdown_engine) { while (raidPtr->node_queue != NULL) { *************** DAGExecutionThread(RF_ThreadArg_t arg) *** 770,776 **** fire_nq = NULL; term_nq = NULL; raidPtr->node_queue = NULL; ! DO_UNLOCK(raidPtr); /* first, strip out the terminal nodes */ while (local_nq) { --- 750,756 ---- fire_nq = NULL; term_nq = NULL; raidPtr->node_queue = NULL; ! mutex_exit(&raidPtr->node_queue_lock); /* first, strip out the terminal nodes */ while (local_nq) { *************** DAGExecutionThread(RF_ThreadArg_t arg) *** 823,838 **** /* fire remaining nodes */ FireNodeList(fire_nq); ! DO_LOCK(raidPtr); } while (!raidPtr->shutdown_engine && raidPtr->node_queue == NULL) { ! DO_WAIT(raidPtr); } } ! DO_UNLOCK(raidPtr); - splx(s); kthread_exit(0); } --- 803,819 ---- /* fire remaining nodes */ FireNodeList(fire_nq); ! mutex_enter(&raidPtr->node_queue_lock); } + /* should be enclosed in a while loop. */ while (!raidPtr->shutdown_engine && raidPtr->node_queue == NULL) { ! cv_wait(&raidPtr->node_queue_cv, ! &raidPtr->node_queue_lock); } } ! mutex_exit(&raidPtr->node_queue_lock); kthread_exit(0); } *************** rf_RaidIOThread(RF_ThreadArg_t arg) *** 851,861 **** { RF_Raid_t *raidPtr; RF_DiskQueueData_t *req; - int s; raidPtr = (RF_Raid_t *) arg; - s = splbio(); mutex_enter(&raidPtr->iodone_lock); while (!raidPtr->shutdown_raidio) { --- 832,840 ---- *************** rf_RaidIOThread(RF_ThreadArg_t arg) *** 893,899 **** cv_signal(&raidPtr->iodone_cv); mutex_exit(&raidPtr->iodone_lock); - splx(s); kthread_exit(0); } --- 872,877 ---- Index: rf_raid.h =================================================================== RCS file: /cvsroot/src/sys/dev/raidframe/rf_raid.h,v retrieving revision 1.39 diff -p -r1.39 rf_raid.h *** rf_raid.h 23 Apr 2011 06:29:05 -0000 1.39 --- rf_raid.h 24 Apr 2011 00:29:30 -0000 *************** struct RF_Raid_s { *** 216,222 **** /* * Engine thread control */ ! RF_DECLARE_MUTEX(node_queue_mutex) RF_DagNode_t *node_queue; RF_Thread_t parity_rewrite_thread; RF_Thread_t copyback_thread; --- 216,223 ---- /* * Engine thread control */ ! kmutex_t node_queue_lock; ! kcondvar_t node_queue_cv; RF_DagNode_t *node_queue; RF_Thread_t parity_rewrite_thread; RF_Thread_t copyback_thread;