guest->host throughput with 02-flush-in-io-thread

guest->host host->guest || cpu utilization throughput vmexits || 01-tx-notifies-disabled-for-longer 02-flush-in-io-thread 03-catch-more-io 04-no-tx-timer 05-drop-mutex

From: Mark McLoughlin 
Subject: [PATCH] kvm: qemu: virtio_net: don't flush the tx queue from the vcpu thread

If we have already set up a tx timer and disabled notifies
but we still get a notify, the queue must be full and we
should flush ASAP.

Signal a flush from the I/O thread using a bottom half so
that we don't pause the guest by flushing in the vcpu thread.

Signed-off-by: Mark McLoughlin 
---
 qemu/hw/virtio-net.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index e816041..2d5f712 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -70,6 +70,8 @@ typedef struct VirtIONet
     VLANClientState *vc;
     QEMUTimer *tx_timer;
     int tx_timer_active;
+    QEMUBH *tx_bh;
+    int tx_bh_scheduled;
 } VirtIONet;
 
 /* TODO
@@ -268,10 +270,14 @@ static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIONet *n = to_virtio_net(vdev);
 
+    if (n->tx_bh_scheduled)
+	return;
+
     if (n->tx_timer_active) {
 	qemu_del_timer(n->tx_timer);
 	n->tx_timer_active = 0;
-	virtio_net_flush_tx(n, n->tx_vq, 1);
+	qemu_bh_schedule(n->tx_bh);
+	n->tx_bh_scheduled = 1;
     } else {
 	qemu_mod_timer(n->tx_timer,
 		       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
@@ -289,6 +295,15 @@ static void virtio_net_tx_timer(void *opaque)
     virtio_net_flush_tx(n, n->tx_vq, 1);
 }
 
+static void virtio_net_tx_bh(void *opaque)
+{
+    VirtIONet *n = opaque;
+
+    n->tx_bh_scheduled = 0;
+
+    virtio_net_flush_tx(n, n->tx_vq, 1);
+}
+
 static void virtio_net_save(QEMUFile *f, void *opaque)
 {
     VirtIONet *n = opaque;
@@ -325,6 +340,7 @@ static int virtio_net_uninit(PCIDevice *dev)
 
     qemu_del_timer(n->tx_timer);
     qemu_free_timer(n->tx_timer);
+    qemu_bh_delete(n->tx_bh);
 
     return 0;
 }
@@ -352,6 +368,8 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
 
     n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
     n->tx_timer_active = 0;
+    n->tx_bh = qemu_bh_new(virtio_net_tx_bh, n);
+    n->tx_bh_scheduled = 0;
 
     n->vdev.pci_dev.unregister = virtio_net_uninit;
 
-- 
1.6.0.1

If you're interested, the nasty scripts I used to generate these are here