Module Name:    src
Committed By:   mrg
Date:           Sat Apr 23 06:29:06 UTC 2011

Modified Files:
        src/sys/dev/raidframe: rf_driver.c rf_engine.c rf_netbsdkintf.c
            rf_paritymap.c rf_raid.h rf_states.c

Log Message:
convert the iodone_lock to a mutex, and use a condvar for signalling.

this only handles the smallest use of old simple_lock/tsleep/wakeup
APIs inside raidframe, and it points out that cv(9)'s have only one
wait channel per cv, whereas each tsleep() caller can specify a
different wait channel.  this change removes the difference between
normal raidio and waiting for IO during shutdown.

i've tested this one 3 systems, ran atf, and had mlelstv and rmind
review the change.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/raidframe/rf_driver.c
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/raidframe/rf_engine.c
cvs rdiff -u -r1.284 -r1.285 src/sys/dev/raidframe/rf_netbsdkintf.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/raidframe/rf_paritymap.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/raidframe/rf_raid.h
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/raidframe/rf_states.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/raidframe/rf_driver.c
diff -u src/sys/dev/raidframe/rf_driver.c:1.122 src/sys/dev/raidframe/rf_driver.c:1.123
--- src/sys/dev/raidframe/rf_driver.c:1.122	Tue Nov 17 18:54:26 2009
+++ src/sys/dev/raidframe/rf_driver.c	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_driver.c,v 1.122 2009/11/17 18:54:26 jld Exp $	*/
+/*	$NetBSD: rf_driver.c,v 1.123 2011/04/23 06:29:05 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.122 2009/11/17 18:54:26 jld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.123 2011/04/23 06:29:05 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_raid_diagnostic.h"
@@ -240,6 +240,9 @@
 		       "rfreshutdown",0);
 	}
 
+	mutex_destroy(&raidPtr->iodone_lock);
+	cv_destroy(&raidPtr->iodone_cv);
+
 	raidPtr->valid = 0;
 
 	if (raidPtr->parity_map != NULL)
@@ -351,7 +354,8 @@
 	raidPtr->reconControl = NULL;
 
 	TAILQ_INIT(&(raidPtr->iodone));
-	simple_lock_init(&(raidPtr->iodone_lock));
+	mutex_init(&raidPtr->iodone_lock, MUTEX_DEFAULT, IPL_VM);
+	cv_init(&raidPtr->iodone_cv, "raidiow");
 
 	DO_RAID_INIT_CONFIGURE(rf_ConfigureEngine);
 	DO_RAID_INIT_CONFIGURE(rf_ConfigureStripeLocks);

Index: src/sys/dev/raidframe/rf_engine.c
diff -u src/sys/dev/raidframe/rf_engine.c:1.41 src/sys/dev/raidframe/rf_engine.c:1.42
--- src/sys/dev/raidframe/rf_engine.c:1.41	Mon Sep 13 08:43:06 2010
+++ src/sys/dev/raidframe/rf_engine.c	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_engine.c,v 1.41 2010/09/13 08:43:06 drochner Exp $	*/
+/*	$NetBSD: rf_engine.c,v 1.42 2011/04/23 06:29:05 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.41 2010/09/13 08:43:06 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.42 2011/04/23 06:29:05 mrg Exp $");
 
 #include <sys/errno.h>
 
@@ -103,17 +103,16 @@
 	raidPtr = (RF_Raid_t *) arg;
 
 	/* Tell the rf_RaidIOThread to shutdown */
-	simple_lock(&(raidPtr->iodone_lock));
+	mutex_enter(&raidPtr->iodone_lock);
 
 	raidPtr->shutdown_raidio = 1;
-	wakeup(&(raidPtr->iodone));
+	cv_signal(&raidPtr->iodone_cv);
 
 	/* ...and wait for it to tell us it has finished */
 	while (raidPtr->shutdown_raidio)
- 		ltsleep(&(raidPtr->shutdown_raidio), PRIBIO, "raidshutdown", 0,
-			&(raidPtr->iodone_lock));
+		cv_wait(&raidPtr->iodone_cv, &raidPtr->iodone_lock);
 
-	simple_unlock(&(raidPtr->iodone_lock));
+	mutex_exit(&raidPtr->iodone_lock);
 
  	/* Now shut down the DAG execution engine. */
  	DO_LOCK(raidPtr);
@@ -848,44 +847,43 @@
 	raidPtr = (RF_Raid_t *) arg;
 
 	s = splbio();
