Skip to contentSkip to conversation

Net patches

GIT PULL New Stefan Hajnoczi 1 participant 4 messages Aug 10, 2012 Networking

lore
Share & tools
lore
#0 lore raw

Paolo's fixes to resume rx when buffers have been replenished on e1000 and xen_nic. virtio-net does not have this bug.

The following changes since commit 3d1d9652978ac5a32a0beb4bdf6065ca39440d89:

handle device help before accelerator set up (2012-08-09 19:53:01 +0000)

are available in the git repository at:

git://github.com/stefanha/qemu.git net

for you to fetch changes up to 4247561bbeacb5ece8b90d0d2439efefc0e7283a:

xen: flush queue when getting an event (2012-08-10 11:43:54 +0100)

----------------------------------------------------------------
Paolo Bonzini (3):
net: notify iothread after flushing queue
e1000: flush queue whenever can_receive can go from false to true
xen: flush queue when getting an event

 hw/e1000.c      |    4 ++++
 hw/virtio-net.c |    4 ----
 hw/xen_nic.c    |    1 +
 net.c           |    7 ++++++-
 net/queue.c     |    5 +++--
 net/queue.h     |    2 +-
 6 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 net: notify iothread after flushing queue

From: Paolo Bonzini <[email protected]>

virtio-net has code to flush the queue and notify the iothread whenever new receive buffers are added by the guest. That is fine, and indeed we need to do the same in all other drivers. However, notifying the iothread should be work for the network subsystem. And since we are at it we can add a little smartness:
if some of the queued packets already could not be delivered, there is no need to notify the iothread.

---
 hw/virtio-net.c |    4 ----
 net.c           |    7 ++++++-
 net/queue.c     |    5 +++--
 net/queue.h     |    2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)
hw/virtio-net.c +0 -4
index b1998b2..6490743 100644
@@ -447,10 +447,6 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
     VirtIONet *n = to_virtio_net(vdev);
 
     qemu_flush_queued_packets(&n->nic->nc);
-
-    /* We now have RX buffers, signal to the IO thread to break out of the
-     * select to re-poll the tap file descriptor */
-    qemu_notify_event();
 }
 
 static int virtio_net_can_receive(NetClientState *nc)
net.c +6 -1
index 60043dd..76a8336 100644
@@ -357,7 +357,12 @@ void qemu_flush_queued_packets(NetClientState *nc)
 {
     nc->receive_disabled = 0;
 
-    qemu_net_queue_flush(nc->send_queue);
+    if (qemu_net_queue_flush(nc->send_queue)) {
+        /* We emptied the queue successfully, signal to the IO thread to repoll
+         * the file descriptor (for tap, for example).
+         */
+        qemu_notify_event();
+    }
 }
 
 static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
net/queue.c +3 -2
index e8030aa..6e64091 100644
@@ -228,7 +228,7 @@ void qemu_net_queue_purge(NetQueue *queue, NetClientState *from)
     }
 }
 
-void qemu_net_queue_flush(NetQueue *queue)
+bool qemu_net_queue_flush(NetQueue *queue)
 {
     while (!QTAILQ_EMPTY(&queue->packets)) {
         NetPacket *packet;
@@ -244,7 +244,7 @@ void qemu_net_queue_flush(NetQueue *queue)
                                      packet->size);
         if (ret == 0) {
             QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
-            break;
+            return false;
         }
 
         if (packet->sent_cb) {
@@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
 
         g_free(packet);
     }
+    return true;
 }
net/queue.h +1 -1
index 9d44a9b..fc02b33 100644
@@ -53,6 +53,6 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue,
                                 NetPacketSent *sent_cb);
 
 void qemu_net_queue_purge(NetQueue *queue, NetClientState *from);
-void qemu_net_queue_flush(NetQueue *queue);
+bool qemu_net_queue_flush(NetQueue *queue);
 
 #endif /* QEMU_NET_QUEUE_H */
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 e1000: flush queue whenever can_receive can go from false to true

In reply to Stefan Hajnoczi

From: Paolo Bonzini <[email protected]>

When the guests replenish the receive ring buffer, the network device should flush its queue of pending packets. This is done with qemu_flush_queued_packets.

e1000's can_receive can go from false to true when RCTL or RDT are modified.

---
 hw/e1000.c |    4 ++++
 1 file changed, 4 insertions(+)
hw/e1000.c +4 -0
index ae8a6c5..ec3a7c4 100644
@@ -295,6 +295,7 @@ set_rx_control(E1000State *s, int index, uint32_t val)
     s->rxbuf_min_shift = ((val / E1000_RCTL_RDMTS_QUAT) & 3) + 1;
     DBGOUT(RX, "RCTL: %d, mac_reg[RCTL] = 0x%x\n", s->mac_reg[RDT],
            s->mac_reg[RCTL]);
+    qemu_flush_queued_packets(&s->nic->nc);
 }
 
 static void
@@ -926,6 +927,9 @@ set_rdt(E1000State *s, int index, uint32_t val)
 {
     s->check_rxov = 0;
     s->mac_reg[index] = val & 0xffff;
+    if (e1000_has_rxbufs(s, 1)) {
+        qemu_flush_queued_packets(&s->nic->nc);
+    }
 }
 
 static void
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/3 xen: flush queue when getting an event

In reply to Stefan Hajnoczi

From: Paolo Bonzini <[email protected]>

xen does not have a register that, when written, will cause can_receive to go from false to true. However, flushing the queue can be attempted whenever the front-end raises its side of the Xen event channel. There is a single event channel for tx and rx.

Cc Stefano Stabellini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 hw/xen_nic.c |    1 +
 1 file changed, 1 insertion(+)
hw/xen_nic.c +1 -0
index 8b79bfb..cf7d559 100644
@@ -415,6 +415,7 @@ static void net_event(struct XenDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
     net_tx_packets(netdev);
+    qemu_flush_queued_packets(&netdev->nic->nc);
 }
 
 static int net_free(struct XenDevice *xendev)
Signature · 1 line
1.7.10.4