[dpdk-dev] [PATCH v6 3/9] ethdev: expose extended error stats

Maryam Tahhan maryam.tahhan at intel.com
Wed Jul 15 15:11:28 CEST 2015


Extend rte_eth_xstats_get to retrieve additional stats from the device
driver as well the ethdev generic stats.

Signed-off-by: Maryam Tahhan <maryam.tahhan at intel.com>
---
 lib/librte_ether/rte_ethdev.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
 mode change 100644 => 100755 lib/librte_ether/rte_ethdev.c

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
old mode 100644
new mode 100755
index ddf3658..7689328
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1661,33 +1661,42 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 {
 	struct rte_eth_stats eth_stats;
 	struct rte_eth_dev *dev;
-	unsigned count, i, q;
+	unsigned count = 0, i, q;
+	signed xcount = 0;
 	uint64_t val, *stats_ptr;
 
 	VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
 	dev = &rte_eth_devices[port_id];
 
-	/* implemented by the driver */
-	if (dev->dev_ops->xstats_get != NULL)
-		return (*dev->dev_ops->xstats_get)(dev, xstats, n);
-
-	/* else, return generic statistics */
+	/* Return generic statistics */
 	count = RTE_NB_STATS;
 	count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
 	count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
-	if (n < count)
-		return count;
 
-	/* now fill the xstats structure */
+	/* implemented by the driver */
+	if (dev->dev_ops->xstats_get != NULL) {
+		/* Retrieve the xstats from the driver at the end of the
+		 * xstats struct.
+		 */
+		xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
+			 (n > count) ? n - count : 0);
 
+		if (xcount < 0)
+			return xcount;
+	}
+
+	if (n < count + xcount)
+		return count + xcount;
+
+	/* now fill the xstats structure */
 	count = 0;
 	rte_eth_stats_get(port_id, &eth_stats);
 
 	/* global stats */
 	for (i = 0; i < RTE_NB_STATS; i++) {
 		stats_ptr = RTE_PTR_ADD(&eth_stats,
-					rte_stats_strings[i].offset);
+				  	rte_stats_strings[i].offset);
 		val = *stats_ptr;
 		snprintf(xstats[count].name, sizeof(xstats[count].name),
 			"%s", rte_stats_strings[i].name);
@@ -1722,7 +1731,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 		}
 	}
 
-	return count;
+	return count + xcount;
 }
 
 /* reset ethdev extended statistics */
-- 
2.4.3



More information about the dev mailing list