-	simple_lock(&(raidPtr->iodone_lock));
+	mutex_enter(&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)) {
-			ltsleep(&(raidPtr->iodone), PRIBIO, "raidiow", 0,
-				&(raidPtr->iodone_lock));
+			cv_wait(&raidPtr->iodone_cv, &raidPtr->iodone_lock);
 		}
 
 		/* Check for deferred parity-map-related work. */
 		if (raidPtr->parity_map != NULL) {
-			simple_unlock(&(raidPtr->iodone_lock));
+			mutex_exit(&raidPtr->iodone_lock);
 			rf_paritymap_checkwork(raidPtr->parity_map);
-			simple_lock(&(raidPtr->iodone_lock));
+			mutex_enter(&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);
-			simple_unlock(&(raidPtr->iodone_lock));
+			mutex_exit(&raidPtr->iodone_lock);
 			rf_DiskIOComplete(req->queue, req, req->error);
 			(req->CompleteFunc) (req->argument, req->error);
-			simple_lock(&(raidPtr->iodone_lock));
+			mutex_enter(&raidPtr->iodone_lock);
 		}
 
 		/* process any pending outgoing IO */
-		simple_unlock(&(raidPtr->iodone_lock));
+		mutex_exit(&raidPtr->iodone_lock);
 		raidstart(raidPtr);
-		simple_lock(&(raidPtr->iodone_lock));
+		mutex_enter(&raidPtr->iodone_lock);
 
 	}
 
 	/* Let rf_ShutdownEngine know that we're done... */
 	raidPtr->shutdown_raidio = 0;
-	wakeup(&(raidPtr->shutdown_raidio));
+	cv_signal(&raidPtr->iodone_cv);
 
-	simple_unlock(&(raidPtr->iodone_lock));
+	mutex_exit(&raidPtr->iodone_lock);
 	splx(s);
 
 	kthread_exit(0);

Index: src/sys/dev/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.284 src/sys/dev/raidframe/rf_netbsdkintf.c:1.285
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.284	Fri Mar 18 23:53:26 2011
+++ src/sys/dev/raidframe/rf_netbsdkintf.c	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_netbsdkintf.c,v 1.284 2011/03/18 23:53:26 mrg Exp $	*/
+/*	$NetBSD: rf_netbsdkintf.c,v 1.285 2011/04/23 06:29:05 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  ***********************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.284 2011/03/18 23:53:26 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.285 2011/04/23 06:29:05 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -829,8 +829,6 @@
 void
 raidstrategy(struct buf *bp)
 {
-	int s;
-
 	unsigned int raidID = raidunit(bp->b_dev);
 	RF_Raid_t *raidPtr;
 	struct raid_softc *rs = &raid_softc[raidID];
@@ -880,7 +878,8 @@
 			goto done;
 		}
 	}
-	s = splbio();
+
+	mutex_enter(&raidPtr->iodone_lock);
 
 	bp->b_resid = 0;
 
@@ -888,9 +887,9 @@
 	bufq_put(rs->buf_queue, bp);
 
 	/* scheduled the IO to happen at the next convenient time */
-	wakeup(&(raidPtrs[raidID]->iodone));
+	cv_signal(&raidPtr->iodone_cv);
+	mutex_exit(&raidPtr->iodone_lock);
 
-	splx(s);
 	return;
 
 done:
@@ -2160,14 +2159,15 @@
 {
 	RF_DiskQueueData_t *req = NULL;
 	RF_DiskQueue_t *queue;
-	int s;
 
-	s = splbio();
 	db1_printf(("recovering the request queue:\n"));
+
 	req = bp->b_private;
 
 	queue = (RF_DiskQueue_t *) req->queue;
 
+	mutex_enter(&queue->raidPtr->iodone_lock);
+
 #if RF_ACC_TRACE > 0
 	if (req->tracerec) {
 		RF_ETIMER_STOP(req->tracerec->timer);
@@ -2209,24 +2209,18 @@
 	}
 
 	/* Fill in the error value */
-
 	req->error = bp->b_error;
 
-	simple_lock(&queue->raidPtr->iodone_lock);
-
 	/* Drop this one on the "finished" queue... */
 	TAILQ_INSERT_TAIL(&(queue->raidPtr->iodone), req, iodone_entries);
 
 	/* Let the raidio thread know there is work to be done. */
-	wakeup(&(queue->raidPtr->iodone));
+	cv_signal(&queue->raidPtr->iodone_cv);
 
-	simple_unlock(&queue->raidPtr->iodone_lock);
-
-	splx(s);
+	mutex_exit(&queue->raidPtr->iodone_lock);
 }
 
 
