From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 8/8] virtio-net: implement async packet sending
Date: Thu, 18 Jun 2009 18:21:36 +0100 [thread overview]
Message-ID: <1245345696-20915-9-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1245345696-20915-8-git-send-email-markmc@redhat.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/virtio-net.c | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index e1efbbe..4fbeaeb 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -32,6 +32,10 @@ typedef struct VirtIONet
VLANClientState *vc;
QEMUTimer *tx_timer;
int tx_timer_active;
+ struct {
+ VirtQueueElement elem;
+ ssize_t len;
+ } async_tx;
int mergeable_rx_bufs;
uint8_t promisc;
uint8_t allmulti;
@@ -483,6 +487,21 @@ static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_
return size;
}
+static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq);
+
+static void virtio_net_tx_complete(VLANClientState *vc, ssize_t len)
+{
+ VirtIONet *n = vc->opaque;
+
+ virtqueue_push(n->tx_vq, &n->async_tx.elem, n->async_tx.len);
+ virtio_notify(&n->vdev, n->tx_vq);
+
+ n->async_tx.elem.out_num = n->async_tx.len = 0;
+
+ virtio_queue_set_notification(n->tx_vq, 1);
+ virtio_net_flush_tx(n, n->tx_vq);
+}
+
/* TX */
static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
{
@@ -492,8 +511,13 @@ static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
return;
+ if (n->async_tx.elem.out_num) {
+ virtio_queue_set_notification(n->tx_vq, 0);
+ return;
+ }
+
while (virtqueue_pop(vq, &elem)) {
- ssize_t len = 0;
+ ssize_t ret, len = 0;
unsigned int out_num = elem.out_num;
struct iovec *out_sg = &elem.out_sg[0];
unsigned hdr_len;
@@ -520,7 +544,16 @@ static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
len += hdr_len;
}
- len += qemu_sendv_packet(n->vc, out_sg, out_num);
+ ret = qemu_sendv_packet_async(n->vc, out_sg, out_num,
+ virtio_net_tx_complete);
+ if (ret == 0) {
+ virtio_queue_set_notification(n->tx_vq, 0);
+ n->async_tx.elem = elem;
+ n->async_tx.len = len;
+ return;
+ }
+
+ len += ret;
virtqueue_push(vq, &elem, len);
virtio_notify(&n->vdev, vq);
@@ -663,6 +696,8 @@ static void virtio_net_cleanup(VLANClientState *vc)
{
VirtIONet *n = vc->opaque;
+ qemu_purge_queued_packets(vc);
+
unregister_savevm("virtio-net", n);
qemu_free(n->mac_table.macs);
--
1.6.0.6
prev parent reply other threads:[~2009-06-18 17:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-18 17:21 [Qemu-devel] [PATCH 0/8] TUNSETSNDBUF - pushback to help UDP tx Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 1/8] net: add qemu_purge_queued_packets() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 2/8] net: purge queued packets in tap_cleanup() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 3/8] net: add tap_read_poll() helper Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 4/8] net: handle EAGAIN from tapfd write() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 5/8] net: return TAPState from net_tap_init() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 6/8] net: add '-net tap,sndbuf=nbytes' Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 7/8] net: add packet length to NetPacketSent callback Mark McLoughlin
2009-06-18 17:21 ` Mark McLoughlin [this message]
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=1245345696-20915-9-git-send-email-markmc@redhat.com \
--to=markmc@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).