[PATCH v2 4/4] net/null: count all queues
Stephen Hemminger
stephen at networkplumber.org
Wed Apr 2 01:47:29 CEST 2025
If RTE_ETHDEV_QUEUE_STAT_CNTRS is less than the number of queues
in a device, the device should still count packets for all queues.
Add byte counters.
Remove the igb_ prefix which was inherited from other driver.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
drivers/net/null/rte_eth_null.c | 57 ++++++++++++++++-----------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 40ce5c6ed2..8a9b74a03b 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -319,38 +319,39 @@ eth_dev_info(struct rte_eth_dev *dev,
}
static int
-eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
+eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
- unsigned int i, num_stats;
- unsigned long rx_total = 0, tx_total = 0;
- const struct pmd_internals *internal;
+ const struct pmd_internals *internal = dev->data->dev_private;
+ unsigned int i;
- if ((dev == NULL) || (igb_stats == NULL))
- return -EINVAL;
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ uint64_t pkts = internal->rx_null_queues[i].rx_pkts;
+ uint64_t bytes = internal->rx_null_queues[i].rx_bytes;
+
+ stats->ipackets += pkts;
+ stats->ibytes += bytes;
- internal = dev->data->dev_private;
- num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS,
- RTE_MIN(dev->data->nb_rx_queues,
- RTE_DIM(internal->rx_null_queues)));
- for (i = 0; i < num_stats; i++) {
- igb_stats->q_ipackets[i] =
- internal->rx_null_queues[i].rx_pkts;
- rx_total += igb_stats->q_ipackets[i];
+ if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ stats->q_ipackets[i] = pkts;
+ stats->q_ibytes[i] = bytes;
+ }
}
- num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS,
- RTE_MIN(dev->data->nb_tx_queues,
- RTE_DIM(internal->tx_null_queues)));
- for (i = 0; i < num_stats; i++) {
- uint64_t pkts = rte_atomic_load_explicit(&internal->tx_null_queues[i].tx_pkts,
- rte_memory_order_relaxed);
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ const struct null_queue *q = &internal->tx_null_queues[i];
+ uint64_t pkts, bytes;
- igb_stats->q_opackets[i] = pkts;
- tx_total += pkts;
- }
+ pkts = rte_atomic_load_explicit(&q->tx_pkts, rte_memory_order_relaxed);
+ bytes = rte_atomic_load_explicit(&q->tx_bytes, rte_memory_order_relaxed);
+
+ stats->opackets = pkts;
+ stats->obytes = bytes;
- igb_stats->ipackets = rx_total;
- igb_stats->opackets = tx_total;
+ if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ stats->q_opackets[i] = pkts;
+ stats->q_obytes[i] = bytes;
+ }
+ }
return 0;
}
@@ -358,13 +359,9 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
static int
eth_stats_reset(struct rte_eth_dev *dev)
{
+ struct pmd_internals *internal = dev->data->dev_private;
unsigned int i;
- struct pmd_internals *internal;
-
- if (dev == NULL)
- return -EINVAL;
- internal = dev->data->dev_private;
for (i = 0; i < RTE_DIM(internal->rx_null_queues); i++) {
internal->rx_null_queues[i].rx_pkts = 0;
internal->rx_null_queues[i].rx_bytes = 0;
--
2.47.2
More information about the dev
mailing list