[dpdk-dev,RFC,v1,2/3] drivers/net/ixgbe: change xstats to use integers

Message ID 1460731462-21229-3-git-send-email-remy.horton@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Remy Horton April 15, 2016, 2:44 p.m. UTC
  Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 87 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 78 insertions(+), 9 deletions(-)
  

Comments

David Harton April 29, 2016, 1:43 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Remy Horton
> Sent: Friday, April 15, 2016 10:44 AM
> To: dev@dpdk.org; Helin Zhang <helin.zhang@intel.com>
> Subject: [dpdk-dev] [RFC PATCH v1 2/3] drivers/net/ixgbe: change xstats to
> use integers
> 
> Signed-off-by: Remy Horton <remy.horton@intel.com>
> ---
>  drivers/net/ixgbe/ixgbe_ethdev.c | 87
> +++++++++++++++++++++++++++++++++++-----
>  1 file changed, 78 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c
> b/drivers/net/ixgbe/ixgbe_ethdev.c
> index 3f1ebc1..4d31fe9 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> @@ -179,6 +179,10 @@ static int ixgbevf_dev_xstats_get(struct rte_eth_dev
> *dev,
>  				  struct rte_eth_xstats *xstats, unsigned n);
>  static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
>  static void ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
> +static int ixgbe_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit);
> +static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit);
>  static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
>  					     uint16_t queue_id,
>  					     uint8_t stat_idx,
> @@ -466,6 +470,7 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
>  	.xstats_get           = ixgbe_dev_xstats_get,
>  	.stats_reset          = ixgbe_dev_stats_reset,
>  	.xstats_reset         = ixgbe_dev_xstats_reset,
> +	.xstats_names         = ixgbe_dev_xstats_names,
>  	.queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
>  	.dev_infos_get        = ixgbe_dev_info_get,
>  	.dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
> @@ -555,6 +560,7 @@ static const struct eth_dev_ops ixgbevf_eth_dev_ops =
> {
>  	.xstats_get           = ixgbevf_dev_xstats_get,
>  	.stats_reset          = ixgbevf_dev_stats_reset,
>  	.xstats_reset         = ixgbevf_dev_stats_reset,
> +	.xstats_names         = ixgbevf_dev_xstats_names,
>  	.dev_close            = ixgbevf_dev_close,
>  	.allmulticast_enable  = ixgbevf_dev_allmulticast_enable,
>  	.allmulticast_disable = ixgbevf_dev_allmulticast_disable,
> @@ -2698,6 +2704,76 @@ ixgbe_xstats_calc_num(void) {
>  		(IXGBE_NB_TXQ_PRIO_STATS * 8);
>  }
> 
> +static int ixgbe_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
> +{
> +	const unsigned cnt_stats = ixgbe_xstats_calc_num();
> +	unsigned stat, i, count, offset;
> +
> +	if (ptr_names != NULL) {
> +		count = 0;
> +		offset = 0;
> +
> +		/* Note: limit >= cnt_stats checked upstream
> +		 * in rte_eth_xstats_names()
> +		 */
> +
> +		/* Extended stats from ixgbe_hw_stats */
> +		for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
> +			snprintf(ptr_names[count].name,
> +				sizeof(ptr_names[count].name),
> +				"%s",
> +				rte_ixgbe_stats_strings[i].name);
> +			count++;
> +			offset += RTE_ETH_XSTATS_NAME_SIZE;
> +		}
> +
> +		/* RX Priority Stats */
> +		for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
> +			for (i = 0; i < 8; i++) {

8 seems magical.  Is there a constant somewhere that can be used?

> +				snprintf(ptr_names[count].name,
> +					sizeof(ptr_names[count].name),
> +					"rx_priority%u_%s", i,
> +					rte_ixgbe_rxq_strings[stat].name);
> +				count++;
> +				offset += RTE_ETH_XSTATS_NAME_SIZE;
> +			}
> +		}
> +
> +		/* TX Priority Stats */
> +		for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
> +			for (i = 0; i < 8; i++) {

Same magic number.

> +				snprintf(ptr_names[count].name,
> +					sizeof(ptr_names[count].name),
> +					"tx_priority%u_%s", i,
> +					rte_ixgbe_txq_strings[stat].name);
> +				count++;
> +				offset += RTE_ETH_XSTATS_NAME_SIZE;
> +			}
> +		}
> +		/* FIXME: Debugging check */

Just a reminder to cleanup.

