Skip to contentSkip to conversation

Add TX stop/wake counters

PATCH Superseded Daniel Jurgens 4 participants 14 messages May 9, 2024 – May 10, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add TX stop/wake counters

Several drivers provide TX stop and wake counters via ethtool stats. Add those to the netdev queue stats, and use them in virtio_net.

Daniel Jurgens (2):
netdev: Add queue stats for TX stop and wake
virtio_net: Add TX stopped and wake counters

 Documentation/netlink/specs/netdev.yaml | 10 +++++++++
 drivers/net/virtio_net.c                | 28 +++++++++++++++++++++++--
 include/net/netdev_queues.h             |  3 +++
 include/uapi/linux/netdev.h             |  2 ++
 net/core/netdev-genl.c                  |  4 +++-
 tools/include/uapi/linux/netdev.h       |  3 ++-
 6 files changed, 46 insertions(+), 4 deletions(-)
Signature · 1 line
2.44.0
#9 lore raw

PATCH 2/2 virtio_net: Add TX stopped and wake counters

Add a tx queue stop and wake counters, they are useful for debugging.

$ ./tools/net/ynl/cli.py --spec netlink/specs/netdev.yaml \
--dump qstats-get --json '{"scope": "queue"}'
...
 {'ifindex': 13,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 14756682850,
  'tx-packets': 226465,
  'tx-stop': 113208,
  'tx-wake': 113208},
 {'ifindex': 13,
  'queue-id': 1,
  'queue-type': 'tx',
  'tx-bytes': 18167675008,
  'tx-packets': 278660,
  'tx-stop': 8632,
  'tx-wake': 8632}]
---
 drivers/net/virtio_net.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +26 -2
index 218a446c4c27..df6121c38a1b 100644
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
 	u64_stats_t xdp_tx_drops;
 	u64_stats_t kicks;
 	u64_stats_t tx_timeouts;
+	u64_stats_t stop;
+	u64_stats_t wake;
 };
 
 struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = {
 static const struct virtnet_stat_desc virtnet_sq_stats_desc_qstat[] = {
 	VIRTNET_SQ_STAT_QSTAT("packets", packets),
 	VIRTNET_SQ_STAT_QSTAT("bytes",   bytes),
+	VIRTNET_SQ_STAT_QSTAT("stop",	 stop),
+	VIRTNET_SQ_STAT_QSTAT("wake",	 wake),
 };
 
 static const struct virtnet_stat_desc virtnet_rq_stats_desc_qstat[] = {
@@ -1014,6 +1018,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
+		u64_stats_update_begin(&sq->stats.syncp);
+		u64_stats_inc(&sq->stats.stop);
+		u64_stats_update_end(&sq->stats.syncp);
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq->vq);
@@ -1022,6 +1029,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
 			free_old_xmit(sq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
 				virtqueue_disable_cb(sq->vq);
 			}
 		}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
 			free_old_xmit(sq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
-		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+			if (netif_tx_queue_stopped(txq)) {
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
+			}
 			netif_tx_wake_queue(txq);
+		}
 
 		__netif_tx_unlock(txq);
 	}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
 	virtqueue_disable_cb(sq->vq);
 	free_old_xmit(sq, true);
 
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+		if (netif_tx_queue_stopped(txq)) {
+			u64_stats_update_begin(&sq->stats.syncp);
+			u64_stats_inc(&sq->stats.wake);
+			u64_stats_update_end(&sq->stats.syncp);
+		}
 		netif_tx_wake_queue(txq);
+	}
 
 	opaque = virtqueue_enable_cb_prepare(sq->vq);
 
