Skip to content

Commit e5a2802

Browse files
committed
Merge branch 'add-tx-stop-wake-counters'
Daniel Jurgens says: ==================== 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. ==================== Link: https://lore.kernel.org/r/20240510201927.1821109-1-danielj@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents c084ebd + c39add9 commit e5a2802

File tree

6 files changed

+50
-3
lines changed

6 files changed

+50
-3
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,20 @@ attribute-sets:
439439
Number of the packets dropped by the device due to the transmit
440440
packets bitrate exceeding the device rate limit.
441441
type: uint
442+
-
443+
name: tx-stop
444+
doc: |
445+
Number of times driver paused accepting new tx packets
446+
from the stack to this queue, because the queue was full.
447+
Note that if BQL is supported and enabled on the device
448+
the networking stack will avoid queuing a lot of data at once.
449+
type: uint
450+
-
451+
name: tx-wake
452+
doc: |
453+
Number of times driver re-started accepting send
454+
requests to this queue from the stack.
455+
type: uint
442456

443457
operations:
444458
list:

drivers/net/virtio_net.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct virtnet_sq_stats {
9595
u64_stats_t xdp_tx_drops;
9696
u64_stats_t kicks;
9797
u64_stats_t tx_timeouts;
98+
u64_stats_t stop;
99+
u64_stats_t wake;
98100
};
99101

100102
struct virtnet_rq_stats {
@@ -145,6 +147,8 @@ static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = {
145147
static const struct virtnet_stat_desc virtnet_sq_stats_desc_qstat[] = {
146148
VIRTNET_SQ_STAT_QSTAT("packets", packets),
147149
VIRTNET_SQ_STAT_QSTAT("bytes", bytes),
150+
VIRTNET_SQ_STAT_QSTAT("stop", stop),
151+
VIRTNET_SQ_STAT_QSTAT("wake", wake),
148152
};
149153

150154
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,
10141018
*/
10151019
if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
10161020
netif_stop_subqueue(dev, qnum);
1021+
u64_stats_update_begin(&sq->stats.syncp);
1022+
u64_stats_inc(&sq->stats.stop);
1023+
u64_stats_update_end(&sq->stats.syncp);
10171024
if (use_napi) {
10181025
if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
10191026
virtqueue_napi_schedule(&sq->napi, sq->vq);
@@ -1022,6 +1029,9 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
10221029
free_old_xmit(sq, false);
10231030
if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
10241031
netif_start_subqueue(dev, qnum);
1032+
u64_stats_update_begin(&sq->stats.syncp);
1033+
u64_stats_inc(&sq->stats.wake);
1034+
u64_stats_update_end(&sq->stats.syncp);
10251035
virtqueue_disable_cb(sq->vq);
10261036
}
10271037
}
@@ -2322,8 +2332,14 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
23222332
free_old_xmit(sq, true);
23232333
} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
23242334

2325-
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
2335+
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
2336+
if (netif_tx_queue_stopped(txq)) {
2337+
u64_stats_update_begin(&sq->stats.syncp);
2338+
u64_stats_inc(&sq->stats.wake);
2339+
u64_stats_update_end(&sq->stats.syncp);
2340+
}
23262341
netif_tx_wake_queue(txq);
2342+
}
23272343

23282344
__netif_tx_unlock(txq);
23292345
}
@@ -2473,8 +2489,14 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
24732489
virtqueue_disable_cb(sq->vq);
24742490
free_old_xmit(sq, true);
24752491

2476-
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
2492+
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) {
2493+
if (netif_tx_queue_stopped(txq)) {
2494+
u64_stats_update_begin(&sq->stats.syncp);
2495+
u64_stats_inc(&sq->stats.wake);
2496+
u64_stats_update_end(&sq->stats.syncp);
2497+
}
24772498
netif_tx_wake_queue(txq);
2499+
}
24782500

24792501
opaque = virtqueue_enable_cb_prepare(sq->vq);
24802502

@@ -4789,6 +4811,8 @@ static void virtnet_get_base_stats(struct net_device *dev,
47894811

47904812
tx->bytes = 0;
47914813
tx->packets = 0;
4814+
tx->stop = 0;
4815+
tx->wake = 0;
47924816

47934817
if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_TX_BASIC) {
47944818
tx->hw_drops = 0;

include/net/netdev_queues.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct netdev_queue_stats_tx {
4141
u64 hw_gso_wire_bytes;
4242

4343
u64 hw_drop_ratelimits;
44+
45+
u64 stop;
46+
u64 wake;
4447
};
4548

4649
/**

include/uapi/linux/netdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ enum {
165165
NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
166166
NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
167167
NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,
168+
NETDEV_A_QSTATS_TX_STOP,
169+
NETDEV_A_QSTATS_TX_WAKE,
168170

169171
__NETDEV_A_QSTATS_MAX,
170172
NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)

net/core/netdev-genl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ netdev_nl_stats_write_tx(struct sk_buff *rsp, struct netdev_queue_stats_tx *tx)
517517
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_BYTES, tx->hw_gso_bytes) ||
518518
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS, tx->hw_gso_wire_packets) ||
519519
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES, tx->hw_gso_wire_bytes) ||
520-
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS, tx->hw_drop_ratelimits))
520+
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS, tx->hw_drop_ratelimits) ||
521+
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_STOP, tx->stop) ||
522+
netdev_stat_put(rsp, NETDEV_A_QSTATS_TX_WAKE, tx->wake))
521523
return -EMSGSIZE;
522524
return 0;
523525
}

tools/include/uapi/linux/netdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ enum {
165165
NETDEV_A_QSTATS_TX_HW_GSO_WIRE_PACKETS,
166166
NETDEV_A_QSTATS_TX_HW_GSO_WIRE_BYTES,
167167
NETDEV_A_QSTATS_TX_HW_DROP_RATELIMITS,
168+
NETDEV_A_QSTATS_TX_STOP,
169+
NETDEV_A_QSTATS_TX_WAKE,
168170

169171
__NETDEV_A_QSTATS_MAX,
170172
NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)

0 commit comments

Comments
 (0)