Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Oct 2012 00:41:31 +0000 (UTC)
From:      Jim Harris <jimharris@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241662 - head/sys/dev/nvme
Message-ID:  <201210180041.q9I0fV2w001416@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jimharris
Date: Thu Oct 18 00:41:31 2012
New Revision: 241662
URL: http://svn.freebsd.org/changeset/base/241662

Log:
  Simplify how the qpair lock is acquired and released.
  
  Sponsored by:	Intel

Modified:
  head/sys/dev/nvme/nvme_ctrlr.c
  head/sys/dev/nvme/nvme_qpair.c

Modified: head/sys/dev/nvme/nvme_ctrlr.c
==============================================================================
--- head/sys/dev/nvme/nvme_ctrlr.c	Thu Oct 18 00:40:40 2012	(r241661)
+++ head/sys/dev/nvme/nvme_ctrlr.c	Thu Oct 18 00:41:31 2012	(r241662)
@@ -802,6 +802,8 @@ nvme_ctrlr_submit_admin_request(struct n
 
 	qpair = &ctrlr->adminq;
 
+	mtx_lock(&qpair->lock);
+
 	tr = nvme_qpair_allocate_tracker(qpair);
 
 	tr->req = req;
@@ -814,6 +816,8 @@ nvme_ctrlr_submit_admin_request(struct n
 			panic("bus_dmamap_load returned non-zero!\n");
 	} else
 		nvme_qpair_submit_cmd(tr->qpair, tr);
+
+	mtx_unlock(&qpair->lock);
 }
 
 void
@@ -829,6 +833,8 @@ nvme_ctrlr_submit_io_request(struct nvme
 	else
 		qpair = &ctrlr->ioq[0];
 
+	mtx_lock(&qpair->lock);
+
 	tr = nvme_qpair_allocate_tracker(qpair);
 
 	tr->req = req;
@@ -850,4 +856,6 @@ nvme_ctrlr_submit_io_request(struct nvme
 		if (err != 0)
 			panic("bus_dmamap_load returned non-zero!\n");
 	}
+
+	mtx_unlock(&qpair->lock);
 }

Modified: head/sys/dev/nvme/nvme_qpair.c
==============================================================================
--- head/sys/dev/nvme/nvme_qpair.c	Thu Oct 18 00:40:40 2012	(r241661)
+++ head/sys/dev/nvme/nvme_qpair.c	Thu Oct 18 00:41:31 2012	(r241662)
@@ -79,8 +79,6 @@ nvme_qpair_allocate_tracker(struct nvme_
 {
 	struct nvme_tracker	*tr;
 
-	mtx_lock(&qpair->lock);
-
 	tr = SLIST_FIRST(&qpair->free_tr);
 	if (tr == NULL) {
 		/* 
@@ -89,7 +87,6 @@ nvme_qpair_allocate_tracker(struct nvme_
 		 *  into the qpair's active tracker array.
 		 */
 		if (qpair->num_tr == qpair->num_entries) {
-			mtx_unlock(&qpair->lock);
 			return (NULL);
 		}
 
@@ -97,7 +94,6 @@ nvme_qpair_allocate_tracker(struct nvme_
 		    M_ZERO | M_NOWAIT);
 
 		if (tr == NULL) {
-			mtx_unlock(&qpair->lock);
 			return (NULL);
 		}
 
@@ -160,7 +156,6 @@ nvme_qpair_process_completions(struct nv
 		callout_stop(&tr->timer);
 
 		if (retry)
-			/* nvme_qpair_submit_cmd() will release the lock. */
 			nvme_qpair_submit_cmd(qpair, tr);
 		else {
 			if (req->payload_size > 0 || req->uio != NULL)
@@ -169,10 +164,10 @@ nvme_qpair_process_completions(struct nv
 
 			nvme_free_request(req);
 			SLIST_INSERT_HEAD(&qpair->free_tr, tr, slist);
-
-			mtx_unlock(&qpair->lock);
 		}
 
+		mtx_unlock(&qpair->lock);
+
 		if (++qpair->cq_head == qpair->num_entries) {
 			qpair->cq_head = 0;
 			qpair->phase = !qpair->phase;
@@ -410,6 +405,4 @@ nvme_qpair_submit_cmd(struct nvme_qpair 
 	    qpair->sq_tail);
 
 	qpair->num_cmds++;
-
-	mtx_unlock(&qpair->lock);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210180041.q9I0fV2w001416>