diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2008-01-07 15:41:30 -0600 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-08 14:49:05 +0200 |
commit | bc7252d3a9274cd16d260236ac4bc66c2435b538 (patch) | |
tree | b67a046b78d76d3cf0de41f6197b453ddbdd0556 /qemu | |
parent | ccfd893acd133ad317c5e1501bc1b9adc343eab3 (diff) |
kvm: qemu: Support TX mitigation in qemu's virtio_net device
This patch adds support for host-side timer-based TX mitigation.
[avi: adjust to use existing notify disable, as per rusty]
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'qemu')
-rw-r--r-- | qemu/hw/virtio-net.c | 42 | ||||
-rw-r--r-- | qemu/hw/virtio.h | 1 |
2 files changed, 41 insertions, 2 deletions
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c index 39407430..9cd0789c 100644 --- a/qemu/hw/virtio-net.c +++ b/qemu/hw/virtio-net.c @@ -14,6 +14,7 @@ #include "virtio.h" #include "net.h" #include "pc.h" +#include "qemu-timer.h" /* from Linux's virtio_net.h */ @@ -28,6 +29,10 @@ #define VIRTIO_NET_F_TSO6 4 #define VIRTIO_NET_F_MAC 5 +#define USE_TX_TIMER + +#define TX_TIMER_INTERVAL (1000 / 500) + /* The config defining mac address (6 bytes) */ struct virtio_net_config { @@ -63,6 +68,8 @@ typedef struct VirtIONet int tap_fd; struct VirtIONet *next; int do_notify; + QEMUTimer *tx_timer; + int tx_timer_active; } VirtIONet; static VirtIONet *VirtIONetHead = NULL; @@ -222,10 +229,10 @@ again: } /* TX */ -static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq) +static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq) { - VirtIONet *n = to_virtio_net(vdev); VirtQueueElement elem; + int count = 0; if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) return; @@ -241,11 +248,39 @@ static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq) len += elem.out_sg[i].iov_len; } + count++; + virtqueue_push(vq, &elem, sizeof(struct virtio_net_hdr) + len); virtio_notify(&n->vdev, vq); } } +static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIONet *n = to_virtio_net(vdev); + + if (n->tx_timer_active && + (vq->vring.avail->idx - vq->last_avail_idx) == 64) { + vq->vring.used->flags &= ~VRING_USED_F_NOTIFY_ON_FULL; + qemu_del_timer(n->tx_timer); + n->tx_timer_active = 0; + virtio_net_flush_tx(n, vq); + } else { + qemu_mod_timer(n->tx_timer, qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL); + n->tx_timer_active = 1; + vq->vring.used->flags |= VRING_USED_F_NOTIFY_ON_FULL; + } +} + +static void virtio_net_tx_timer(void *opaque) +{ + VirtIONet *n = opaque; + + n->tx_vq->vring.used->flags &= ~VRING_USED_F_NOTIFY_ON_FULL; + n->tx_timer_active = 0; + virtio_net_flush_tx(n, n->tx_vq); +} + void *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) { VirtIONet *n; @@ -270,5 +305,8 @@ void *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) VirtIONetHead = n; } + n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n); + n->tx_timer_active = 0; + return &n->vdev; } diff --git a/qemu/hw/virtio.h b/qemu/hw/virtio.h index dee97ba7..21b96a39 100644 --- a/qemu/hw/virtio.h +++ b/qemu/hw/virtio.h @@ -39,6 +39,7 @@ /* This means don't notify other side when buffer added. */ #define VRING_USED_F_NO_NOTIFY 1 +#define VRING_USED_F_NOTIFY_ON_FULL 2 /* This means don't interrupt guest when buffer consumed. */ #define VRING_AVAIL_F_NO_INTERRUPT 1 |