From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A5B77A0032; Fri, 24 Jun 2022 11:00:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 431F042823; Fri, 24 Jun 2022 11:00:31 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 27A1542820; Fri, 24 Jun 2022 11:00:29 +0200 (CEST) Received: from kwepemi500017.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LTrfc1GhdzDsTX; Fri, 24 Jun 2022 16:59:52 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemi500017.china.huawei.com (7.221.188.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 24 Jun 2022 17:00:27 +0800 From: Dongdong Liu To: , , , CC: , Huisong Li , Dongdong Liu , Yisen Zhuang Subject: [PATCH 3/6] net/hns3: fix statistic lock Date: Fri, 24 Jun 2022 16:59:48 +0800 Message-ID: <20220624085951.3177-4-liudongdong3@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20220624085951.3177-1-liudongdong3@huawei.com> References: <20220624085951.3177-1-liudongdong3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500017.china.huawei.com (7.221.188.110) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Huisong Li 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 Signed-off-by: Dongdong Liu --- 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