DPDK patches and discussions
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, <linuxarm@openeuler.org>
Subject: [dpdk-dev] [PATCH 12/17] net/hns3: fix stats flip overflow
Date: Wed, 3 Feb 2021 15:46:17 +0800	[thread overview]
Message-ID: <1612338382-3253-13-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1612338382-3253-1-git-send-email-oulijun@huawei.com>

From: Chengchang Tang <tangchengchang@huawei.com>

Currently, statistics may overflow in some scenarios.

For example, if HW statistics are reset by stats reset operation,
but there are still a lot of residual packets exist in the HW
queues and these packets are error packets, flip may occurred
because the ipacket is obtained by substracting the number of
software error packets from the number of HW received packets.

This patch verifies the calculation and returns 0 when overflow
may occur.

Fixes: 8839c5e202f3 ("net/hns3: support device stats")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/net/hns3/hns3_stats.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index e58ebea..58cce35 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -637,8 +637,14 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
 #endif
 
 	rte_stats->oerrors = 0;
-	rte_stats->ipackets = stats->rcb_rx_ring_pktnum_rcd -
-		rte_stats->ierrors;
+	/*
+	 * If HW statistics are reset by stats_reset, but a lot of residual
+	 * packets exist in the hardware queue and these packets are error
+	 * packets, flip overflow may occurred. So return 0 in this case.
+	 */
+	rte_stats->ipackets =
+		stats->rcb_rx_ring_pktnum_rcd > rte_stats->ierrors ?
+		stats->rcb_rx_ring_pktnum_rcd - rte_stats->ierrors : 0;
 	rte_stats->opackets  = stats->rcb_tx_ring_pktnum_rcd -
 		rte_stats->oerrors;
 	rte_stats->rx_nombuf = eth_dev->data->rx_mbuf_alloc_failed;
@@ -889,8 +895,15 @@ hns3_rxq_basic_stats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 		rxq_stats = &rxq->basic_stats;
 		rxq_stats->errors = rxq->err_stats.l2_errors +
 					rxq->err_stats.pkt_len_errors;
-		rxq_stats->packets = stats->rcb_rx_ring_pktnum[i] -
-			rxq_stats->errors;
+		/*
+		 * If HW statistics are reset by stats_reset, but a lot of
+		 * residual packets exist in the hardware queue and these
+		 * packets are error packets, flip overflow may occurred.
+		 * So return 0 in this case.
+		 */
+		rxq_stats->packets =
+			stats->rcb_rx_ring_pktnum[i] > rxq_stats->errors ?
+			stats->rcb_rx_ring_pktnum[i] - rxq_stats->errors : 0;
 
 		for (j = 0; j < HNS3_NUM_RXQ_BASIC_STATS; j++) {
 			val = (char *)rxq_stats +
-- 
2.7.4


  parent reply	other threads:[~2021-02-03  7:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03  7:46 [dpdk-dev] [PATCH 00/17] bugfixes and small functionality for hns3 Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 01/17] net/hns3: support module EEPROM dump Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 02/17] net/hns3: add more registers to dump Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 03/17] net/hns3: implement cleanup for Tx done Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 04/17] net/hns3: add enhance stats function Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 05/17] net/hns3: fix query order of link status and link info Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 06/17] net/hns3: fix link status change from firmware Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 07/17] net/hns3: encapsulate a port shaping interface Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 08/17] net/hns3: support PF on electrical net device Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 09/17] net/hns3: fix RSS indirection table size Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 10/17] net/hns3: constraint TM peak rate Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 11/17] net/hns3: remove MPLS type from supported flow items Lijun Ou
2021-02-03  7:46 ` Lijun Ou [this message]
2021-02-03  7:46 ` [dpdk-dev] [PATCH 13/17] net/hns3: replace all atomic type with C11 atomic builtins Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 14/17] net/hns3: fix FD rule residue in hardware when malloc fail Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 15/17] net/hns3: fix cmdq cleared during firmware process Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 16/17] net/hns3: fix VF reset after MBX failed Lijun Ou
2021-02-03  7:46 ` [dpdk-dev] [PATCH 17/17] net/hns3: add check for max pkt length of Rx Lijun Ou
2021-02-03  9:24 ` [dpdk-dev] [PATCH 00/17] bugfixes and small functionality for hns3 Ferruh Yigit
2021-02-03 11:05   ` oulijun
2021-02-03 11:46     ` Ferruh Yigit
2021-02-03 12:18       ` oulijun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1612338382-3253-13-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=linuxarm@openeuler.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).