socsvn commit: r257376 - soc2013/zcore/head/usr.sbin/bhyve

zcore at FreeBSD.org zcore at FreeBSD.org
Sun Sep 15 14:30:24 UTC 2013


Author: zcore
Date: Sun Sep 15 14:30:23 2013
New Revision: 257376
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257376

Log:
  simplify queue handling
  
  The max tag number is 32 and the blockif queue size is also 32, so
  the queue won't be full.

Modified:
  soc2013/zcore/head/usr.sbin/bhyve/block_if.c
  soc2013/zcore/head/usr.sbin/bhyve/block_if.h
  soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c

Modified: soc2013/zcore/head/usr.sbin/bhyve/block_if.c
==============================================================================
--- soc2013/zcore/head/usr.sbin/bhyve/block_if.c	Sun Sep 15 14:07:16 2013	(r257375)
+++ soc2013/zcore/head/usr.sbin/bhyve/block_if.c	Sun Sep 15 14:30:23 2013	(r257376)
@@ -54,6 +54,7 @@
 enum blockop {
 	BOP_READ,
 	BOP_WRITE,
+	BOP_FLUSH,
 	BOP_CANCEL
 };
 
@@ -132,6 +133,10 @@
 			     br->br_offset) < 0)
 			err = errno;
 		break;
+	case BOP_FLUSH:
+		if (fsync(bc->bc_fd) < 0)
+			err = errno;
+		break;
 	case BOP_CANCEL:
 		err = EINTR;
 		break;
@@ -299,6 +304,14 @@
 }
 
 int
+blockif_flush(struct blockif_ctxt *bc)
+{
+
+	assert(bc->bc_magic == BLOCKIF_SIG);
+	return (blockif_request(bc, NULL, BOP_FLUSH));
+}
+
+int
 blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
 {
 
@@ -335,14 +348,6 @@
 	return (0);
 }
 
-int
-blockif_fsync(struct blockif_ctxt *bc)
-{
-
-	assert(bc->bc_magic == BLOCKIF_SIG);
-	return fsync(bc->bc_fd);
-}
-
 /*
  * Accessors
  */

Modified: soc2013/zcore/head/usr.sbin/bhyve/block_if.h
==============================================================================
--- soc2013/zcore/head/usr.sbin/bhyve/block_if.h	Sun Sep 15 14:07:16 2013	(r257375)
+++ soc2013/zcore/head/usr.sbin/bhyve/block_if.h	Sun Sep 15 14:30:23 2013	(r257376)
@@ -52,8 +52,8 @@
 int	 blockif_is_ro(struct blockif_ctxt *bc);
 int	 blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);
 int	 blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);
+int	 blockif_flush(struct blockif_ctxt *bc);
 int	 blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq);
 int	 blockif_close(struct blockif_ctxt *bc);
-int	 blockif_fsync(struct blockif_ctxt *bc);
 
 #endif /* _BLOCK_IF_H_ */

Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c
==============================================================================
--- soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c	Sun Sep 15 14:07:16 2013	(r257375)
+++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c	Sun Sep 15 14:30:23 2013	(r257376)
@@ -115,10 +115,6 @@
 	int atapi;
 	int reset;
 	int mult_sectors;
-	int flush_pending;
-	uint32_t unhandled_read;
-	uint32_t unhandled_write;
-	pthread_cond_t flush_cond;
 	uint8_t xfermode;
 	uint8_t sense_key;
 	uint8_t asc;
@@ -146,7 +142,6 @@
 	 */
 	struct ahci_ioreq *ioreq;
 	int ioqsz;
-	int iofree;
 	STAILQ_HEAD(ahci_fhead, ahci_ioreq) iofhd;
 };
 
@@ -392,14 +387,6 @@
 			cfis[2] == ATA_WRITE_FPDMA_QUEUED)
 		readop = 0;
 
