From: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: Anthony Liguori
<aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Subject: [PATCH 3/3][QEMU] Support TX mitigation in QEMU's virtio_net device
Date: Mon, 7 Jan 2008 15:41:30 -0600 [thread overview]
Message-ID: <1199742091954-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1199742091998-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
This patch adds support for TX mitigation in QEMU using the new NOTIFY_ON_FULL
virtio ring flag.
Signed-off-by: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 3940743..5fd4114 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 dee97ba..21b96a3 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
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
next prev parent reply other threads:[~2008-01-07 21:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-07 21:41 [PATCH 1/3] Remove the TX timer from virtio_net Anthony Liguori
[not found] ` <11997420901032-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-07 21:41 ` [PATCH 2/3] Add support for VRING_USED_F_NOTIFY_ON_FULL Anthony Liguori
[not found] ` <1199742091998-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-07 21:41 ` Anthony Liguori [this message]
[not found] ` <1199742091954-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-08 13:53 ` [PATCH 3/3][QEMU] Support TX mitigation in QEMU's virtio_net device Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1199742091954-git-send-email-aliguori@us.ibm.com \
--to=aliguori-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox