net/nfp: fix get represetor wrong port stats

Message ID 20250225013454.442170-1-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Stephen Hemminger
Headers
Series net/nfp: fix get represetor wrong port stats |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS

Commit Message

Chaoyong He Feb. 25, 2025, 1:34 a.m. UTC
From: Long Wu <long.wu@corigine.com>

The 'ipackets'/'opackets' are used to record the number
of packets on represetor port received/sent. But the
code does not consider concurrent calculation of
'ipackets'/'opackets'. If multiple queues are calculated
'ipackets'/'opackets' simultaneously, it will result in
incorrect results.

The previous logic has recorded the number of packets on
each queue, therefore driver only needs to add the data of
all queues to obtain the data of the representor port.

Based on this, modify code to fix the issue.

Fixes: 636e133ec891 ("net/nfp: update Tx and Rx for multiple PF")
Fixes: 82a2c286f35a ("net/nfp: support xstats for flower firmware")
Cc: peng.zhang@corigine.com
Cc: chaoyong.he@corigine.com
Cc: stable@dpdk.org

Signed-off-by: Long Wu <long.wu@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.c            |  2 --
 .../net/nfp/flower/nfp_flower_representor.c    | 18 ++++++++++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
  

Comments

Stephen Hemminger Feb. 25, 2025, 4:17 p.m. UTC | #1
On Tue, 25 Feb 2025 09:34:54 +0800
Chaoyong He <chaoyong.he@corigine.com> wrote:

> From: Long Wu <long.wu@corigine.com>
> 
> The 'ipackets'/'opackets' are used to record the number
> of packets on represetor port received/sent. But the
> code does not consider concurrent calculation of
> 'ipackets'/'opackets'. If multiple queues are calculated
> 'ipackets'/'opackets' simultaneously, it will result in
> incorrect results.
> 
> The previous logic has recorded the number of packets on
> each queue, therefore driver only needs to add the data of
> all queues to obtain the data of the representor port.
> 
> Based on this, modify code to fix the issue.
> 
> Fixes: 636e133ec891 ("net/nfp: update Tx and Rx for multiple PF")
> Fixes: 82a2c286f35a ("net/nfp: support xstats for flower firmware")
> Cc: peng.zhang@corigine.com
> Cc: chaoyong.he@corigine.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Long Wu <long.wu@corigine.com>

Applied to next-net and fixed spelling in commit message.
  

Patch

diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index f087d0dfdc..804ad494d5 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -238,7 +238,6 @@  nfp_flower_multiple_pf_recv_pkts(void *rx_queue,
 		for (i = 0; i < recv; i++)
 			data_len += rx_pkts[i]->data_len;
 
-		repr->repr_stats.ipackets += recv;
 		repr->repr_stats.q_ipackets[rxq->qidx] += recv;
 		repr->repr_stats.q_ibytes[rxq->qidx] += data_len;
 	}
@@ -277,7 +276,6 @@  nfp_flower_multiple_pf_xmit_pkts(void *tx_queue,
 		for (i = 0; i < sent; i++)
 			data_len += tx_pkts[i]->data_len;
 
-		repr->repr_stats.opackets += sent;
 		repr->repr_stats.q_opackets[txq->qidx] += sent;
 		repr->repr_stats.q_obytes[txq->qidx] += data_len;
 	}
diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 9601aa5f96..e377d45e53 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -315,9 +315,25 @@  static int
 nfp_flower_repr_stats_get(struct rte_eth_dev *ethdev,
 		struct rte_eth_stats *stats)
 {
+	uint16_t i;
 	struct nfp_flower_representor *repr;
 
 	repr = ethdev->data->dev_private;
+
+	repr->repr_stats.ipackets = 0;
+	repr->repr_stats.ibytes = 0;
+	for (i = 0; i < ethdev->data->nb_rx_queues; i++) {
+		repr->repr_stats.ipackets += repr->repr_stats.q_ipackets[i];
+		repr->repr_stats.ibytes += repr->repr_stats.q_ibytes[i];
+	}
+
+	repr->repr_stats.opackets = 0;
+	repr->repr_stats.obytes = 0;
+	for (i = 0; i < ethdev->data->nb_tx_queues; i++) {
+		repr->repr_stats.opackets += repr->repr_stats.q_opackets[i];
+		repr->repr_stats.obytes += repr->repr_stats.q_obytes[i];
+	}
+
 	rte_memcpy(stats, &repr->repr_stats, sizeof(struct rte_eth_stats));
 
 	return 0;
@@ -385,7 +401,6 @@  nfp_flower_repr_rx_burst(void *rx_queue,
 		for (i = 0; i < total_dequeue; i++)
 			data_len += rx_pkts[i]->data_len;
 
-		repr->repr_stats.ipackets += total_dequeue;
 		repr->repr_stats.q_ipackets[rxq->qidx] += total_dequeue;
 		repr->repr_stats.q_ibytes[rxq->qidx] += data_len;
 	}
@@ -434,7 +449,6 @@  nfp_flower_repr_tx_burst(void *tx_queue,
 		for (i = 0; i < sent; i++)
 			data_len += tx_pkts[i]->data_len;
 
-		repr->repr_stats.opackets += sent;
 		repr->repr_stats.q_opackets[txq->qidx] += sent;
 		repr->repr_stats.q_obytes[txq->qidx] += data_len;
 	}