Skip to contentSkip to conversation

net: add missing queue flush for e1000 and xen

PATCH In review Paolo Bonzini 5 participants 9 messages Aug 9, 2012 – Aug 30, 2012 Networking

lore
Share & tools
lore
#0 lore raw

cover net: add missing queue flush for e1000 and xen

Luigi reminded me of these patches...

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, and patches 2+3 add the missing call to two drivers, e1000 and xen. More may come later---no time to test them now.

However, the device should not just retry delivery of packets that were already read from the tap device, it should also try to read more packets from the tap device. The latter requires a qemu_notify_event to force recomputation of the fd_sets. virtio already does this, but it is a layering violation; patch 1 moves the call from virtio to the network subsystem, so that e1000 and xen will then get it for free.

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 file modificati, 15 inserzioni(+), 8 rimozioni(-)

Signature · 1 line
1.7.11.2
#1 lore raw

PATCH 1/3 net: notify iothread after flushing queue

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 file modificati, 10 inserzioni(+), 8 rimozioni(-)

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..f3f0098 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 0;
         }
 
         if (packet->sent_cb) {
@@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
 
         g_free(packet);
     }
+    return 1;
 }
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.11.2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] net: notify iothread after flushing queue

Quoted 66 lines · Paolo Bonzini

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 file modificati, 10 inserzioni(+), 8 rimozioni(-)

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 +1 -1
index e8030aa..f3f0098 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;

net/queue.c void qemu_net_queue_flush(NetQueue *queue) · line 247

Quoted 5 lines
net/queue.c +1 -1
@@ -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 0;

return false;

net/queue.c void qemu_net_queue_flush(NetQueue *queue) · line 256

Quoted 8 lines
net/queue.c +1 -0
         }
 
         if (packet->sent_cb) {
@@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
 
         g_free(packet);
     }
+    return 1;

return true;

Quoted 18 lines
net/queue.c +0 -0
 }
net/queue.h +1 -2
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 */
--

1.7.11.2

#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] net: notify iothread after flushing queue

Quoted 12 lines · Blue Swirl

net/queue.c void qemu_net_queue_flush(NetQueue *queue) · line 247

Quoted 6 lines · Paolo Bonzini
net/queue.c +1 -1
@@ -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 0;

return false;

Quoted 2 lines
(quoted diff) +0 -0
         }
 
Quoted 8 lines

net/queue.c void qemu_net_queue_flush(NetQueue *queue) · line 256

Quoted 6 lines
net/queue.c +1 -0
         if (packet->sent_cb) {
@@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
 
         g_free(packet);
     }
+    return 1;

return true;

Will fix these up when merging. I think it's clearer to use bool too.

Stefan

#4 lore raw

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

In reply to Paolo Bonzini

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 modificati, 4 inserzioni(+)

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.11.2
#5 lore raw

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

In reply to Paolo Bonzini

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 modificati, 1 inserzioni(+)

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.11.2
#6 lore raw
In reply to Paolo Bonzini
Quoted 20 lines · Paolo Bonzini

Luigi reminded me of these patches...

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, and patches 2+3 add the missing call to two drivers, e1000 and xen. More may come later---no time to test them now.

However, the device should not just retry delivery of packets that were already read from the tap device, it should also try to read more packets from the tap device. The latter requires a qemu_notify_event to force recomputation of the fd_sets. virtio already does this, but it is a layering violation; patch 1 moves the call from virtio to the network subsystem, so that e1000 and xen will then get it for free.

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

Quoted 7 lines
 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 file modificati, 15 inserzioni(+), 8 rimozioni(-)

Looks good for QEMU 1.2. I'll give Jan and Stefano time to respond, if they want.

Stefan

#7 lore raw
Quoted 29 lines · Stefan Hajnoczi
Quoted 20 lines · Paolo Bonzini

Luigi reminded me of these patches...

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, and patches 2+3 add the missing call to two drivers, e1000 and xen. More may come later---no time to test them now.

However, the device should not just retry delivery of packets that were already read from the tap device, it should also try to read more packets from the tap device. The latter requires a qemu_notify_event to force recomputation of the fd_sets. virtio already does this, but it is a layering violation; patch 1 moves the call from virtio to the network subsystem, so that e1000 and xen will then get it for free.

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

Quoted 7 lines
 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 file modificati, 15 inserzioni(+), 8 rimozioni(-)

Quoted 2 lines

Looks good for QEMU 1.2. I'll give Jan and Stefano time to respond, if they want.

The patches are fine by me

Reviewed-by on the v1 series
#8 lore raw
In reply to Paolo Bonzini
Quoted 20 lines · Paolo Bonzini

Luigi reminded me of these patches...

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, and patches 2+3 add the missing call to two drivers, e1000 and xen. More may come later---no time to test them now.

However, the device should not just retry delivery of packets that were already read from the tap device, it should also try to read more packets from the tap device. The latter requires a qemu_notify_event to force recomputation of the fd_sets. virtio already does this, but it is a layering violation; patch 1 moves the call from virtio to the network subsystem, so that e1000 and xen will then get it for free.

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

Quoted 7 lines
  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 file modificati, 15 inserzioni(+), 8 rimozioni(-)

LGTM.

Signature · 1 line
			Amos.