Thread (24 messages) flat view 24 messages, 6 authors, 2023-03-31

Re: [PATCH v3 2/4] virtio_net: move txq wakeups under tx q lock

From: Jason Wang <hidden>
Date: 2021-05-27 03:48:48
Also in: lkml, netdev

在 2021/5/26 下午4:24, Michael S. Tsirkin 写道:
We currently check num_free outside tx q lock
which is unsafe: new packets can arrive meanwhile
and there won't be space in the queue.
Thus a spurious queue wakeup causing overhead
and even packet drops.

Move the check under the lock to fix that.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Jason Wang <redacted>

quoted hunk ↗ jump to hunk
---
  drivers/net/virtio_net.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 12512d1002ec..c29f42d1e04f 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1434,11 +1434,12 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
  
  	if (__netif_tx_trylock(txq)) {
  		free_old_xmit_skbs(sq, true);
+
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+			netif_tx_wake_queue(txq);
+
  		__netif_tx_unlock(txq);
  	}
-
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
-		netif_tx_wake_queue(txq);
  }
  
  static int virtnet_poll(struct napi_struct *napi, int budget)
@@ -1522,6 +1523,9 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
  	virtqueue_disable_cb(sq->vq);
  	free_old_xmit_skbs(sq, true);
  
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		netif_tx_wake_queue(txq);
+
  	opaque = virtqueue_enable_cb_prepare(sq->vq);
  
  	done = napi_complete_done(napi, 0);
@@ -1542,9 +1546,6 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
  		}
  	}
  
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
-		netif_tx_wake_queue(txq);
-
  	return 0;
  }
  
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help