DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dongdong Liu <liudongdong3@huawei.com>
To: <dev@dpdk.org>, <ferruh.yigit@xilinx.com>,
	<andrew.rybchenko@oktetlabs.ru>, <thomas@monjalon.net>
Cc: <stable@dpdk.org>, Huisong Li <lihuisong@huawei.com>,
	Dongdong Liu <liudongdong3@huawei.com>,
	Yisen Zhuang <yisen.zhuang@huawei.com>
Subject: [PATCH 3/6] net/hns3: fix statistic lock
Date: Fri, 24 Jun 2022 16:59:48 +0800	[thread overview]
Message-ID: <20220624085951.3177-4-liudongdong3@huawei.com> (raw)
In-Reply-To: <20220624085951.3177-1-liudongdong3@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

The stats_lock is used to protect statistics update in stats APIs and
periodic task, but current code only protect queue related statistics.

Fixes: 1bb6e9073b82 ("net/hns3: fix MAC and queues hw statistics reversion")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_stats.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index 07fad03485..1b0464f3f7 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -629,6 +629,7 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
 	uint16_t i;
 	int ret;
 
+	rte_spinlock_lock(&hw->stats_lock);
 	/* Update imissed stats */
 	ret = hns3_update_imissed_stats(hw, false);
 	if (ret) {
@@ -644,10 +645,7 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
 		if (rxq == NULL)
 			continue;
 
-		rte_spinlock_lock(&hw->stats_lock);
 		hns3_rcb_rx_ring_stats_get(rxq, stats);
-		rte_spinlock_unlock(&hw->stats_lock);
-
 		rte_stats->ierrors += rxq->err_stats.l2_errors +
 				      rxq->err_stats.pkt_len_errors;
 		rte_stats->ibytes += rxq->basic_stats.bytes;
@@ -659,9 +657,7 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
 		if (txq == NULL)
 			continue;
 
-		rte_spinlock_lock(&hw->stats_lock);
 		hns3_rcb_tx_ring_stats_get(txq, stats);
-		rte_spinlock_unlock(&hw->stats_lock);
 		rte_stats->obytes += txq->basic_stats.bytes;
 	}
 
@@ -683,7 +679,10 @@ hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
 	rte_stats->opackets  = stats->rcb_tx_ring_pktnum_rcd -
 		rte_stats->oerrors;
 	rte_stats->rx_nombuf = eth_dev->data->rx_mbuf_alloc_failed;
+
 out:
+	rte_spinlock_unlock(&hw->stats_lock);
+
 	return ret;
 }
 
@@ -697,6 +696,7 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev)
 	uint16_t i;
 	int ret;
 
+	rte_spinlock_lock(&hw->stats_lock);
 	/*
 	 * Note: Reading hardware statistics of imissed registers will
 	 * clear them.
@@ -732,7 +732,6 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev)
 		if (rxq == NULL)
 			continue;
 
-		rte_spinlock_lock(&hw->stats_lock);
 		memset(&rxq->basic_stats, 0,
 				sizeof(struct hns3_rx_basic_stats));
 
@@ -740,7 +739,6 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev)
 		(void)hns3_read_dev(rxq, HNS3_RING_RX_PKTNUM_RECORD_REG);
 		rxq->err_stats.pkt_len_errors = 0;
 		rxq->err_stats.l2_errors = 0;
-		rte_spinlock_unlock(&hw->stats_lock);
 	}
 
 	/* Clear all the stats of a txq in a loop to keep them synchronized */
@@ -749,19 +747,18 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev)
 		if (txq == NULL)
 			continue;
 
-		rte_spinlock_lock(&hw->stats_lock);
 		memset(&txq->basic_stats, 0,
 				sizeof(struct hns3_tx_basic_stats));
 
 		/* This register is read-clear */
 		(void)hns3_read_dev(txq, HNS3_RING_TX_PKTNUM_RECORD_REG);
-		rte_spinlock_unlock(&hw->stats_lock);
 	}
 
-	rte_spinlock_lock(&hw->stats_lock);
 	hns3_tqp_stats_clear(hw);
-	rte_spinlock_unlock(&hw->stats_lock);
+
 out:
+	rte_spinlock_unlock(&hw->stats_lock);
+
 	return ret;
 }
 
@@ -1082,11 +1079,11 @@ hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 			count++;
 		}
 	}
-	rte_spinlock_unlock(&hw->stats_lock);
 
 	ret = hns3_update_imissed_stats(hw, false);
 	if (ret) {
 		hns3_err(hw, "update imissed stats failed, ret = %d", ret);
+		rte_spinlock_unlock(&hw->stats_lock);
 		return ret;
 	}
 
@@ -1115,7 +1112,6 @@ hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 		}
 	}
 
-	rte_spinlock_lock(&hw->stats_lock);
 	hns3_tqp_dfx_stats_get(dev, xstats, &count);
 	hns3_queue_stats_get(dev, xstats, &count);
 	rte_spinlock_unlock(&hw->stats_lock);
-- 
2.22.0


  parent reply	other threads:[~2022-06-24  9:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24  8:59 [PATCH 0/6] some bugfixes for hns3 Dongdong Liu
2022-06-24  8:59 ` [PATCH 1/6] net/hns3: cancel heartbeat alarm when VF reset Dongdong Liu
2022-06-24  8:59 ` [PATCH 2/6] net/hns3: fix received unknown event print when PTP enable Dongdong Liu
2022-06-24  8:59 ` Dongdong Liu [this message]
2022-06-24  8:59 ` [PATCH 4/6] net/hns3: fix nb-desc not verified when using SVE Dongdong Liu
2022-06-24  8:59 ` [PATCH 5/6] net/hns3: make code more clean Dongdong Liu
2022-06-24  8:59 ` [PATCH 6/6] net/hns3: delete the unused code Dongdong Liu
2022-06-24 12:37 ` [PATCH 0/6] some bugfixes for hns3 Andrew Rybchenko

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=20220624085951.3177-4-liudongdong3@huawei.com \
    --to=liudongdong3@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@xilinx.com \
    --cc=lihuisong@huawei.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yisen.zhuang@huawei.com \
    /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).