From a3a8bfb13a43392e2b7753668858f67c352a58df Mon Sep 17 00:00:00 2001 From: Tony Lu Date: Fri, 24 Jul 2020 11:17:23 +0800 Subject: [PATCH 2358/2944] alinux: virtio_net: introduce TX timeout dev_watchdog handler fix #23955192 Driver virtio-net doesn't implement netdev_ops->ndo_tx_timeout and ignore the TX timeout event. This event is emitted when TX queue do not send out any packet for a while. We should notice this event when packet drop or latency increment. Besides that, TX timeout count will merge into rtnl_link_stats64. This handler doesn't reset TX queue after this event is emitted. Signed-off-by: Tony Lu Acked-by: Dust Li --- drivers/net/virtio_net.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c88ee37..c988482 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -88,6 +88,7 @@ struct virtnet_sq_stats { u64 xdp_tx; u64 xdp_tx_drops; u64 kicks; + u64 tx_timeouts; }; struct virtnet_rq_stats { @@ -111,6 +112,7 @@ struct virtnet_rq_stats { { "xdp_tx", VIRTNET_SQ_STAT(xdp_tx) }, { "xdp_tx_drops", VIRTNET_SQ_STAT(xdp_tx_drops) }, { "kicks", VIRTNET_SQ_STAT(kicks) }, + { "tx_timeouts", VIRTNET_SQ_STAT(tx_timeouts) }, }; static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = { @@ -1731,7 +1733,7 @@ static void virtnet_stats(struct net_device *dev, int i; for (i = 0; i < vi->max_queue_pairs; i++) { - u64 tpackets, tbytes, rpackets, rbytes, rdrops; + u64 tpackets, tbytes, terrors, rpackets, rbytes, rdrops; struct receive_queue *rq = &vi->rq[i]; struct send_queue *sq = &vi->sq[i]; @@ -1739,6 +1741,7 @@ static void virtnet_stats(struct net_device *dev, start = u64_stats_fetch_begin_irq(&sq->stats.syncp); tpackets = sq->stats.packets; tbytes = sq->stats.bytes; + terrors = sq->stats.tx_timeouts; } while (u64_stats_fetch_retry_irq(&sq->stats.syncp, start)); do { @@ -1753,6 +1756,7 @@ static void virtnet_stats(struct net_device *dev, tot->rx_bytes += rbytes; tot->tx_bytes += tbytes; tot->rx_dropped += rdrops; + tot->tx_errors += terrors; } tot->tx_dropped = dev->stats.tx_dropped; @@ -2517,6 +2521,28 @@ static int virtnet_get_phys_port_name(struct net_device *dev, char *buf, return 0; } +static void virtnet_tx_timeout(struct net_device *dev) +{ + struct virtnet_info *vi = netdev_priv(dev); + u32 i; + + for (i = 0; i < vi->curr_queue_pairs; i++) { + struct netdev_queue *dev_queue = netdev_get_tx_queue(dev, i); + struct send_queue *sq = &vi->sq[i]; + + if (!netif_xmit_stopped(dev_queue)) + continue; + + u64_stats_update_begin(&sq->stats.syncp); + sq->stats.tx_timeouts++; + u64_stats_update_end(&sq->stats.syncp); + + netdev_warn(dev, "TX timeout on queue: %d, sq: 0x%x, vq: 0x%x, name: %s, usecs since last trans: %u\n", + i, sq->name, sq->vq->index, sq->vq->name, + jiffies_to_usecs(jiffies - dev_queue->trans_start)); + } +} + static const struct net_device_ops virtnet_netdev = { .ndo_open = virtnet_open, .ndo_stop = virtnet_close, @@ -2531,6 +2557,7 @@ static int virtnet_get_phys_port_name(struct net_device *dev, char *buf, .ndo_xdp_xmit = virtnet_xdp_xmit, .ndo_features_check = passthru_features_check, .ndo_get_phys_port_name = virtnet_get_phys_port_name, + .ndo_tx_timeout = virtnet_tx_timeout, }; static void virtnet_config_changed_work(struct work_struct *work) -- 1.8.3.1