d4cdad5
From 71108acb189f5fda923013ed72270642199ab50d Mon Sep 17 00:00:00 2001
d4cdad5
From: Amit Shah <amit.shah@redhat.com>
d4cdad5
Date: Mon, 21 Mar 2011 22:06:41 +0100
d4cdad5
Subject: [PATCH 113/118] virtio-console: Enable port throttling when chardev
d4cdad5
 is slow to consume data
d4cdad5
d4cdad5
When a chardev indicates it can't accept more data, we tell the
d4cdad5
virtio-serial code to stop sending us any more data till we tell
d4cdad5
otherwise.  This helps in guests continuing to run normally while the vq
d4cdad5
keeps getting full and eventually the guest stops queueing more data.
d4cdad5
As soon as the chardev indicates it can accept more data, start pushing!
d4cdad5
d4cdad5
Signed-off-by: Amit Shah <amit.shah@redhat.com>
d4cdad5
---
d4cdad5
 hw/virtio-console.c |   11 +++++++++++
d4cdad5
 1 files changed, 11 insertions(+), 0 deletions(-)
d4cdad5
d4cdad5
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
d4cdad5
index 6d6f3ef..da68211 100644
d4cdad5
--- a/hw/virtio-console.c
d4cdad5
+++ b/hw/virtio-console.c
d4cdad5
@@ -20,6 +20,16 @@ typedef struct VirtConsole {
d4cdad5
     CharDriverState *chr;
d4cdad5
 } VirtConsole;
d4cdad5
d4cdad5
+/*
d4cdad5
+ * Callback function that's called from chardevs when backend becomes
d4cdad5
+ * writable.
d4cdad5
+ */
d4cdad5
+static void chr_write_unblocked(void *opaque)
d4cdad5
+{
d4cdad5
+    VirtConsole *vcon = opaque;
d4cdad5
+
d4cdad5
+    virtio_serial_throttle_port(&vcon->port, false);
d4cdad5
+}
d4cdad5
d4cdad5
 /* Callback function that's called when the guest sends us data */
d4cdad5
 static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
d4cdad5
@@ -99,6 +109,7 @@ static const QemuChrHandlers chr_handlers = {
d4cdad5
     .fd_can_read = chr_can_read,
d4cdad5
     .fd_read = chr_read,
d4cdad5
     .fd_event = chr_event,
d4cdad5
+    .fd_write_unblocked = chr_write_unblocked,
d4cdad5
 };
d4cdad5
d4cdad5
 static int virtconsole_initfn(VirtIOSerialPort *port)
d4cdad5
-- 
d4cdad5
1.7.7.5
d4cdad5