[Midnightbsd-cvs] src [9066] trunk/sys: add dev_strategy_csw to avoid extra lock/unlock calls

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Oct 1 06:13:08 EDT 2016


Revision: 9066
          http://svnweb.midnightbsd.org/src/?rev=9066
Author:   laffer1
Date:     2016-10-01 06:13:08 -0400 (Sat, 01 Oct 2016)
Log Message:
-----------
add dev_strategy_csw to avoid extra lock/unlock calls

Modified Paths:
--------------
    trunk/sys/kern/kern_physio.c
    trunk/sys/kern/vfs_bio.c
    trunk/sys/sys/conf.h

Modified: trunk/sys/kern/kern_physio.c
===================================================================
--- trunk/sys/kern/kern_physio.c	2016-10-01 10:12:04 UTC (rev 9065)
+++ trunk/sys/kern/kern_physio.c	2016-10-01 10:13:08 UTC (rev 9066)
@@ -34,11 +34,11 @@
 int
 physio(struct cdev *dev, struct uio *uio, int ioflag)
 {
-	int i;
-	int error;
+	struct buf *bp;
+	struct cdevsw *csw;
 	caddr_t sa;
 	u_int iolen;
-	struct buf *bp;
+	int error, i;
 
 	/* Keep the process UPAGES from being swapped. XXX: why ? */
 	PHOLD(curproc);
@@ -90,14 +90,14 @@
 			bp->b_bufsize = bp->b_bcount;
 
 			bp->b_blkno = btodb(bp->b_offset);
-
-			if (uio->uio_segflg == UIO_USERSPACE)
+			csw = dev->si_devsw;
+			if (uio->uio_segflg == UIO_USERSPACE) {
 				if (vmapbuf(bp) < 0) {
 					error = EFAULT;
 					goto doerror;
 				}
-
-			dev_strategy(dev, bp);
+			}
+			dev_strategy_csw(dev, csw, bp);
 			if (uio->uio_rw == UIO_READ)
 				bwait(bp, PRIBIO, "physrd");
 			else

Modified: trunk/sys/kern/vfs_bio.c
===================================================================
--- trunk/sys/kern/vfs_bio.c	2016-10-01 10:12:04 UTC (rev 9065)
+++ trunk/sys/kern/vfs_bio.c	2016-10-01 10:13:08 UTC (rev 9066)
@@ -3275,11 +3275,34 @@
 dev_strategy(struct cdev *dev, struct buf *bp)
 {
 	struct cdevsw *csw;
-	struct bio *bip;
 	int ref;
 
-	if ((!bp->b_iocmd) || (bp->b_iocmd & (bp->b_iocmd - 1)))
-		panic("b_iocmd botch");
+	KASSERT(dev->si_refcount > 0,
+	    ("dev_strategy on un-referenced struct cdev *(%s) %p",
+	    devtoname(dev), dev));
+
+	csw = dev_refthread(dev, &ref);
+	dev_strategy_csw(dev, csw, bp);
+	dev_relthread(dev, ref);
+}
+
+void
+dev_strategy_csw(struct cdev *dev, struct cdevsw *csw, struct buf *bp)
+{
+	struct bio *bip;
+
+	KASSERT(bp->b_iocmd == BIO_READ || bp->b_iocmd == BIO_WRITE,
+	    ("b_iocmd botch"));
+	KASSERT(((dev->si_flags & SI_ETERNAL) != 0 && csw != NULL) ||
+	    dev->si_threadcount > 0,
+	    ("dev_strategy_csw threadcount cdev *(%s) %p", devtoname(dev),
+	    dev));
+	if (csw == NULL) {
+		bp->b_error = ENXIO;
+		bp->b_ioflags = BIO_ERROR;
+		bufdone(bp);
+		return;
+	}
 	for (;;) {
 		bip = g_new_bio();
 		if (bip != NULL)
@@ -3295,19 +3318,7 @@
 	bip->bio_done = bufdonebio;
 	bip->bio_caller2 = bp;
 	bip->bio_dev = dev;
-	KASSERT(dev->si_refcount > 0,
-	    ("dev_strategy on un-referenced struct cdev *(%s)",
-	    devtoname(dev)));
-	csw = dev_refthread(dev, &ref);
-	if (csw == NULL) {
-		g_destroy_bio(bip);
-		bp->b_error = ENXIO;
-		bp->b_ioflags = BIO_ERROR;
-		bufdone(bp);
-		return;
-	}
 	(*csw->d_strategy)(bip);
-	dev_relthread(dev, ref);
 }
 
 /*

Modified: trunk/sys/sys/conf.h
===================================================================
--- trunk/sys/sys/conf.h	2016-10-01 10:12:04 UTC (rev 9065)
+++ trunk/sys/sys/conf.h	2016-10-01 10:13:08 UTC (rev 9066)
@@ -258,6 +258,7 @@
 void	dev_refl(struct cdev *dev);
 void	dev_rel(struct cdev *dev);
 void	dev_strategy(struct cdev *dev, struct buf *bp);
+void	dev_strategy_csw(struct cdev *dev, struct cdevsw *csw, struct buf *bp);
 struct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid,
 		int _perms, const char *_fmt, ...) __printflike(6, 7);
 struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit,



More information about the Midnightbsd-cvs mailing list