Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178341785
D60617.1796531596.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D60617.1796531596.diff
View Options
diff --git a/sys/dev/virtio/console/virtio_console.c b/sys/dev/virtio/console/virtio_console.c
--- a/sys/dev/virtio/console/virtio_console.c
+++ b/sys/dev/virtio/console/virtio_console.c
@@ -60,6 +60,7 @@
#define VTCON_BULK_BUFSZ 128
#define VTCON_CTRL_BUFSZ 128
#define VTCON_TX_TIMEOUT 100000 /* microseconds */
+#define VTCON_TX_NBUFS 2
/*
* The buffers cannot cross more than one page boundary due to the
@@ -69,6 +70,7 @@
CTASSERT(VTCON_CTRL_BUFSZ <= PAGE_SIZE);
CTASSERT(sizeof(struct virtio_console_config) <= VTCON_CTRL_BUFSZ);
+CTASSERT(VTCON_TX_NBUFS <= sizeof(u_int) * NBBY);
struct vtcon_softc;
struct vtcon_softc_port;
@@ -101,9 +103,9 @@
struct virtqueue *vcsp_outvq;
struct mtx vcsp_mtx;
int vcsp_flags;
-#define VTCON_SCPORT_FLAG_TXBUSY 0x01
-#define VTCON_SCPORT_FLAG_TXSTOP 0x02
- char vcsp_txbuf[VTCON_BULK_BUFSZ];
+#define VTCON_SCPORT_FLAG_TXSTOP 0x01
+ u_int vcsp_txbusy;
+ char vcsp_txbuf[VTCON_TX_NBUFS][VTCON_BULK_BUFSZ];
};
#define VTCON_SCPORT_LOCK(_scport) mtx_lock_spin(&(_scport)->vcsp_mtx)
@@ -672,14 +674,23 @@
virtio_stop(sc->vtcon_dev);
}
+/* Returns true once the host holds no transmit buffer. */
static bool
vtcon_scport_tx_reclaim(struct vtcon_softc_port *scport)
{
- if ((scport->vcsp_flags & VTCON_SCPORT_FLAG_TXBUSY) != 0 &&
- virtqueue_dequeue(scport->vcsp_outvq, NULL) != NULL)
- scport->vcsp_flags &= ~VTCON_SCPORT_FLAG_TXBUSY;
+ char *buf;
+ u_int i;
+
+ while ((buf = virtqueue_dequeue(scport->vcsp_outvq, NULL)) != NULL) {
+ for (i = 0; i < VTCON_TX_NBUFS; i++)
+ if (buf == scport->vcsp_txbuf[i])
+ break;
+ KASSERT(i < VTCON_TX_NBUFS,
+ ("%s: unknown transmit buffer %p", __func__, buf));
+ scport->vcsp_txbusy &= ~(1u << i);
+ }
- return ((scport->vcsp_flags & VTCON_SCPORT_FLAG_TXBUSY) == 0);
+ return (scport->vcsp_txbusy == 0);
}
static bool
@@ -702,31 +713,39 @@
struct sglist_seg segs[2];
struct sglist sg;
struct virtqueue *vq;
+ char *txbuf;
+ u_int i;
int error;
mtx_assert(&scport->vcsp_mtx, MA_OWNED);
- KASSERT(len > 0 && len <= (int)sizeof(scport->vcsp_txbuf),
+ KASSERT(len > 0 && len <= (int)sizeof(scport->vcsp_txbuf[0]),
("%s: bad length %d", __func__, len));
vq = scport->vcsp_outvq;
if (scport->vcsp_flags & VTCON_SCPORT_FLAG_TXSTOP)
return (ENXIO);
- if (!vtcon_scport_tx_reclaim(scport))
+
+ (void)vtcon_scport_tx_reclaim(scport);
+ for (i = 0; i < VTCON_TX_NBUFS; i++)
+ if ((scport->vcsp_txbusy & (1u << i)) == 0)
+ break;
+ if (i == VTCON_TX_NBUFS)
return (EBUSY);
- memcpy(scport->vcsp_txbuf, buf, len);
+ txbuf = scport->vcsp_txbuf[i];
+ memcpy(txbuf, buf, len);
sglist_init(&sg, 2, segs);
- error = sglist_append(&sg, scport->vcsp_txbuf, len);
+ error = sglist_append(&sg, txbuf, len);
KASSERT(error == 0, ("%s: error %d adding buffer to sglist",
__func__, error));
- error = virtqueue_enqueue(vq, scport->vcsp_txbuf, &sg, sg.sg_nseg, 0);
+ error = virtqueue_enqueue(vq, txbuf, &sg, sg.sg_nseg, 0);
if (error)
- return (error);
+ return (scport->vcsp_txbusy != 0 ? EBUSY : error);
- scport->vcsp_flags |= VTCON_SCPORT_FLAG_TXBUSY;
+ scport->vcsp_txbusy |= 1u << i;
virtqueue_notify(vq);
return (0);
@@ -1537,9 +1556,9 @@
scport = port->vtcport_scport;
/*
- * Wait for the host to finish with the previous buffer with the spin
- * mutex dropped. A host that never completes it stalls the writer,
- * but only until the device is stopped.
+ * Wait for the host to return a transmit buffer with the spin mutex
+ * dropped. A host that never returns one stalls the writer, but only
+ * until the device is stopped.
*/
for (;;) {
VTCON_SCPORT_LOCK(scport);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 6, 4:33 AM (15 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40736110
Default Alt Text
D60617.1796531596.diff (3 KB)
Attached To
Mode
D60617: virtio_console: Add a second transmit buffer
Attached
Detach File
Event Timeline