@@ -4790,6 +4812,8 @@ static void virtnet_get_base_stats(struct net_device *dev,
 
 	tx->bytes = 0;
 	tx->packets = 0;
+	tx->stop = 0;
+	tx->wake = 0;
 
 	if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {
 		tx->hw_drops = 0;
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 netdev: Add queue stats for TX stop and wake

In reply to Daniel Jurgens

TX queue stop and wake are counted by some drivers. Support reporting these via netdev-genl queue stats.

---
 Documentation/netlink/specs/netdev.yaml | 10 ++++++++++
 include/net/netdev_queues.h             |  3 +++
 include/uapi/linux/netdev.h             |  2 ++
 net/core/netdev-genl.c                  |  4 +++-
 tools/include/uapi/linux/netdev.h       |  3 ++-
 5 files changed, 20 insertions(+), 2 deletions(-)
Documentation/netlink/specs/netdev.yaml +10 -0
index 2be4b3714d17..c8b976d03330 100644
@@ -439,6 +439,16 @@ attribute-sets:
           Number of the packets dropped by the device due to the transmit
           packets bitrate exceeding the device rate limit.
         type: uint
+      -
+        name: tx-stop
+        doc: |
+          Number of times the tx queue was stopped.
+        type: uint
+      -
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.
+        type: uint
 
 operations:
   list:
include/net/netdev_queues.h +3 -0
index e7b84f018cee..a8a7e48dfa6c 100644
@@ -41,6 +41,9 @@ struct netdev_queue_stats_tx {
 	u64 hw_gso_wire_bytes;
 
 	u64 hw_drop_ratelimits;
+
+	u64 stop;
+	u64 wake;
 };
 
 /**
include/uapi/linux/netdev.h +2 -0
index cf24f1d9adf8..a8188202413e 100644
@@ -165,6 +165,8 @@ enum {
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
 	NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,
+	NETDEV_A_QSTATS_TX_STOP,
+	NETDEV_A_QSTATS_TX_WAKE,
 
 	__NETDEV_A_QSTATS_MAX,
 	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
net/core/netdev-genl.c +3 -1
index 4b5054087309..1f6ae6379e0f 100644
@@ -517,7 +517,9 @@ netdev_nl_stats_write_tx(struct sk_buff *rsp, struct netdev_queue_stats_tx *tx)
 	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_BYTES, tx->hw_gso_bytes) ||
 	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS, tx->hw_gso_wire_packets) ||
 	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES, tx->hw_gso_wire_bytes) ||
-	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS, tx->hw_drop_ratelimits))
+	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS, tx->hw_drop_ratelimits) ||
+	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_STOP, tx->stop) ||
+	    netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_WAKE, tx->wake))
 		return -EMSGSIZE;
 	return 0;
 }
tools/include/uapi/linux/netdev.h +2 -1
index cf24f1d9adf8..ccf6976b1693 100644
@@ -164,7 +164,8 @@ enum {
 	NETDEV_A_QSTATS_TX_HW_GSO_BYTES,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
-	NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,
+	NETDEV_A_QSTATS_TX_STOP,
+	NETDEV_A_QSTATS_TX_WAKE,
 
 	__NETDEV_A_QSTATS_MAX,
 	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
Signature · 1 line
2.44.0
#2 lore raw

Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 21 lines · Daniel Jurgens

TX queue stop and wake are counted by some drivers. Support reporting these via netdev-genl queue stats.

---
 Documentation/netlink/specs/netdev.yaml | 10 ++++++++++
 include/net/netdev_queues.h             |  3 +++
 include/uapi/linux/netdev.h             |  2 ++
 net/core/netdev-genl.c                  |  4 +++-
 tools/include/uapi/linux/netdev.h       |  3 ++-
 5 files changed, 20 insertions(+), 2 deletions(-)
Documentation/netlink/specs/netdev.yaml +0 -0
index 2be4b3714d17..c8b976d03330 100644
@@ -439,6 +439,16 @@ attribute-sets:
           Number of the packets dropped by the device due to the transmit
           packets bitrate exceeding the device rate limit.
         type: uint

Documentation/netlink/specs/netdev.yaml attribute-sets: · line 451

Quoted 10 lines
Documentation/netlink/specs/netdev.yaml +10 -0
+      -
+        name: tx-stop
+        doc: |
+          Number of times the tx queue was stopped.
+        type: uint
+      -
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.
+        type: uint

I'm curious where these names came from. The opposite of stop would be start. The opposite of wake would be sleep. Are these meant to be opposites of each other? If they are opposites, why would they differ by more than 1? And if they can only differ by 1, why do we need both?

Andrew

#3 lore raw

RE: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 15 lines

From: Andrew Lunn <[email protected]>
Sent: Thursday, May 9, 2024 3:47 PM
To: Dan Jurgens <[email protected]>
Subject: Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Documentation/netlink/specs/netdev.yaml attribute-sets: · line 451

Quoted 7 lines · Daniel Jurgens

TX queue stop and wake are counted by some drivers. Support reporting these via netdev-genl queue stats.

Documentation/netlink/specs/netdev.yaml +4 -0
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.
+        type: uint
Quoted 4 lines

I'm curious where these names came from. The opposite of stop would be start. The opposite of wake would be sleep. Are these meant to be opposites of each other? If they are opposites, why would they differ by more than 1? And if they can only differ by 1, why do we need both?

The names come from the API. netif_tx_stop_queue, netif_tx_wake_queue. It's true that they can only ever differ by 1, but when they do that's interesting. Though eventually a TX timeout will occur if it's due to something like a lost interrupt.

The most useful thing is knowing if queues are being stopped frequently, so if there's objection to the wake side it can be dropped.

Quoted 2 lines

Andrew

reviewer
#10 lore raw

Re: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

In reply to Daniel Jurgens
Quoted 49 lines · Daniel Jurgens

Add a tx queue stop and wake counters, they are useful for debugging.

$ ./tools/net/ynl/cli.py --spec netlink/specs/netdev.yaml \
--dump qstats-get --json '{"scope": "queue"}'
...
 {'ifindex': 13,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 14756682850,
  'tx-packets': 226465,
  'tx-stop': 113208,
  'tx-wake': 113208},
 {'ifindex': 13,
  'queue-id': 1,
  'queue-type': 'tx',
  'tx-bytes': 18167675008,
  'tx-packets': 278660,
  'tx-stop': 8632,
  'tx-wake': 8632}]
---
 drivers/net/virtio_net.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +4 -0
index 218a446c4c27..df6121c38a1b 100644
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
 	u64_stats_t xdp_tx_drops;
 	u64_stats_t kicks;
 	u64_stats_t tx_timeouts;
+	u64_stats_t stop;
+	u64_stats_t wake;
 };
 
 struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = {
 static const struct virtnet_stat_desc virtnet_sq_stats_desc_qstat[] = {
 	VIRTNET_SQ_STAT_QSTAT("packets", packets),
 	VIRTNET_SQ_STAT_QSTAT("bytes",   bytes),
+	VIRTNET_SQ_STAT_QSTAT("stop",	 stop),
+	VIRTNET_SQ_STAT_QSTAT("wake",	 wake),
 };
 
 static const struct virtnet_stat_desc virtnet_rq_stats_desc_qstat[] = {

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1023

Quoted 6 lines
drivers/net/virtio_net.c +3 -0
@@ -1014,6 +1018,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
+		u64_stats_update_begin(&sq->stats.syncp);
+		u64_stats_inc(&sq->stats.stop);
+		u64_stats_update_end(&sq->stats.syncp);

How about introduce two helpers to wrap
netif_tx_queue_stopped and netif_start_subqueue?

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1034

Quoted 10 lines
drivers/net/virtio_net.c +3 -0
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq->vq);
@@ -1022,6 +1029,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
 			free_old_xmit(sq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);

If we start the queue immediately, should we update the counter?

Thanks.

Quoted 47 lines
drivers/net/virtio_net.c +16 -3
 				virtqueue_disable_cb(sq->vq);
 			}
 		}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
 			free_old_xmit(sq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
-		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+			if (netif_tx_queue_stopped(txq)) {
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
+			}
 			netif_tx_wake_queue(txq);
+		}
 
 		__netif_tx_unlock(txq);
 	}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
 	virtqueue_disable_cb(sq->vq);
 	free_old_xmit(sq, true);
 
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+		if (netif_tx_queue_stopped(txq)) {
+			u64_stats_update_begin(&sq->stats.syncp);
+			u64_stats_inc(&sq->stats.wake);
+			u64_stats_update_end(&sq->stats.syncp);
+		}
 		netif_tx_wake_queue(txq);
+	}
 
 	opaque = virtqueue_enable_cb_prepare(sq->vq);
 
@@ -4790,6 +4812,8 @@ static void virtnet_get_base_stats(struct net_device *dev,
 
 	tx->bytes = 0;
 	tx->packets = 0;
+	tx->stop = 0;
+	tx->wake = 0;
 
 	if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {
 		tx->hw_drops = 0;
--

2.44.0

maintainer
#7 lore raw

Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

In reply to Daniel Jurgens

tools/include/uapi/linux/netdev.h enum { · line 167

Quoted 9 lines · On Thu, 9 May 2024 11:32:15 -0500 Daniel Jurgens wrote:
tools/include/uapi/linux/netdev.h +0 -1
index cf24f1d9adf8..ccf6976b1693 100644
@@ -164,7 +164,8 @@ enum {
 	NETDEV_A_QSTATS_TX_HW_GSO_BYTES,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
-	NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,

Looks like an accidental removal?

tools/include/uapi/linux/netdev.h enum { · line 168

Quoted 2 lines
tools/include/uapi/linux/netdev.h +2 -0
+	NETDEV_A_QSTATS_TX_STOP,
+	NETDEV_A_QSTATS_TX_WAKE,

Since you'll have to respin let me nit pick on the docs, as I'm hoping that those will be comprehensible to users not only devs.

tools/include/uapi/linux/netdev.h enum { · line 171

Quoted 3 lines
tools/include/uapi/linux/netdev.h +3 -0
+        name: tx-stop
+        doc: |
+          Number of times the tx queue was stopped.

How about:

Number of times driver paused accepting new tx packets from the stack to this queue, because the queue was full. Note that if BQL is supported and enabled on the device the networking stack will avoid queuing a lot of data at once.

tools/include/uapi/linux/netdev.h enum {

Quoted 3 lines
tools/include/uapi/linux/netdev.h +3 -0
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.

Number of times driver re-started accepting send requests to this queue from the stack.

#11 lore raw

RE: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

In reply to Xuan Zhuo
Quoted 74 lines

From: Xuan Zhuo <[email protected]>
Sent: Thursday, May 9, 2024 8:22 PM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri Pirko <[email protected]>; Dan Jurgens <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

Quoted 40 lines · Daniel Jurgens

Add a tx queue stop and wake counters, they are useful for debugging.

$ ./tools/net/ynl/cli.py --spec netlink/specs/netdev.yaml \ --dump
qstats-get --json '{"scope": "queue"}'
...
 {'ifindex': 13,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 14756682850,
  'tx-packets': 226465,
  'tx-stop': 113208,
  'tx-wake': 113208},
 {'ifindex': 13,
  'queue-id': 1,
  'queue-type': 'tx',
  'tx-bytes': 18167675008,
  'tx-packets': 278660,
  'tx-stop': 8632,
  'tx-wake': 8632}]
---
 drivers/net/virtio_net.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

218a446c4c27..df6121c38a1b 100644

drivers/net/virtio_net.c +2 -0
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
 	u64_stats_t xdp_tx_drops;
 	u64_stats_t kicks;
 	u64_stats_t tx_timeouts;
+	u64_stats_t stop;
+	u64_stats_t wake;
 };
 
 struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc
Quoted 1 line

virtnet_rq_stats_desc[] = { static const struct virtnet_stat_desc

virtnet_sq_stats_desc_qstat[] = {

Quoted 8 lines
drivers/net/virtio_net.c +2 -0
 	VIRTNET_SQ_STAT_QSTAT("packets", packets),
 	VIRTNET_SQ_STAT_QSTAT("bytes",   bytes),
+	VIRTNET_SQ_STAT_QSTAT("stop",	 stop),
+	VIRTNET_SQ_STAT_QSTAT("wake",	 wake),
 };
 
 static const struct virtnet_stat_desc virtnet_rq_stats_desc_qstat[] =

{ @@ -1014,6 +1018,9 @@ static void check_sq_full_and_disable(struct

virtnet_info *vi,

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1023

Quoted 6 lines
drivers/net/virtio_net.c +3 -0
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
+		u64_stats_update_begin(&sq->stats.syncp);
+		u64_stats_inc(&sq->stats.stop);
+		u64_stats_update_end(&sq->stats.syncp);

How about introduce two helpers to wrap netif_tx_queue_stopped and netif_start_subqueue?

Quoted 13 lines

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1034

Quoted 11 lines
drivers/net/virtio_net.c +0 -0
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq-

vq); @@ -1022,6 +1029,9 @@
static void check_sq_full_and_disable(struct virtnet_info *vi,

drivers/net/virtio_net.c +3 -0
 			free_old_xmit(sq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);

If we start the queue immediately, should we update the counter?

I intentionally only counted the wakes on restarts after stopping the queue. I don't think counting the initial wake adds any value since it always happens.

Quoted 53 lines

Thanks.

drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct

Quoted 4 lines
drivers/net/virtio_net.c +0 -0
 				virtqueue_disable_cb(sq->vq);
 			}
 		}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct

receive_queue *rq)

drivers/net/virtio_net.c static int virtnet_poll_tx(struct napi_struct

Quoted 16 lines
drivers/net/virtio_net.c +7 -1
 			free_old_xmit(sq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
-		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+			if (netif_tx_queue_stopped(txq)) {
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
+			}
 			netif_tx_wake_queue(txq);
+		}
 
 		__netif_tx_unlock(txq);
 	}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct napi_struct

*napi, int budget)

Quoted 28 lines
drivers/net/virtio_net.c +9 -1
 	virtqueue_disable_cb(sq->vq);
 	free_old_xmit(sq, true);
 
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+		if (netif_tx_queue_stopped(txq)) {
+			u64_stats_update_begin(&sq->stats.syncp);
+			u64_stats_inc(&sq->stats.wake);
+			u64_stats_update_end(&sq->stats.syncp);
+		}
 		netif_tx_wake_queue(txq);
+	}
 
 	opaque = virtqueue_enable_cb_prepare(sq->vq);
 
@@ -4790,6 +4812,8 @@ static void virtnet_get_base_stats(struct
 net_device *dev,
 
 	tx->bytes = 0;
 	tx->packets = 0;
+	tx->stop = 0;
+	tx->wake = 0;
 
 	if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {

tx->hw_drops = 0;
--
2.44.0

#8 lore raw

RE: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

In reply to Jakub Kicinski
Quoted 11 lines

From: Jakub Kicinski <[email protected]>
Sent: Thursday, May 9, 2024 8:31 PM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri Pirko <[email protected]>
Subject: Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

On Thu, 9 May 2024 11:32:15 -0500 Daniel Jurgens wrote:

Quoted 12 lines

tools/include/uapi/linux/netdev.h enum { · line 167

Quoted 10 lines
tools/include/uapi/linux/netdev.h +0 -1
index cf24f1d9adf8..ccf6976b1693 100644
@@ -164,7 +164,8 @@ enum {
 	NETDEV_A_QSTATS_TX_HW_GSO_BYTES,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
 	NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
-	NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,

Looks like an accidental removal?

Yes, thanks.

Quoted 18 lines

tools/include/uapi/linux/netdev.h enum { · line 168

Quoted 3 lines
tools/include/uapi/linux/netdev.h +2 -0
+	NETDEV_A_QSTATS_TX_STOP,
+	NETDEV_A_QSTATS_TX_WAKE,

Since you'll have to respin let me nit pick on the docs, as I'm hoping that those will be comprehensible to users not only devs.

tools/include/uapi/linux/netdev.h enum { · line 171

Quoted 3 lines
tools/include/uapi/linux/netdev.h +3 -0
+        name: tx-stop
+        doc: |
+          Number of times the tx queue was stopped.

How about:

Number of times driver paused accepting new tx packets from the stack to this queue, because the queue was full. Note that if BQL is supported and enabled on the device the networking stack will avoid queuing a lot of data at once.

Quoted 6 lines

tools/include/uapi/linux/netdev.h enum {

Quoted 3 lines
tools/include/uapi/linux/netdev.h +3 -0
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.

Number of times driver re-started accepting send requests to this queue from the stack.

Will update it. Thanks for the text!

reviewer
#12 lore raw

Re: RE: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

In reply to Dan Jurgens
Quoted 88 lines · Dan Jurgens
Quoted 74 lines

From: Xuan Zhuo <[email protected]>
Sent: Thursday, May 9, 2024 8:22 PM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri Pirko <[email protected]>; Dan Jurgens <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

Quoted 40 lines · Daniel Jurgens

Add a tx queue stop and wake counters, they are useful for debugging.

$ ./tools/net/ynl/cli.py --spec netlink/specs/netdev.yaml \ --dump
qstats-get --json '{"scope": "queue"}'
...
 {'ifindex': 13,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 14756682850,
  'tx-packets': 226465,
  'tx-stop': 113208,
  'tx-wake': 113208},
 {'ifindex': 13,
  'queue-id': 1,
  'queue-type': 'tx',
  'tx-bytes': 18167675008,
  'tx-packets': 278660,
  'tx-stop': 8632,
  'tx-wake': 8632}]
---
 drivers/net/virtio_net.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

218a446c4c27..df6121c38a1b 100644

drivers/net/virtio_net.c +2 -0
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
 	u64_stats_t xdp_tx_drops;
 	u64_stats_t kicks;
 	u64_stats_t tx_timeouts;
+	u64_stats_t stop;
+	u64_stats_t wake;
 };
 
 struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc
Quoted 1 line

virtnet_rq_stats_desc[] = { static const struct virtnet_stat_desc

virtnet_sq_stats_desc_qstat[] = {

Quoted 8 lines
drivers/net/virtio_net.c +2 -0
 	VIRTNET_SQ_STAT_QSTAT("packets", packets),
 	VIRTNET_SQ_STAT_QSTAT("bytes",   bytes),
+	VIRTNET_SQ_STAT_QSTAT("stop",	 stop),
+	VIRTNET_SQ_STAT_QSTAT("wake",	 wake),
 };
 
 static const struct virtnet_stat_desc virtnet_rq_stats_desc_qstat[] =

{ @@ -1014,6 +1018,9 @@ static void check_sq_full_and_disable(struct

virtnet_info *vi,

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1023

Quoted 6 lines
drivers/net/virtio_net.c +3 -0
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
+		u64_stats_update_begin(&sq->stats.syncp);
+		u64_stats_inc(&sq->stats.stop);
+		u64_stats_update_end(&sq->stats.syncp);

How about introduce two helpers to wrap netif_tx_queue_stopped and netif_start_subqueue?

Quoted 13 lines

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1034

Quoted 11 lines
drivers/net/virtio_net.c +0 -0
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq-

vq); @@ -1022,6 +1029,9 @@
static void check_sq_full_and_disable(struct virtnet_info *vi,

drivers/net/virtio_net.c +3 -0
 			free_old_xmit(sq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);

If we start the queue immediately, should we update the counter?

Quoted 2 lines

I intentionally only counted the wakes on restarts after stopping the queue. I don't think counting the initial wake adds any value since it always happens.

Here, we start the queue immediately after the queue is stopped. So for the upper layer, the queue "has not" changed the status, I think we do not need to update the wake counter.

Thanks.

Quoted 55 lines
Quoted 54 lines

Thanks.

drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct

Quoted 4 lines
drivers/net/virtio_net.c +0 -0
 				virtqueue_disable_cb(sq->vq);
 			}
 		}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct

receive_queue *rq)

drivers/net/virtio_net.c static int virtnet_poll_tx(struct napi_struct

Quoted 16 lines
drivers/net/virtio_net.c +7 -1
 			free_old_xmit(sq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
-		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+			if (netif_tx_queue_stopped(txq)) {
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
+			}
 			netif_tx_wake_queue(txq);
+		}
 
 		__netif_tx_unlock(txq);
 	}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct napi_struct

*napi, int budget)

Quoted 28 lines
drivers/net/virtio_net.c +9 -1
 	virtqueue_disable_cb(sq->vq);
 	free_old_xmit(sq, true);
 
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+		if (netif_tx_queue_stopped(txq)) {
+			u64_stats_update_begin(&sq->stats.syncp);
+			u64_stats_inc(&sq->stats.wake);
+			u64_stats_update_end(&sq->stats.syncp);
+		}
 		netif_tx_wake_queue(txq);
+	}
 
 	opaque = virtqueue_enable_cb_prepare(sq->vq);
 
@@ -4790,6 +4812,8 @@ static void virtnet_get_base_stats(struct
 net_device *dev,
 
 	tx->bytes = 0;
 	tx->packets = 0;
+	tx->stop = 0;
+	tx->wake = 0;
 
 	if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {

tx->hw_drops = 0;
--
2.44.0

#4 lore raw

Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

In reply to Dan Jurgens
Quoted 15 lines · Dan Jurgens
Quoted 15 lines

From: Andrew Lunn <[email protected]>
Sent: Thursday, May 9, 2024 3:47 PM
To: Dan Jurgens <[email protected]>
Subject: Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 7 lines · Daniel Jurgens

TX queue stop and wake are counted by some drivers. Support reporting these via netdev-genl queue stats.

Documentation/netlink/specs/netdev.yaml +4 -0
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.
+        type: uint
Quoted 6 lines
Quoted 4 lines

I'm curious where these names came from. The opposite of stop would be start. The opposite of wake would be sleep. Are these meant to be opposites of each other? If they are opposites, why would they differ by more than 1? And if they can only differ by 1, why do we need both?

The names come from the API. netif_tx_stop_queue, netif_tx_wake_queue.

O.K. So in that context, these names make sense. Maybe extend the doc:
to mention these function names?

You say there are a few drivers with these counters? Does it make sense to actually push the increment into netif_tx_stop_queue(), netif_tx_wake_queue() so that they become available for all drivers? I've no idea what that implies...

Andrew

#13 lore raw

RE: RE: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

In reply to Xuan Zhuo
Quoted 104 lines

From: Xuan Zhuo <[email protected]>
Sent: Friday, May 10, 2024 1:48 AM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri Pirko <[email protected]>; [email protected]
Subject: Re: RE: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

Quoted 4 lines · Dan Jurgens
Quoted 4 lines

From: Xuan Zhuo <[email protected]>
Sent: Thursday, May 9, 2024 8:22 PM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri

Pirko

Quoted 70 lines
Quoted 70 lines

<[email protected]>; Dan Jurgens <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 2/2] virtio_net: Add TX stopped and wake counters

Quoted 40 lines · Daniel Jurgens

Add a tx queue stop and wake counters, they are useful for debugging.

$ ./tools/net/ynl/cli.py --spec netlink/specs/netdev.yaml \ --dump
qstats-get --json '{"scope": "queue"}'
...
 {'ifindex': 13,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 14756682850,
  'tx-packets': 226465,
  'tx-stop': 113208,
  'tx-wake': 113208},
 {'ifindex': 13,
  'queue-id': 1,
  'queue-type': 'tx',
  'tx-bytes': 18167675008,
  'tx-packets': 278660,
  'tx-stop': 8632,
  'tx-wake': 8632}]
---
 drivers/net/virtio_net.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +2 -0
index 218a446c4c27..df6121c38a1b 100644
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
 	u64_stats_t xdp_tx_drops;
 	u64_stats_t kicks;
 	u64_stats_t tx_timeouts;
+	u64_stats_t stop;
+	u64_stats_t wake;
 };
 
 struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc
Quoted 1 line

virtnet_rq_stats_desc[] = { static const struct virtnet_stat_desc

virtnet_sq_stats_desc_qstat[] = {

Quoted 9 lines
drivers/net/virtio_net.c +2 -0
 	VIRTNET_SQ_STAT_QSTAT("packets", packets),
 	VIRTNET_SQ_STAT_QSTAT("bytes",   bytes),
+	VIRTNET_SQ_STAT_QSTAT("stop",	 stop),
+	VIRTNET_SQ_STAT_QSTAT("wake",	 wake),
 };
 
 static const struct virtnet_stat_desc

virtnet_rq_stats_desc_qstat[] = { @@ -1014,6 +1018,9 @@ static void check_sq_full_and_disable(struct

virtnet_info *vi,

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1023

Quoted 6 lines
drivers/net/virtio_net.c +3 -0
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
+		u64_stats_update_begin(&sq->stats.syncp);
+		u64_stats_inc(&sq->stats.stop);
+		u64_stats_update_end(&sq->stats.syncp);

How about introduce two helpers to wrap netif_tx_queue_stopped and netif_start_subqueue?

Quoted 3 lines
Quoted 3 lines

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi,

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 		if (use_napi) {
 			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
 				virtqueue_napi_schedule(&sq->napi, sq- vq);

@@ -1022,6

Quoted 11 lines
Quoted 10 lines

drivers/net/virtio_net.c static void check_sq_full_and_disable(struct virtnet_info *vi, · line 1034

Quoted 8 lines

+1029,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,

drivers/net/virtio_net.c +3 -0
 			free_old_xmit(sq, false);
 			if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
 				netif_start_subqueue(dev, qnum);
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);

If we start the queue immediately, should we update the counter?

Quoted 8 lines
Quoted 1 line

I intentionally only counted the wakes on restarts after stopping the

queue.

Quoted 1 line

I don't think counting the initial wake adds any value since it always

happens.

Here, we start the queue immediately after the queue is stopped. So for the upper layer, the queue "has not" changed the status, I think we do not need to update the wake counter.

I think we should. We incremented the stop counter. If they get out sync wake loses any functionality.

Quoted 60 lines

Thanks.

Quoted 56 lines
Quoted 55 lines

Thanks.

drivers/net/virtio_net.c static void virtnet_poll_cleantx(struct

Quoted 4 lines
drivers/net/virtio_net.c +0 -0
 				virtqueue_disable_cb(sq->vq);
 			}
 		}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct

receive_queue *rq)

Quoted 16 lines
drivers/net/virtio_net.c +7 -1
 			free_old_xmit(sq, true);
 		} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
 
-		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+		if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+			if (netif_tx_queue_stopped(txq)) {
+				u64_stats_update_begin(&sq->stats.syncp);
+				u64_stats_inc(&sq->stats.wake);
+				u64_stats_update_end(&sq->stats.syncp);
+			}
 			netif_tx_wake_queue(txq);
+		}
 
 		__netif_tx_unlock(txq);
 	}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct
Quoted 1 line

napi_struct

*napi, int budget)

Quoted 28 lines
drivers/net/virtio_net.c +9 -1
 	virtqueue_disable_cb(sq->vq);
 	free_old_xmit(sq, true);
 
-	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
+	if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
+		if (netif_tx_queue_stopped(txq)) {
+			u64_stats_update_begin(&sq->stats.syncp);
+			u64_stats_inc(&sq->stats.wake);
+			u64_stats_update_end(&sq->stats.syncp);
+		}
 		netif_tx_wake_queue(txq);
+	}
 
 	opaque = virtqueue_enable_cb_prepare(sq->vq);
@@ -4790,6 +4812,8 @@ static void virtnet_get_base_stats(struct
 net_device *dev,
 
 	tx->bytes = 0;
 	tx->packets = 0;
+	tx->stop = 0;
+	tx->wake = 0;
 
 	if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {

tx->hw_drops = 0;
--
2.44.0

#5 lore raw

RE: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

In reply to Andrew Lunn
Quoted 35 lines

From: Andrew Lunn <[email protected]>
Sent: Friday, May 10, 2024 7:59 AM
To: Dan Jurgens <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jiri Pirko <[email protected]>
Subject: Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 15 lines · Dan Jurgens
Quoted 15 lines

From: Andrew Lunn <[email protected]>
Sent: Thursday, May 9, 2024 3:47 PM
To: Dan Jurgens <[email protected]>
Subject: Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 7 lines · Daniel Jurgens

TX queue stop and wake are counted by some drivers. Support reporting these via netdev-genl queue stats.

Documentation/netlink/specs/netdev.yaml +4 -0
+        name: tx-wake
+        doc: |
+          Number of times the tx queue was restarted.
+        type: uint
Quoted 4 lines
Quoted 4 lines

I'm curious where these names came from. The opposite of stop would be start. The opposite of wake would be sleep. Are these meant to be opposites of each other? If they are opposites, why would they differ by more than 1? And if they can only differ by 1, why do we need

both?

Quoted 2 lines

The names come from the API. netif_tx_stop_queue,

netif_tx_wake_queue.

Quoted 7 lines

O.K. So in that context, these names make sense. Maybe extend the doc:
to mention these function names?

You say there are a few drivers with these counters? Does it make sense to actually push the increment into netif_tx_stop_queue(), netif_tx_wake_queue() so that they become available for all drivers? I've no idea what that implies...

It wouldn't be trivial. The stats are queried from the driver.

Quoted 2 lines

Andrew

#6 lore raw

Re: [PATCH net-next 1/2] netdev: Add queue stats for TX stop and wake

Quoted 1 line

It wouldn't be trivial. The stats are queried from the driver.

So are page pool stats, with the increments happening in the page pool code, not the driver.

Andrew