-	if (!p->iofree) {
-		if (readop)
-			p->unhandled_read |= (1 << slot);
-		else
-			p->unhandled_write |= (1 << slot);
-		return;
-	}
-
 	if (cfis[2] == ATA_WRITE_FPDMA_QUEUED ||
 			cfis[2] == ATA_READ_FPDMA_QUEUED) {
 		lba = ((uint64_t)cfis[10] << 40) |
@@ -437,7 +424,6 @@
 	aior = STAILQ_FIRST(&p->iofhd);
 	assert(aior != NULL);
 	STAILQ_REMOVE_HEAD(&p->iofhd, io_list);
-	p->iofree--;
 	aior->cfis = cfis;
 	aior->slot = slot;
 	aior->len = len;
@@ -464,15 +450,21 @@
 static void
 handle_flush(struct ahci_port *p, int slot, uint8_t *cfis)
 {
-	struct pci_ahci_softc *sc = p->pr_sc;
+	int err;
+	struct ahci_ioreq *aior;
 
-	if (p->unhandled_write) {
-		p->flush_pending = 1;
-		pthread_cond_wait(&p->flush_cond, &sc->mtx);
-		p->flush_pending = 0;
-	}
-	blockif_fsync(p->bctx);
-	ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
+	/*
+	 * Pull request off free list
+	 */
+	aior = STAILQ_FIRST(&p->iofhd);
+	assert(aior != NULL);
+	STAILQ_REMOVE_HEAD(&p->iofhd, io_list);
+	aior->cfis = cfis;
+	aior->slot = slot;
+	aior->len = 0;
+
+	err = blockif_flush(p->bctx);
+	assert(err == 0);
 }
 
 static inline void
@@ -836,10 +828,6 @@
 	struct ahci_prdt_entry *prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
 	struct ahci_cmd_hdr *hdr = p->cmd_lst + slot * AHCI_CL_SIZE;
 
-	if (!p->iofree) {
-		p->unhandled_read |= (1 << slot);
-		return;
-	}
 	lba = be32dec(acmd + 2);
 	if (acmd[0] == READ_10)
 		len = be16dec(acmd + 7);
@@ -858,7 +846,6 @@
 	aior = STAILQ_FIRST(&p->iofhd);
 	assert(aior != NULL);
 	STAILQ_REMOVE_HEAD(&p->iofhd, io_list);
-	p->iofree--;
 	aior->cfis = cfis;
 	aior->slot = slot;
 	aior->len = len;
@@ -1175,28 +1162,6 @@
 	 * Move the blockif request back to the free list
 	 */
 	STAILQ_INSERT_TAIL(&p->iofhd, aior, io_list);
-	p->iofree++;
-
-	/*
-	 * If the number of oustanding commands has dropped below the
-	 * threshold, see if more can be queued up
-	 */
-	if (p->ioqsz - p->iofree <= 2 && (p->cmd & AHCI_P_CMD_ST)) {
-		int i;
-		uint32_t unhandled = p->unhandled_read | p->unhandled_write;
-		for (i = 0; (i < 32) && unhandled; i++) {
-			if (!p->iofree)
-				break;
-			if (unhandled & (1 << i)) {
-				handle_slot(p, i);
-				unhandled &= ~(1 << i);
-			}
-		}
-		p->unhandled_read &= unhandled;
-		p->unhandled_write &= unhandled;
-		if (!p->unhandled_write && p->flush_pending)
-			pthread_cond_signal(&p->flush_cond);
-	}
 
 	pthread_mutex_unlock(&sc->mtx);
 	dprintf("%s exit\n", __func__);
@@ -1239,25 +1204,6 @@
 	 * Move the blockif request back to the free list
 	 */
 	STAILQ_INSERT_TAIL(&p->iofhd, aior, io_list);
-	p->iofree++;
-
-	/*
-	 * If the number of oustanding commands has dropped below the
-	 * threshold, see if more can be queued up
-	 */
-	if (p->ioqsz - p->iofree <= 2 && (p->cmd & AHCI_P_CMD_ST)) {
-		int i;
-		uint32_t unhandled = p->unhandled_read;
-		for (i = 0; (i < 32) && unhandled; i++) {
-			if (!p->iofree)
-				break;
-			if (unhandled & (1 << i)) {
-				handle_slot(p, i);
-				unhandled &= ~(1 << i);
-			}
-		}
-		p->unhandled_read &= unhandled;
-	}
 
 	pthread_mutex_unlock(&sc->mtx);
 	dprintf("%s exit\n", __func__);
@@ -1286,7 +1232,6 @@
 			vr->io_req.br_callback = atapi_ioreq_cb;
 		vr->io_req.br_param = vr;
 		STAILQ_INSERT_TAIL(&pr->iofhd, vr, io_list);
-		pr->iofree++;
 	}
 }
 
@@ -1345,7 +1290,6 @@
 
 		sc->port[i].bctx = bctxt;
 		sc->port[i].pr_sc = sc;
-		pthread_cond_init(&sc->port[i].flush_cond, NULL);
 		/*
 		 * Allocate blockif request structures and add them
 		 * to the free list


More information about the svn-soc-all mailing list