DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation
@ 2017-10-20  0:03 Ferruh Yigit
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-20  0:03 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit

Extract into static inline function so that can be used by other
functions.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0b1e92894..798855e15 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1550,6 +1550,22 @@ rte_eth_stats_reset(uint16_t port_id)
 	return 0;
 }
 
+static inline int
+get_xstats_basic_count(struct rte_eth_dev *dev)
+{
+	uint16_t nb_rxqs, nb_txqs;
+	int count;
+
+	nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+	nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+
+	count = RTE_NB_STATS;
+	count += nb_rxqs * RTE_NB_RXQ_STATS;
+	count += nb_txqs * RTE_NB_TXQ_STATS;
+
+	return count;
+}
+
 static int
 get_xstats_count(uint16_t port_id)
 {
@@ -1571,11 +1587,9 @@ get_xstats_count(uint16_t port_id)
 	} else
 		count = 0;
 
-	count += RTE_NB_STATS;
-	count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_RXQ_STATS;
-	count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_TXQ_STATS;
+
+	count += get_xstats_basic_count(dev);
+
 	return count;
 }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS
  2017-10-20  0:03 [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
@ 2017-10-20  0:03 ` Ferruh Yigit
  2017-10-20 12:33   ` Ivan Malov
  2017-10-23 22:20   ` Thomas Monjalon
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats Ferruh Yigit
  2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 2 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-20  0:03 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Ivan Malov, Harry Van Haaren, Lee Daly

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(-)

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,
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats
  2017-10-20  0:03 [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
@ 2017-10-20  0:03 ` Ferruh Yigit
  2017-10-23 22:26   ` Thomas Monjalon
  2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 1 reply; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-20  0:03 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Lee Daly

Some function calls in xstat functions can return negative values
to indicate the error, check return values for those cases.

Coverity issue: 195028, 195026
Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Lee Daly <lee.daly@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 4ed2f6d5f..dc669362a 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1648,11 +1648,16 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	expected_entries = get_xstats_count(port_id);
 	dev = &rte_eth_devices[port_id];
 
+	ret = get_xstats_count(port_id);
+	if (ret < 0)
+		return ret;
+	expected_entries = (unsigned int)ret;
+
 	/* Return max number of stats if no ids given */
 	if (!ids) {
 		if (!xstats_names)
@@ -1792,6 +1797,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	expected_entries = get_xstats_count(port_id);
@@ -1828,8 +1834,10 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	}
 
 	/* Fill the xstats structure */
-	num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
-		expected_entries);
+	ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+	if (ret < 0)
+		return ret;
+	num_xstats_filled = (unsigned int)ret;
 
 	/* Return all stats */
 	if (!ids) {
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
@ 2017-10-20 12:33   ` Ivan Malov
  2017-10-23 22:20   ` Thomas Monjalon
  1 sibling, 0 replies; 14+ messages in thread
From: Ivan Malov @ 2017-10-20 12:33 UTC (permalink / raw)
  To: Ferruh Yigit, dev; +Cc: Thomas Monjalon, Harry Van Haaren, Lee Daly

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>

-- 
Best regards,
Ivan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
  2017-10-20 12:33   ` Ivan Malov
@ 2017-10-23 22:20   ` Thomas Monjalon
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Monjalon @ 2017-10-23 22:20 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Ivan Malov, Harry Van Haaren, Lee Daly

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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats Ferruh Yigit
@ 2017-10-23 22:26   ` Thomas Monjalon
  0 siblings, 0 replies; 14+ messages in thread
From: Thomas Monjalon @ 2017-10-23 22:26 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Lee Daly

Suggested title:
	check more errors in xstats retrieval

20/10/2017 02:03, Ferruh Yigit:
> Some function calls in xstat functions can return negative values
> to indicate the error, check return values for those cases.
> 
> Coverity issue: 195028, 195026
> Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Acked-by: Thomas Monjalon <thomas@monjalon.net>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation
  2017-10-20  0:03 [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
  2017-10-20  0:03 ` [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats Ferruh Yigit
@ 2017-10-23 23:12 ` Ferruh Yigit
  2017-10-23 23:12   ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
                     ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:12 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit

Extract into static inline function so that can be used by other
functions.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0b1e92894..798855e15 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1550,6 +1550,22 @@ rte_eth_stats_reset(uint16_t port_id)
 	return 0;
 }
 
+static inline int
+get_xstats_basic_count(struct rte_eth_dev *dev)
+{
+	uint16_t nb_rxqs, nb_txqs;
+	int count;
+
+	nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+	nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+
+	count = RTE_NB_STATS;
+	count += nb_rxqs * RTE_NB_RXQ_STATS;
+	count += nb_txqs * RTE_NB_TXQ_STATS;
+
+	return count;
+}
+
 static int
 get_xstats_count(uint16_t port_id)
 {
@@ -1571,11 +1587,9 @@ get_xstats_count(uint16_t port_id)
 	} else
 		count = 0;
 
-	count += RTE_NB_STATS;
-	count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_RXQ_STATS;
-	count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_TXQ_STATS;
+
+	count += get_xstats_basic_count(dev);
+
 	return count;
 }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS
  2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
