Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2518658pxb; Fri, 17 Sep 2021 11:34:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2yd5UAJUeywUHMPA6NtrHg4A4mkXgYgQsfI/YPsndSA2vnMzHNdzNbXOeSKViNJObEuQ/ X-Received: by 2002:a05:6e02:168d:: with SMTP id f13mr8862013ila.12.1631903682363; Fri, 17 Sep 2021 11:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631903682; cv=none; d=google.com; s=arc-20160816; b=UcHAWUw9aL64MoPJiavkMX/QZRkpHRVhNX+uginGsA31uz9yQ+YWtje4eHE8zcaQRl R8mAxs8Dc7NbCVRMRhkugyi1f6CaK/nEqxt0RwNkhacFr1j6aN4ow7qsDPvbROxEZSqr ONY4ojMODSD4YuffJtoByuxkNC0lQJxVX0vkFoGEXh+3KWXLqT65jJs1Gv8KJuhWieOl dt6GnoF1eCuMANoCU5uKCVe+USE5qQI1MwPS7osDJhhLB2aTUfM+pftCZqj26rfiR5qD MsxIGWdYLCnLDywxFgid2D6Qb/WRq7Za7S+k45dttaBp02oKwrOl+PghU2LTqkvrhny2 Qa7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=OlnJfZHFrbUTxFlJhHKec2iFp58KjmQ4CT86yXptOCU=; b=ILF1KVttlNgISemHJwX4iRAqRrNl/tcVpZcFUC9GVWOQjgOtrr4caLBYm0lFpBhvx1 hXSlGTZo75x6+htlYZm7PlrqDuTZ72mfWSr4K6lybDNBsJvBEtcpLDa3HSyqyHP5yy/Q 93lcomzUfLq1VFjqRif56NgCWvgpxhcg6H0jeZzPC9CXbl1C3ITWTLz/WmyoJ87xtuDB XZBsI2O8gXQnzjlo9S/NLAlEOpdU6Oqg8slu3tRbbdujyPnoJRt/XWtTNfjV1Xh07Iph 0+Zm5V9QYmsZC1Hc8Ifxa/EBTvQLcImg4+4zu7sqBm8A+nkrhihgdwvpg/1JuHX76t3c RWBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si7988889ilu.53.2021.09.17.11.34.29; Fri, 17 Sep 2021 11:34:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245448AbhIQIqf (ORCPT + 99 others); Fri, 17 Sep 2021 04:46:35 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:59897 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233688AbhIQIqe (ORCPT ); Fri, 17 Sep 2021 04:46:34 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=tonylu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Uofyx2P_1631868310; Received: from localhost(mailfrom:tonylu@linux.alibaba.com fp:SMTPD_---0Uofyx2P_1631868310) by smtp.aliyun-inc.com(127.0.0.1); Fri, 17 Sep 2021 16:45:10 +0800 From: tonylu_linux To: mst@redhat.com, jasowang@redhat.com Cc: linux-kernel@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH] virtio_net: introduce TX timeout watchdog Date: Fri, 17 Sep 2021 16:40:06 +0800 Message-Id: <20210917084004.44332-1-tonylu@linux.alibaba.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tony Lu This implements ndo_tx_timeout handler and put this into stats. When there is something wrong to send out packets, we could notice tx timeout events and total timeout counter. We have suffered send timeout issues due to the backends hung. With this, we can find the details, and collect the counters by monitor systems. Signed-off-by: Tony Lu --- drivers/net/virtio_net.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 271d38c1d9f8..90fed0fdc40f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -80,6 +80,7 @@ struct virtnet_sq_stats { u64 xdp_tx; u64 xdp_tx_drops; u64 kicks; + u64 tx_timeouts; }; struct virtnet_rq_stats { @@ -103,6 +104,7 @@ static const struct virtnet_stat_desc virtnet_sq_stats_desc[] = { { "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[] = { @@ -1856,7 +1858,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]; @@ -1864,6 +1866,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 { @@ -1878,6 +1881,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; @@ -2659,6 +2663,21 @@ static int virtnet_set_features(struct net_device *dev, return 0; } +static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) +{ + struct virtnet_info *priv = netdev_priv(dev); + struct send_queue *sq = &priv->sq[txqueue]; + struct netdev_queue *txq = netdev_get_tx_queue(dev, txqueue); + + u64_stats_update_begin(&sq->stats.syncp); + sq->stats.tx_timeouts++; + u64_stats_update_end(&sq->stats.syncp); + + netdev_err(dev, "TX timeout on queue: %u, sq: %s, vq: 0x%x, name: %s, %u usecs ago\n", + txqueue, sq->name, sq->vq->index, sq->vq->name, + jiffies_to_usecs(jiffies - txq->trans_start)); +} + static const struct net_device_ops virtnet_netdev = { .ndo_open = virtnet_open, .ndo_stop = virtnet_close, @@ -2674,6 +2693,7 @@ static const struct net_device_ops virtnet_netdev = { .ndo_features_check = passthru_features_check, .ndo_get_phys_port_name = virtnet_get_phys_port_name, .ndo_set_features = virtnet_set_features, + .ndo_tx_timeout = virtnet_tx_timeout, }; static void virtnet_config_changed_work(struct work_struct *work) -- 2.19.1.6.gb485710b