> +		if (cnt_stats != count)
> +			return -EIO;
> +	}
> +	return cnt_stats;
> +}
> +
> +static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
> +{
> +	unsigned i;
> +
> +	if (limit < IXGBEVF_NB_XSTATS)

Think this check has to be removed since rte_eth_xstats_count() calls with 
limit == 0.

> +		return -ENOMEM;
> +
> +	if (ptr_names != NULL)
> +		for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
> +			snprintf(ptr_names[i].name,
> +				sizeof(ptr_names[i].name),
> +				"%s", rte_ixgbevf_stats_strings[i].name);
> +	return IXGBEVF_NB_XSTATS;
> +}
> +
>  static int
>  ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats
> *xstats,
>  					 unsigned n)
> @@ -2731,8 +2807,6 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct
> rte_eth_xstats *xstats,
>  	/* Extended stats from ixgbe_hw_stats */
>  	count = 0;
>  	for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
> -		snprintf(xstats[count].name, sizeof(xstats[count].name), "%s",
> -			 rte_ixgbe_stats_strings[i].name);

Forgot to add key/id.
Also, same name comment as above.

>  		xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
>  				rte_ixgbe_stats_strings[i].offset);
>  		count++;
> @@ -2741,9 +2815,6 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct
> rte_eth_xstats *xstats,
>  	/* RX Priority Stats */
>  	for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
>  		for (i = 0; i < 8; i++) {
> -			snprintf(xstats[count].name, sizeof(xstats[count].name),
> -				 "rx_priority%u_%s", i,
> -				 rte_ixgbe_rxq_strings[stat].name);

Add key/id...terminate name.

>  			xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
>  					rte_ixgbe_rxq_strings[stat].offset +
>  					(sizeof(uint64_t) * i));
> @@ -2754,16 +2825,14 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
> struct rte_eth_xstats *xstats,
>  	/* TX Priority Stats */
>  	for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
>  		for (i = 0; i < 8; i++) {
> -			snprintf(xstats[count].name, sizeof(xstats[count].name),
> -				 "tx_priority%u_%s", i,
> -				 rte_ixgbe_txq_strings[stat].name);

Add key/id...terminate name.

>  			xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
>  					rte_ixgbe_txq_strings[stat].offset +
>  					(sizeof(uint64_t) * i));
>  			count++;
>  		}
>  	}
> -
> +	for (i = 0; i < count; i++)
> +		xstats[i].key = i;

Suggest doing this in the loops above to be consistent with pass-thru
and likely saves some instructions.

Regards,
Dave

>  	return count;
>  }
> 
> --
> 2.5.5
  
