Skip to content

Commit cfeb7cd

Browse files
Liming Wukuba-moo
authored andcommitted
virtio_net: enhance wake/stop tx queue statistics accounting
This patch refines and strengthens the statistics collection of TX queue wake/stop events introduced by commit c39add9 ("virtio_net: Add TX stopped and wake counters"). Previously, the driver only recorded partial wake/stop statistics for TX queues. Some wake events triggered by 'skb_xmit_done()' or resume operations were not counted, which made the per-queue metrics incomplete. Signed-off-by: Liming Wu <liming.wu@jaguarmicro.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Link: https://patch.msgid.link/20251120015320.1418-1-liming.wu@jaguarmicro.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8ccd116 commit cfeb7cd

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

drivers/net/virtio_net.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -775,19 +775,34 @@ static bool virtqueue_napi_complete(struct napi_struct *napi,
775775
return false;
776776
}
777777

778+
static void virtnet_tx_wake_queue(struct virtnet_info *vi,
779+
struct send_queue *sq)
780+
{
781+
unsigned int index = vq2txq(sq->vq);
782+
struct netdev_queue *txq = netdev_get_tx_queue(vi->dev, index);
783+
784+
if (netif_tx_queue_stopped(txq)) {
785+
u64_stats_update_begin(&sq->stats.syncp);
786+
u64_stats_inc(&sq->stats.wake);
787+
u64_stats_update_end(&sq->stats.syncp);
788+
netif_tx_wake_queue(txq);
789+
}
790+
}
791+
778792
static void skb_xmit_done(struct virtqueue *vq)
779793
{
780794
struct virtnet_info *vi = vq->vdev->priv;
781-
struct napi_struct *napi = &vi->sq[vq2txq(vq)].napi;
795+
unsigned int index = vq2txq(vq);
796+
struct send_queue *sq = &vi->sq[index];
797+
struct napi_struct *napi = &sq->napi;
782798

783799
/* Suppress further interrupts. */
784800
virtqueue_disable_cb(vq);
785801

786802
if (napi->weight)
787803
virtqueue_napi_schedule(napi, vq);
788804
else
789-
/* We were probably waiting for more output buffers. */
790-
netif_wake_subqueue(vi->dev, vq2txq(vq));
805+
virtnet_tx_wake_queue(vi, sq);
791806
}
792807

793808
#define MRG_CTX_HEADER_SHIFT 22
@@ -3080,13 +3095,8 @@ static void virtnet_poll_cleantx(struct receive_queue *rq, int budget)
30803095
free_old_xmit(sq, txq, !!budget);
30813096
} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
30823097

3083-
if (sq->vq->num_free >= MAX_SKB_FRAGS + 2 &&
3084-
netif_tx_queue_stopped(txq)) {
3085-
u64_stats_update_begin(&sq->stats.syncp);
3086-
u64_stats_inc(&sq->stats.wake);
3087-
u64_stats_update_end(&sq->stats.syncp);
3088-
netif_tx_wake_queue(txq);
3089-
}
3098+
if (sq->vq->num_free >= MAX_SKB_FRAGS + 2)
3099+
virtnet_tx_wake_queue(vi, sq);
30903100

30913101
__netif_tx_unlock(txq);
30923102
}
@@ -3276,13 +3286,8 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
32763286
else
32773287
free_old_xmit(sq, txq, !!budget);
32783288

3279-
if (sq->vq->num_free >= MAX_SKB_FRAGS + 2 &&
3280-
netif_tx_queue_stopped(txq)) {
3281-
u64_stats_update_begin(&sq->stats.syncp);
3282-
u64_stats_inc(&sq->stats.wake);
3283-
u64_stats_update_end(&sq->stats.syncp);
3284-
netif_tx_wake_queue(txq);
3285-
}
3289+
if (sq->vq->num_free >= MAX_SKB_FRAGS + 2)
3290+
virtnet_tx_wake_queue(vi, sq);
32863291

32873292
if (xsk_done >= budget) {
32883293
__netif_tx_unlock(txq);
@@ -3537,6 +3542,9 @@ static void virtnet_tx_pause(struct virtnet_info *vi, struct send_queue *sq)
35373542

35383543
/* Prevent the upper layer from trying to send packets. */
35393544
netif_stop_subqueue(vi->dev, qindex);
3545+
u64_stats_update_begin(&sq->stats.syncp);
3546+
u64_stats_inc(&sq->stats.stop);
3547+
u64_stats_update_end(&sq->stats.syncp);
35403548

35413549
__netif_tx_unlock_bh(txq);
35423550
}
@@ -3553,7 +3561,7 @@ static void virtnet_tx_resume(struct virtnet_info *vi, struct send_queue *sq)
35533561

35543562
__netif_tx_lock_bh(txq);
35553563
sq->reset = false;
3556-
netif_tx_wake_queue(txq);
3564+
virtnet_tx_wake_queue(vi, sq);
35573565
__netif_tx_unlock_bh(txq);
35583566

35593567
if (running)

0 commit comments

Comments
 (0)