-
 /*
  * initialize a buf structure for doing an I/O in the kernel.
  */

Index: src/sys/dev/raidframe/rf_paritymap.c
diff -u src/sys/dev/raidframe/rf_paritymap.c:1.6 src/sys/dev/raidframe/rf_paritymap.c:1.7
--- src/sys/dev/raidframe/rf_paritymap.c:1.6	Tue Mar  1 22:51:14 2011
+++ src/sys/dev/raidframe/rf_paritymap.c	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_paritymap.c,v 1.6 2011/03/01 22:51:14 riz Exp $ */
+/* $NetBSD: rf_paritymap.c,v 1.7 2011/04/23 06:29:05 mrg Exp $ */
 
 /*-
  * Copyright (c) 2009 Jed Davis.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_paritymap.c,v 1.6 2011/03/01 22:51:14 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_paritymap.c,v 1.7 2011/04/23 06:29:05 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -259,7 +259,10 @@
 	mutex_enter(&pm->lk_flags);
 	pm->flags |= TICKED;
 	mutex_exit(&pm->lk_flags);
-	wakeup(&(pm->raid->iodone)); /* XXX */
+
+	mutex_enter(&pm->raid->iodone_lock);
+	cv_signal(&pm->raid->iodone_cv); /* XXX */
+	mutex_exit(&pm->raid->iodone_lock);
 }
 
 /*
@@ -582,10 +585,10 @@
 	if (raidPtr->parity_map == NULL)
 		return;
 
-	simple_lock(&(raidPtr->iodone_lock));
+	mutex_enter(&raidPtr->iodone_lock);
 	struct rf_paritymap *pm = raidPtr->parity_map;
 	raidPtr->parity_map = NULL;
-	simple_unlock(&(raidPtr->iodone_lock));
+	mutex_exit(&raidPtr->iodone_lock);
 	/* XXXjld is that enough locking?  Or too much? */
 	rf_paritymap_destroy(pm, 0);
 	kmem_free(pm, sizeof(*pm));

Index: src/sys/dev/raidframe/rf_raid.h
diff -u src/sys/dev/raidframe/rf_raid.h:1.38 src/sys/dev/raidframe/rf_raid.h:1.39
--- src/sys/dev/raidframe/rf_raid.h:1.38	Tue Nov 17 18:54:26 2009
+++ src/sys/dev/raidframe/rf_raid.h	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_raid.h,v 1.38 2009/11/17 18:54:26 jld Exp $	*/
+/*	$NetBSD: rf_raid.h,v 1.39 2011/04/23 06:29:05 mrg Exp $	*/
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -161,8 +161,9 @@
 	   a kernel thread deal with calling rf_DiskIOComplete and any
 	   callback functions. */
 	TAILQ_HEAD(iodone_q,RF_DiskQueueData_s) iodone;
-	/* and a lock to protect it */
-	struct simplelock iodone_lock;
+	/* and a lock/cv to protect it */
+	kmutex_t iodone_lock;
+	kcondvar_t iodone_cv;
 
 
 	RF_VoidPointerListElem_t *iobuf;       /* I/O buffer free list */

Index: src/sys/dev/raidframe/rf_states.c
diff -u src/sys/dev/raidframe/rf_states.c:1.44 src/sys/dev/raidframe/rf_states.c:1.45
--- src/sys/dev/raidframe/rf_states.c:1.44	Tue Nov 17 18:54:26 2009
+++ src/sys/dev/raidframe/rf_states.c	Sat Apr 23 06:29:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_states.c,v 1.44 2009/11/17 18:54:26 jld Exp $	*/
+/*	$NetBSD: rf_states.c,v 1.45 2011/04/23 06:29:05 mrg Exp $	*/
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_states.c,v 1.44 2009/11/17 18:54:26 jld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_states.c,v 1.45 2011/04/23 06:29:05 mrg Exp $");
 
 #include <sys/errno.h>
 
@@ -236,7 +236,9 @@
 	((RF_Raid_t *) desc->raidPtr)->openings++;
 	RF_UNLOCK_MUTEX(((RF_Raid_t *) desc->raidPtr)->mutex);
 
-	wakeup(&(desc->raidPtr->iodone));
+	mutex_enter(&desc->raidPtr->iodone_lock);
+	cv_signal(&desc->raidPtr->iodone_cv);
+	mutex_exit(&desc->raidPtr->iodone_lock);
 
 	/*
 	 * The parity_map hook has to go here, because the iodone

Reply via email to