Remy Horton May 3, 2016, 12:22 p.m. UTC | #2
On 29/04/2016 14:43, David Harton (dharton) wrote:
[..]
>> +		/* RX Priority Stats */
>> +		for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
>> +			for (i = 0; i < 8; i++) {
>
> 8 seems magical.  Is there a constant somewhere that can be used?

Not that I'm aware of. I've made it a #define as a small cleanup.


>> +static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
>> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
>> +{
>> +	unsigned i;
>> +
>> +	if (limit < IXGBEVF_NB_XSTATS)
>
> Think this check has to be removed since rte_eth_xstats_count() calls with
> limit == 0.

Well spotted. It should only error-out if ptr_names is non-NULL.

As an aside, I am wondering whether getting stats counts should itself 
be a seperate driver hook.


..Remy
  
David Harton May 3, 2016, 1:40 p.m. UTC | #3
> -----Original Message-----
> From: Remy Horton [mailto:remy.horton@intel.com]
> Sent: Tuesday, May 03, 2016 8:23 AM
> To: David Harton (dharton) <dharton@cisco.com>; dev@dpdk.org; Helin Zhang
> <helin.zhang@intel.com>
> Subject: Re: [dpdk-dev] [RFC PATCH v1 2/3] drivers/net/ixgbe: change
> xstats to use integers
> 
> 
> On 29/04/2016 14:43, David Harton (dharton) wrote:
> [..]
> >> +		/* RX Priority Stats */
> >> +		for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
> >> +			for (i = 0; i < 8; i++) {
> >
> > 8 seems magical.  Is there a constant somewhere that can be used?
> 
> Not that I'm aware of. I've made it a #define as a small cleanup.
> 
> 
> >> +static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev
> *dev,
> >> +	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
> >> +{
> >> +	unsigned i;
> >> +
> >> +	if (limit < IXGBEVF_NB_XSTATS)
> >
> > Think this check has to be removed since rte_eth_xstats_count() calls
> > with limit == 0.
> 
> Well spotted. It should only error-out if ptr_names is non-NULL.
> 
> As an aside, I am wondering whether getting stats counts should itself be
> a seperate driver hook.

I personally think it would be cleaner.  Bug, I can also see the argument of keeping
the vector table smaller and would conceded to others that felt strongly about it.

I do really like having a separate external API to the user.  A user should explicitly
ask for the count.

Cheers,
Dave

> 
> 
> ..Remy
  

Patch

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 3f1ebc1..4d31fe9 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -179,6 +179,10 @@  static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
 				  struct rte_eth_xstats *xstats, unsigned n);
 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
 static void ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
+static int ixgbe_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit);
+static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit);
 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
 					     uint16_t queue_id,
 					     uint8_t stat_idx,
@@ -466,6 +470,7 @@  static const struct eth_dev_ops ixgbe_eth_dev_ops = {
 	.xstats_get           = ixgbe_dev_xstats_get,
 	.stats_reset          = ixgbe_dev_stats_reset,
 	.xstats_reset         = ixgbe_dev_xstats_reset,
+	.xstats_names         = ixgbe_dev_xstats_names,
 	.queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
 	.dev_infos_get        = ixgbe_dev_info_get,
 	.dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
@@ -555,6 +560,7 @@  static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
 	.xstats_get           = ixgbevf_dev_xstats_get,
 	.stats_reset          = ixgbevf_dev_stats_reset,
 	.xstats_reset         = ixgbevf_dev_stats_reset,
+	.xstats_names         = ixgbevf_dev_xstats_names,
 	.dev_close            = ixgbevf_dev_close,
 	.allmulticast_enable  = ixgbevf_dev_allmulticast_enable,
 	.allmulticast_disable = ixgbevf_dev_allmulticast_disable,
@@ -2698,6 +2704,76 @@  ixgbe_xstats_calc_num(void) {
 		(IXGBE_NB_TXQ_PRIO_STATS * 8);
 }
 
+static int ixgbe_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
+{
+	const unsigned cnt_stats = ixgbe_xstats_calc_num();
+	unsigned stat, i, count, offset;
+
+	if (ptr_names != NULL) {
+		count = 0;
+		offset = 0;
+
+		/* Note: limit >= cnt_stats checked upstream
+		 * in rte_eth_xstats_names()
+		 */
+
+		/* Extended stats from ixgbe_hw_stats */
+		for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
+			snprintf(ptr_names[count].name,
+				sizeof(ptr_names[count].name),
+				"%s",
+				rte_ixgbe_stats_strings[i].name);
+			count++;
+			offset += RTE_ETH_XSTATS_NAME_SIZE;
+		}
+
+		/* RX Priority Stats */
+		for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
+			for (i = 0; i < 8; i++) {
+				snprintf(ptr_names[count].name,
+					sizeof(ptr_names[count].name),
+					"rx_priority%u_%s", i,
+					rte_ixgbe_rxq_strings[stat].name);
+				count++;
+				offset += RTE_ETH_XSTATS_NAME_SIZE;
+			}
+		}
+
+		/* TX Priority Stats */
+		for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
+			for (i = 0; i < 8; i++) {
+				snprintf(ptr_names[count].name,
+					sizeof(ptr_names[count].name),
+					"tx_priority%u_%s", i,
+					rte_ixgbe_txq_strings[stat].name);
+				count++;
+				offset += RTE_ETH_XSTATS_NAME_SIZE;
+			}
+		}
+		/* FIXME: Debugging check */
+		if (cnt_stats != count)
+			return -EIO;
+	}
+	return cnt_stats;
+}
+
+static int ixgbevf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+	struct rte_eth_xstats_name *ptr_names, __rte_unused unsigned limit)
+{
+	unsigned i;
+
+	if (limit < IXGBEVF_NB_XSTATS)
+		return -ENOMEM;
+
+	if (ptr_names != NULL)
+		for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
+			snprintf(ptr_names[i].name,
+				sizeof(ptr_names[i].name),
+				"%s", rte_ixgbevf_stats_strings[i].name);
+	return IXGBEVF_NB_XSTATS;
+}
+
 static int
 ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
 					 unsigned n)
@@ -2731,8 +2807,6 @@  ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
 	/* Extended stats from ixgbe_hw_stats */
 	count = 0;
 	for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
-		snprintf(xstats[count].name, sizeof(xstats[count].name), "%s",
-			 rte_ixgbe_stats_strings[i].name);
 		xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
 				rte_ixgbe_stats_strings[i].offset);
 		count++;
@@ -2741,9 +2815,6 @@  ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
 	/* RX Priority Stats */
 	for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
 		for (i = 0; i < 8; i++) {
-			snprintf(xstats[count].name, sizeof(xstats[count].name),
-				 "rx_priority%u_%s", i,
-				 rte_ixgbe_rxq_strings[stat].name);
 			xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
 					rte_ixgbe_rxq_strings[stat].offset +
 					(sizeof(uint64_t) * i));
@@ -2754,16 +2825,14 @@  ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
 	/* TX Priority Stats */
 	for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
 		for (i = 0; i < 8; i++) {
-			snprintf(xstats[count].name, sizeof(xstats[count].name),
-				 "tx_priority%u_%s", i,
-				 rte_ixgbe_txq_strings[stat].name);
 			xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
 					rte_ixgbe_txq_strings[stat].offset +
 					(sizeof(uint64_t) * i));
 			count++;
 		}
 	}
-
+	for (i = 0; i < count; i++)
+		xstats[i].key = i;
 	return count;
 }