[dpdk-dev,2/2] lib: optimize _xstats_by_ids APIs

Message ID 1512519907-62388-2-git-send-email-elza.mathew@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Elza Mathew Dec. 6, 2017, 12:25 a.m. UTC
  Introduced a check to detect if the stats IDs being
requested are all basic stats IDs. In that case,
ensured that only the basic stats would be retrieved.
Previously, both basic stats and xstats were being
retrieved even if all the IDs were basic stats IDs.

Signed-off-by: Elza Mathew <elza.mathew@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
  

Comments

Daly, Lee Dec. 11, 2017, 1:27 p.m. UTC | #1
> Subject: [dpdk-dev] [PATCH 2/2] lib: optimize _xstats_by_ids APIs
> 
> Introduced a check to detect if the stats IDs being requested are all basic
> stats IDs. In that case, ensured that only the basic stats would be retrieved.
> Previously, both basic stats and xstats were being retrieved even if all the IDs
> were basic stats IDs.
> 
> Signed-off-by: Elza Mathew <elza.mathew@intel.com>

Reviewed-by: Lee Daly <lee.daly@intel.com>
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index dfe8e65..210600d 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1688,7 +1688,9 @@  struct rte_eth_dev *
 {
 	struct rte_eth_xstat_name *xstats_names_copy;
 	unsigned int no_basic_stat_requested = 1;
+	unsigned int no_ext_stat_requested = 1;
 	unsigned int expected_entries;
+	unsigned int basic_count;
 	struct rte_eth_dev *dev;
 	unsigned int i;
 	int ret;
@@ -1696,6 +1698,7 @@  struct rte_eth_dev *
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	basic_count = get_xstats_basic_count(dev);
 	ret = get_xstats_count(port_id);
 	if (ret < 0)
 		return ret;
@@ -1713,7 +1716,6 @@  struct rte_eth_dev *
 		return -EINVAL;
 
 	if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
-		unsigned int basic_count = get_xstats_basic_count(dev);
 		uint64_t ids_copy[size];
 
 		for (i = 0; i < size; i++) {
@@ -1752,8 +1754,22 @@  struct rte_eth_dev *
 		return -ENOMEM;
 	}
 
+	if (ids) {
+		for (i = 0; i < size; i++) {
+			if (ids[i] > basic_count) {
+				no_ext_stat_requested = 0;
+				break;
+			}
+		}
+	}
+
 	/* Fill xstats_names_copy structure */
-	rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
+	if (ids && no_ext_stat_requested) {
+		rte_eth_basic_stats_get_names(dev, xstats_names_copy);
+	} else {
+		rte_eth_xstats_get_names(port_id, xstats_names_copy,
+			expected_entries);
+	}
 
 	/* Filter stats */
 	for (i = 0; i < size; i++) {
@@ -1860,7 +1876,9 @@  struct rte_eth_dev *
 			 uint64_t *values, unsigned int size)
 {
 	unsigned int no_basic_stat_requested = 1;
+	unsigned int no_ext_stat_requested = 1;
 	unsigned int num_xstats_filled;
+	unsigned int basic_count;
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
@@ -1870,6 +1888,7 @@  struct rte_eth_dev *
 	expected_entries = get_xstats_count(port_id);
 	struct rte_eth_xstat xstats[expected_entries];
 	dev = &rte_eth_devices[port_id];
+	basic_count = get_xstats_basic_count(dev);
 
 	/* Return max number of stats if no ids given */
 	if (!ids) {
@@ -1904,8 +1923,21 @@  struct rte_eth_dev *
 					values, size);
 	}
 
+	if (ids) {
+		for (i = 0; i < size; i++) {
+			if (ids[i] > basic_count) {
+				no_ext_stat_requested = 0;
+				break;
+			}
+		}
+	}
+
 	/* Fill the xstats structure */
-	ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+	if (ids && no_ext_stat_requested)
+		ret = rte_eth_basic_stats_get(port_id, xstats);
+	else
+		ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+
 	if (ret < 0)
 		return ret;
 	num_xstats_filled = (unsigned int)ret;