@ 2017-10-23 23:12   ` Ferruh Yigit
  2017-10-23 23:12   ` [dpdk-dev] [PATCH 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
  2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 0 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:12 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Ivan Malov, Harry Van Haaren, Lee Daly

xstats _by_id() APIs are broken because ids known by user sent directly
to the PMDs.

ethdev xstat get by id APIs:
rte_eth_xstats_get_names_by_id() and rte_eth_xstats_get_by_id()
work on ids calculated as "basic stats + extended stats"

When an application asking for id less than "basic stats count", it is
indeed asking basic stats not extended stats.

The dev_ops PMDs implements work on extended stats ids.

This patch adds a check if all requested stats are xstats and if so
converts ids to xstats ids before passing them to PMDs.

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

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

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Tested-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
Cc: Ivan Malov <Ivan.Malov@oktetlabs.ru>
Cc: Harry Van Haaren <harry.van.haaren@intel.com>
Cc: Lee Daly <lee.daly@intel.com>

v2:
* variable renamed, all_ids_from_pmd -> no_basic_stat_requested
* xstats id conversion commented.
---
 lib/librte_ether/rte_ethdev.c | 50 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 798855e15..15ed2df10 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 no_basic_stat_requested = 1;
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
@@ -1663,9 +1664,27 @@ 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) {
+				no_basic_stat_requested = 0;
+				break;
+			}
+
+			/*
+			 * Convert ids to xstats ids that PMD knows.
+			 * ids known by user are basic + extended stats.
+			 */
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (no_basic_stat_requested)
+			return (*dev->dev_ops->xstats_get_names_by_id)(dev,
+					xstats_names, ids_copy, size);
+	}
 
 	/* Retrieve all stats */
 	if (!ids) {
@@ -1772,6 +1791,7 @@ int
 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 			 uint64_t *values, unsigned int size)
 {
+	unsigned int no_basic_stat_requested = 1;
 	unsigned int num_xstats_filled;
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
@@ -1793,9 +1813,27 @@ 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) {
+				no_basic_stat_requested = 0;
+				break;
+			}
+
+			/*
+			 * Convert ids to xstats ids that PMD knows.
+			 * ids known by user are basic + extended stats.
+			 */
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (no_basic_stat_requested)
+			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,
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH 3/3] ethdev: check more errors in xstats retrieval
  2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-23 23:12   ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
