[dpdk-dev,2/3] ethdev: fix xstats get by id APIS

Message ID 20171020000351.57868-2-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

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

Commit Message

Ferruh Yigit Oct. 20, 2017, 12:03 a.m. UTC
  ethdev xstat get by id APIs:
rte_eth_xstats_get_names_by_id()
rte_eth_xstats_get_by_id()

Works on ids calculated as "basic stats + device specific stats"

When an application asking for id less than "basic stats count", it is
indeed asking basic stats nothing specific to device stats.

The dev_ops PMDs implements xstats_get_names_by_id and xstats_get_by_id
works on device specific ids.

This patch adds a check if all stats requested by ids can be provided
via device and if so converts ids to device specific ones.

This conversion wasn't required before commit 8c49d5f1c219, because
_by_id dev_ops were always used to get whole stats instead of specific
ids.

Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Ivan Malov <Ivan.Malov@oktetlabs.ru>
Cc: Harry Van Haaren <harry.van.haaren@intel.com>
Cc: Lee Daly <lee.daly@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)
  

Comments

Ivan Malov Oct. 20, 2017, 12:33 p.m. UTC | #1
On Fri, Oct 20, 2017 at 01:03:50AM +0100, Ferruh Yigit wrote:
> ethdev xstat get by id APIs:
> rte_eth_xstats_get_names_by_id()
> rte_eth_xstats_get_by_id()
> 
> Works on ids calculated as "basic stats + device specific stats"
> 
> When an application asking for id less than "basic stats count", it is
> indeed asking basic stats nothing specific to device stats.
> 
> The dev_ops PMDs implements xstats_get_names_by_id and xstats_get_by_id
> works on device specific ids.
> 
> This patch adds a check if all stats requested by ids can be provided
> via device and if so converts ids to device specific ones.
> 
> This conversion wasn't required before commit 8c49d5f1c219, because
> _by_id dev_ops were always used to get whole stats instead of specific
> ids.
> 
> Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Cc: Ivan Malov <Ivan.Malov@oktetlabs.ru>
> Cc: Harry Van Haaren <harry.van.haaren@intel.com>
> Cc: Lee Daly <lee.daly@intel.com>

The patch looks reasonable.
It solves the problem for me provided that the parts 1/3 and 3/3 are also applied.

Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Tested-by: Ivan Malov <ivan.malov@oktetlabs.ru>
  
Thomas Monjalon Oct. 23, 2017, 10:20 p.m. UTC | #2
20/10/2017 02:03, Ferruh Yigit:
> ethdev xstat get by id APIs:
> rte_eth_xstats_get_names_by_id()
> rte_eth_xstats_get_by_id()
> 
> Works on ids calculated as "basic stats + device specific stats"
> 
> When an application asking for id less than "basic stats count", it is
> indeed asking basic stats nothing specific to device stats.
> 
> The dev_ops PMDs implements xstats_get_names_by_id and xstats_get_by_id
> works on device specific ids.
> 
> This patch adds a check if all stats requested by ids can be provided
> via device and if so converts ids to device specific ones.
> 
> This conversion wasn't required before commit 8c49d5f1c219, because
> _by_id dev_ops were always used to get whole stats instead of specific
> ids.
> 
> Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")

It would be easier to understand if starting with a statement of bug.


> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -1644,6 +1644,7 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
>  	uint64_t *ids)
>  {
>  	struct rte_eth_xstat_name *xstats_names_copy;
> +	unsigned int all_ids_from_pmd = 1;

This variable would be better renamed as "no_basic_stat_requested".

> +			ids_copy[i] = ids[i] - basic_count;

This line may deserve a comment.
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 798855e15..4ed2f6d5f 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1644,6 +1644,7 @@  rte_eth_xstats_get_names_by_id(uint16_t port_id,
 	uint64_t *ids)
 {
 	struct rte_eth_xstat_name *xstats_names_copy;
+	unsigned int all_ids_from_pmd = 1;
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
@@ -1663,9 +1664,23 @@  rte_eth_xstats_get_names_by_id(uint16_t port_id,
 	if (ids && !xstats_names)
 		return -EINVAL;
 
-	if (dev->dev_ops->xstats_get_names_by_id != NULL)
-		return (*dev->dev_ops->xstats_get_names_by_id)(
-				dev, xstats_names, ids, size);
+	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++) {
+			if (ids[i] < basic_count) {
+				all_ids_from_pmd = 0;
+				break;
+			}
+
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (all_ids_from_pmd)
+			return (*dev->dev_ops->xstats_get_names_by_id)(dev,
+					xstats_names, ids_copy, size);
+	}
 
 	/* Retrieve all stats */
 	if (!ids) {
@@ -1772,6 +1787,7 @@  int
 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 			 uint64_t *values, unsigned int size)
 {
+	unsigned int all_ids_from_pmd = 1;
 	unsigned int num_xstats_filled;
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
@@ -1793,9 +1809,23 @@  rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	if (ids && !values)
 		return -EINVAL;
 
-	if (dev->dev_ops->xstats_get_by_id != NULL)
-		return (*dev->dev_ops->xstats_get_by_id)(dev, ids, values,
-			size);
+	if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
+		unsigned int basic_count = get_xstats_basic_count(dev);
+		uint64_t ids_copy[size];
+
+		for (i = 0; i < size; i++) {
+			if (ids[i] < basic_count) {
+				all_ids_from_pmd = 0;
+				break;
+			}
+
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (all_ids_from_pmd)
+			return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
+					values, size);
+	}
 
 	/* Fill the xstats structure */
 	num_xstats_filled = rte_eth_xstats_get(port_id, xstats,