netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next] virtio_net: add support for Byte Queue Limits
@ 2024-05-09 11:46 Jiri Pirko
  2024-05-09 12:41 ` Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 55+ messages in thread
From: Jiri Pirko @ 2024-05-09 11:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, mst, jasowang, xuanzhuo,
	virtualization, ast, daniel, hawk, john.fastabend

From: Jiri Pirko <jiri@nvidia.com>

Add support for Byte Queue Limits (BQL).

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 drivers/net/virtio_net.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 218a446c4c27..c53d6dc6d332 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -84,7 +84,9 @@ struct virtnet_stat_desc {
 
 struct virtnet_sq_free_stats {
 	u64 packets;
+	u64 xdp_packets;
 	u64 bytes;
+	u64 xdp_bytes;
 };
 
 struct virtnet_sq_stats {
@@ -512,19 +514,19 @@ static void __free_old_xmit(struct send_queue *sq, bool in_napi,
 	void *ptr;
 
 	while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
-		++stats->packets;
-
 		if (!is_xdp_frame(ptr)) {
 			struct sk_buff *skb = ptr;
 
 			pr_debug("Sent skb %p\n", skb);
 
+			stats->packets++;
 			stats->bytes += skb->len;
 			napi_consume_skb(skb, in_napi);
 		} else {
 			struct xdp_frame *frame = ptr_to_xdp(ptr);
 
-			stats->bytes += xdp_get_frame_len(frame);
+			stats->xdp_packets++;
+			stats->xdp_bytes += xdp_get_frame_len(frame);
 			xdp_return_frame(frame);
 		}
 	}
@@ -965,7 +967,8 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf)
 	virtnet_rq_free_buf(vi, rq, buf);
 }
 
-static void free_old_xmit(struct send_queue *sq, bool in_napi)
+static void free_old_xmit(struct send_queue *sq, struct netdev_queue *txq,
+			  bool in_napi)
 {
 	struct virtnet_sq_free_stats stats = {0};
 
@@ -974,9 +977,11 @@ static void free_old_xmit(struct send_queue *sq, bool in_napi)
 	/* Avoid overhead when no packets have been processed
 	 * happens when called speculatively from start_xmit.
 	 */
-	if (!stats.packets)
+	if (!stats.packets && !stats.xdp_packets)
 		return;
 
+	netdev_tx_completed_queue(txq, stats.packets, stats.bytes);
+
 	u64_stats_update_begin(&sq->stats.syncp);
 	u64_stats_add(&sq->stats.bytes, stats.bytes);
 	u64_stats_add(&sq->stats.packets, stats.packets);
@@ -1013,13 +1018,15 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
 	 * early means 16 slots are typically wasted.
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
-		netif_stop_subqueue(dev, qnum);
+		struct netdev_queue *txq = netdev_get_tx_queue(dev, qnum);
+
+		netif_tx_stop_queue(txq);
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq->vq);
 		} else if (unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
 			/* More just got used, free them then recheck. */
-			free_old_xmit(sq, false);
+			free_old_xmit(sq, txq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
 				virtqueue_disable_cb(sq->vq);
@@ -2319,7 +2326,7 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
 
 		do {
 			virtqueue_disable_cb(sq->vq);
-			free_old_xmit(sq, true);
+			free_old_xmit(sq, txq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
 		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
@@ -2471,7 +2478,7 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
 	txq = netdev_get_tx_queue(vi->dev, index);
 	__netif_tx_lock(txq, raw_smp_processor_id());
 	virtqueue_disable_cb(sq->vq);
-	free_old_xmit(sq, true);
+	free_old_xmit(sq, txq, true);
 
 	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
 		netif_tx_wake_queue(txq);
@@ -2553,7 +2560,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct send_queue *sq = &vi->sq[qnum];
 	int err;
 	struct netdev_queue *txq = netdev_get_tx_queue(dev, qnum);
-	bool kick = !netdev_xmit_more();
+	bool xmit_more = netdev_xmit_more();
 	bool use_napi = sq->napi.weight;
 
 	/* Free up any pending old buffers before queueing new ones. */
@@ -2561,9 +2568,9 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 		if (use_napi)
 			virtqueue_disable_cb(sq->vq);
 
-		free_old_xmit(sq, false);
+		free_old_xmit(sq, txq, false);
 
-	} while (use_napi && kick &&
+	} while (use_napi && !xmit_more &&
 	       unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
 	/* timestamp packet in software */
@@ -2592,7 +2599,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	check_sq_full_and_disable(vi, dev, sq);
 
-	if (kick || netif_xmit_stopped(txq)) {
+	if (__netdev_tx_sent_queue(txq, skb->len, xmit_more)) {
 		if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
 			u64_stats_update_begin(&sq->stats.syncp);
 			u64_stats_inc(&sq->stats.kicks);
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2024-06-18 18:23 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-09 11:46 [patch net-next] virtio_net: add support for Byte Queue Limits Jiri Pirko
2024-05-09 12:41 ` Michael S. Tsirkin
2024-05-09 13:31   ` Jiri Pirko
2024-05-09 14:28     ` Michael S. Tsirkin
2024-05-10  4:25       ` Jason Wang
2024-05-10 10:37       ` Jiri Pirko
2024-05-10 10:52         ` Michael S. Tsirkin
2024-05-10 11:11           ` Jiri Pirko
2024-05-10 11:27             ` Michael S. Tsirkin
2024-05-10 11:36               ` Jiri Pirko
2024-05-15  7:34               ` Jiri Pirko
2024-05-15  8:20                 ` Michael S. Tsirkin
2024-05-15 10:12                   ` Jiri Pirko
2024-05-15 12:54                     ` Jiri Pirko
2024-05-16  4:48                       ` Jason Wang
2024-05-16 10:54                         ` Jiri Pirko
2024-05-16 12:31                           ` Michael S. Tsirkin
2024-05-16 15:25                             ` Jiri Pirko
2024-05-16 19:04                               ` Michael S. Tsirkin
2024-05-17  7:52                                 ` Jiri Pirko
     [not found]                 ` <CAA93jw6WanAQrPAFZ1hYVTXuWDwP+4J70LnmPOD2ugNwYK6HMA@mail.gmail.com>
2024-06-06  7:30                   ` Jiri Pirko
2024-05-10  4:25 ` Jason Wang
2024-05-10  7:11 ` Heng Qi
2024-05-10 10:35   ` Jiri Pirko
2024-05-20 12:48   ` Jiri Pirko
2024-06-05 11:30     ` Jiri Pirko
2024-06-05 11:42       ` Heng Qi
2024-06-06  0:20         ` Jason Wang
2024-06-06  2:58           ` Jason Xing
2024-06-06  4:25             ` Jason Wang
2024-06-06  6:05               ` Michael S. Tsirkin
2024-06-06  7:56                 ` Jason Wang
2024-06-06 13:45                   ` Jiri Pirko
2024-06-07  6:25                     ` Jason Wang
2024-06-07  6:39                       ` Jiri Pirko
2024-06-07  6:43                         ` Michael S. Tsirkin
2024-06-07  6:47                         ` Jason Wang
2024-06-07  9:57                           ` Jiri Pirko
2024-06-07 10:23                             ` Michael S. Tsirkin
2024-06-07 11:30                               ` Jiri Pirko
2024-06-10 14:18                                 ` Michael S. Tsirkin
2024-06-17  1:44                                   ` Jason Wang
2024-06-17  9:30                                     ` Jiri Pirko
2024-06-17 16:16                                       ` Michael S. Tsirkin
2024-06-18  1:19                                         ` Jason Wang
2024-06-18  0:52                                       ` Jason Wang
2024-06-18 18:23                                         ` Michael S. Tsirkin
2024-06-17 16:18                                     ` Michael S. Tsirkin
2024-06-07 11:22                             ` Jason Xing
2024-06-06 11:42               ` Jason Xing
2024-06-06 12:00                 ` Michael S. Tsirkin
2024-06-06 13:41               ` Jiri Pirko
2024-06-07  6:22                 ` Jason Wang
2024-06-07  6:39                   ` Michael S. Tsirkin
2024-06-07  6:40                   ` Jiri Pirko

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).