@ 2017-10-23 23:12   ` Ferruh Yigit
  2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 0 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:12 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Lee Daly

Some function calls in xstat functions can return negative values
to indicate the error, check return values for those cases.

Coverity issue: 195028, 195026
Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
---
Cc: Lee Daly <lee.daly@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 15ed2df10..0b13a58db 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1648,11 +1648,16 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	expected_entries = get_xstats_count(port_id);
 	dev = &rte_eth_devices[port_id];
 
+	ret = get_xstats_count(port_id);
+	if (ret < 0)
+		return ret;
+	expected_entries = (unsigned int)ret;
+
 	/* Return max number of stats if no ids given */
 	if (!ids) {
 		if (!xstats_names)
@@ -1796,6 +1801,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	expected_entries = get_xstats_count(port_id);
@@ -1836,8 +1842,10 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	}
 
 	/* Fill the xstats structure */
-	num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
-		expected_entries);
+	ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+	if (ret < 0)
+		return ret;
+	num_xstats_filled = (unsigned int)ret;
 
 	/* Return all stats */
 	if (!ids) {
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation
  2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-23 23:12   ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
  2017-10-23 23:12   ` [dpdk-dev] [PATCH 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
@ 2017-10-23 23:15   ` Ferruh Yigit
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
                       ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:15 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit

Extract into static inline function so that can be used by other
functions.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0b1e92894..798855e15 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1550,6 +1550,22 @@ rte_eth_stats_reset(uint16_t port_id)
 	return 0;
 }
 
+static inline int
+get_xstats_basic_count(struct rte_eth_dev *dev)
+{
+	uint16_t nb_rxqs, nb_txqs;
+	int count;
+
+	nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+	nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+
+	count = RTE_NB_STATS;
+	count += nb_rxqs * RTE_NB_RXQ_STATS;
+	count += nb_txqs * RTE_NB_TXQ_STATS;
+
+	return count;
+}
+
 static int
 get_xstats_count(uint16_t port_id)
 {
@@ -1571,11 +1587,9 @@ get_xstats_count(uint16_t port_id)
 	} else
 		count = 0;
 
-	count += RTE_NB_STATS;
-	count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_RXQ_STATS;
-	count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-		 RTE_NB_TXQ_STATS;
+
+	count += get_xstats_basic_count(dev);
+
 	return count;
 }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS
  2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
@ 2017-10-23 23:15     ` Ferruh Yigit
  2017-10-23 23:33       ` Thomas Monjalon
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
  2017-10-24  0:31     ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 1 reply; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:15 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Ivan Malov, Harry Van Haaren, Lee Daly

xstats _by_id() APIs are broken because ids known by user sent directly
to the PMDs.

ethdev xstat get by id APIs:
rte_eth_xstats_get_names_by_id() and rte_eth_xstats_get_by_id()
work on ids calculated as "basic stats + extended stats"

When an application asking for id less than "basic stats count", it is
indeed asking basic stats not extended stats.

The dev_ops PMDs implements work on extended stats ids.

This patch adds a check if all requested stats are xstats and if so
converts ids to xstats ids before passing them to PMDs.

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

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

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Tested-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
Cc: Ivan Malov <Ivan.Malov@oktetlabs.ru>
Cc: Harry Van Haaren <harry.van.haaren@intel.com>
Cc: Lee Daly <lee.daly@intel.com>

v2:
* variable renamed, all_ids_from_pmd -> no_basic_stat_requested
* xstats id conversion commented.
---
 lib/librte_ether/rte_ethdev.c | 50 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 798855e15..15ed2df10 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 no_basic_stat_requested = 1;
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
@@ -1663,9 +1664,27 @@ 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) {
+				no_basic_stat_requested = 0;
+				break;
+			}
+
+			/*
+			 * Convert ids to xstats ids that PMD knows.
+			 * ids known by user are basic + extended stats.
+			 */
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (no_basic_stat_requested)
+			return (*dev->dev_ops->xstats_get_names_by_id)(dev,
+					xstats_names, ids_copy, size);
+	}
 
 	/* Retrieve all stats */
 	if (!ids) {
@@ -1772,6 +1791,7 @@ int
 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 			 uint64_t *values, unsigned int size)
 {
+	unsigned int no_basic_stat_requested = 1;
 	unsigned int num_xstats_filled;
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
@@ -1793,9 +1813,27 @@ 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) {
+				no_basic_stat_requested = 0;
+				break;
+			}
+
+			/*
+			 * Convert ids to xstats ids that PMD knows.
+			 * ids known by user are basic + extended stats.
+			 */
+			ids_copy[i] = ids[i] - basic_count;
+		}
+
+		if (no_basic_stat_requested)
+			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,
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [dpdk-dev] [PATCH v2 3/3] ethdev: check more errors in xstats retrieval
  2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
@ 2017-10-23 23:15     ` Ferruh Yigit
  2017-10-24  0:31     ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2 siblings, 0 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-23 23:15 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Ferruh Yigit, Lee Daly

Some function calls in xstat functions can return negative values
to indicate the error, check return values for those cases.

Coverity issue: 195028, 195026
Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
---
Cc: Lee Daly <lee.daly@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 15ed2df10..0b13a58db 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1648,11 +1648,16 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
 	unsigned int expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	expected_entries = get_xstats_count(port_id);
 	dev = &rte_eth_devices[port_id];
 
+	ret = get_xstats_count(port_id);
+	if (ret < 0)
+		return ret;
+	expected_entries = (unsigned int)ret;
+
 	/* Return max number of stats if no ids given */
 	if (!ids) {
 		if (!xstats_names)
@@ -1796,6 +1801,7 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	uint16_t expected_entries;
 	struct rte_eth_dev *dev;
 	unsigned int i;
+	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	expected_entries = get_xstats_count(port_id);
@@ -1836,8 +1842,10 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	}
 
 	/* Fill the xstats structure */
-	num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
-		expected_entries);
+	ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+	if (ret < 0)
+		return ret;
+	num_xstats_filled = (unsigned int)ret;
 
 	/* Return all stats */
 	if (!ids) {
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
@ 2017-10-23 23:33       ` Thomas Monjalon
  0 siblings, 0 replies; 14+ messages in thread
From: Thomas Monjalon @ 2017-10-23 23:33 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Ivan Malov, Harry Van Haaren, Lee Daly

24/10/2017 01:15, Ferruh Yigit:
> xstats _by_id() APIs are broken because ids known by user sent directly
> to the PMDs.
> 
> ethdev xstat get by id APIs:
> rte_eth_xstats_get_names_by_id() and rte_eth_xstats_get_by_id()
> work on ids calculated as "basic stats + extended stats"
> 
> When an application asking for id less than "basic stats count", it is
> indeed asking basic stats not extended stats.
> 
> The dev_ops PMDs implements work on extended stats ids.
> 
> This patch adds a check if all requested stats are xstats and if so
> converts ids to xstats ids before passing them to PMDs.
> 
> This conversion wasn't required before commit 8c49d5f1c219, because
> _by_id dev_ops were always used to get whole stats via NULL ids.
> 
> Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id")
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> Tested-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> ---
> Cc: Ivan Malov <Ivan.Malov@oktetlabs.ru>
> Cc: Harry Van Haaren <harry.van.haaren@intel.com>
> Cc: Lee Daly <lee.daly@intel.com>
> 
> v2:
> * variable renamed, all_ids_from_pmd -> no_basic_stat_requested
> * xstats id conversion commented.

A lot more clear :)
Thanks

Acked-by: Thomas Monjalon <thomas@monjalon.net>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation
  2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
  2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
@ 2017-10-24  0:31     ` Ferruh Yigit
  2 siblings, 0 replies; 14+ messages in thread
From: Ferruh Yigit @ 2017-10-24  0:31 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On 10/23/2017 4:15 PM, Ferruh Yigit wrote:
> Extract into static inline function so that can be used by other
> functions.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Series applied to dpdk-next-net/master, thanks.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-10-24  0:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-20  0:03 [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
2017-10-20  0:03 ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
2017-10-20 12:33   ` Ivan Malov
2017-10-23 22:20   ` Thomas Monjalon
2017-10-20  0:03 ` [dpdk-dev] [PATCH 3/3] ethdev: fix negative return values in xstats Ferruh Yigit
2017-10-23 22:26   ` Thomas Monjalon
2017-10-23 23:12 ` [dpdk-dev] [PATCH 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
2017-10-23 23:12   ` [dpdk-dev] [PATCH 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
2017-10-23 23:12   ` [dpdk-dev] [PATCH 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
2017-10-23 23:15   ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit
2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS Ferruh Yigit
2017-10-23 23:33       ` Thomas Monjalon
2017-10-23 23:15     ` [dpdk-dev] [PATCH v2 3/3] ethdev: check more errors in xstats retrieval Ferruh Yigit
2017-10-24  0:31     ` [dpdk-dev] [PATCH v2 1/3] ethdev: extract xstat basic stat count calculation Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).