net: add missing queue flush for e1000 and xen
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
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
@@ -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
@@ -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
@@ -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
@@ -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
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.Reported-by Luigi Rizzo <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Jan Kiszka <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- 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@@ -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@@ -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@@ -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@@ -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
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
-0if (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
PATCH 2/3 e1000: flush queue whenever can_receive can go from false to true
In reply to Paolo BonziniWhen 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
@@ -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
PATCH 3/3 xen: flush queue when getting an event
In reply to Paolo Bonzinixen 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.
--- hw/xen_nic.c | 1 +
1 file modificati, 1 inserzioni(+)
hw/xen_nic.c +1 -0
@@ -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
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_eventto force recomputation of thefd_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 whenevercan_receivecan 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
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_eventto force recomputation of thefd_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 whenevercan_receivecan go from false to true
xen: flush queue when getting an eventQuoted 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
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_eventto force recomputation of thefd_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 whenevercan_receivecan 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.