DPDK patches and discussions
 help / color / mirror / Atom feed
* Re: [dpdk-dev] [PATCH] event/dsw: add by-name xstats retrieval
@ 2020-01-14 15:03 Jerin Jacob Kollanukkaran
  0 siblings, 0 replies; 2+ messages in thread
From: Jerin Jacob Kollanukkaran @ 2020-01-14 15:03 UTC (permalink / raw)
  To: Mattias Rönnblom, dev; +Cc: niclas.storm



> -----Original Message-----
> From: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> Sent: Friday, December 13, 2019 12:14 AM
> To: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>
> Cc: niclas.storm@ericsson.com; Mattias Rönnblom
> <mattias.ronnblom@ericsson.com>
> Subject: [EXT] [PATCH] event/dsw: add by-name xstats retrieval
> 
> Implement rte_event_dev_stats_by_name().
> 
> Suggested-by: Niclas Storm <niclas.storm@ericsson.com>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>


Applied to dpdk-next-eventdev/master. Thanks.


> ---
>  drivers/event/dsw/dsw_xstats.c     | 144 +++++++++++++++++++++--------
>  drivers/event/sw/sw_evdev_xstats.c |   2 -
>  2 files changed, 108 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/event/dsw/dsw_xstats.c b/drivers/event/dsw/dsw_xstats.c
> index bf2eec527..c3f5db89c 100644
> --- a/drivers/event/dsw/dsw_xstats.c
> +++ b/drivers/event/dsw/dsw_xstats.c
> @@ -1,5 +1,5 @@
>  /* SPDX-License-Identifier: BSD-3-Clause
> - * Copyright(c) 2018 Ericsson AB
> + * Copyright(c) 2018-2019 Ericsson AB
>   */
> 
>  #include "dsw_evdev.h"
> @@ -150,54 +150,81 @@ static struct dsw_xstats_port dsw_port_xstats[] = {
>  	  false }
>  };
> 
> -static int
> -dsw_xstats_dev_get_names(struct rte_event_dev_xstats_name
> *xstats_names,
> -			 unsigned int *ids, unsigned int size)
> +typedef
> +void (*dsw_xstats_foreach_fn)(const char *xstats_name,
> +			      enum rte_event_dev_xstats_mode mode,
> +			      uint8_t queue_port_id, unsigned int xstats_id,
> +			      void *data);
> +
> +static void
> +dsw_xstats_dev_foreach(dsw_xstats_foreach_fn fn, void *fn_data)
>  {
>  	unsigned int i;
> 
> -	for (i = 0; i < RTE_DIM(dsw_dev_xstats) && i < size; i++) {
> -		ids[i] = i;
> -		strcpy(xstats_names[i].name, dsw_dev_xstats[i].name);
> -	}
> -
> -	return i;
> +	for (i = 0; i < RTE_DIM(dsw_dev_xstats); i++)
> +		fn(dsw_dev_xstats[i].name, RTE_EVENT_DEV_XSTATS_DEVICE,
> 0,
> +		   i, fn_data);
>  }
> 
> -static int
> -dsw_xstats_port_get_names(struct dsw_evdev *dsw, uint8_t port_id,
> -			  struct rte_event_dev_xstats_name *xstats_names,
> -			  unsigned int *ids, unsigned int size)
> +static void
> +dsw_xstats_port_foreach(struct dsw_evdev *dsw, uint8_t port_id,
> +			dsw_xstats_foreach_fn fn, void *fn_data)
>  {
> -	uint8_t queue_id = 0;
> -	unsigned int id_idx;
> +	uint8_t queue_id;
>  	unsigned int stat_idx;
> 
> -	for (id_idx = 0, stat_idx = 0;
> -	     id_idx < size && stat_idx < RTE_DIM(dsw_port_xstats);
> -	     id_idx++) {
> +	for (stat_idx = 0, queue_id = 0;
> +	     stat_idx < RTE_DIM(dsw_port_xstats);) {
>  		struct dsw_xstats_port *xstat = &dsw_port_xstats[stat_idx];
> +		char xstats_name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
> +		unsigned int xstats_id;
> 
>  		if (xstat->per_queue) {
> -			ids[id_idx] = DSW_XSTATS_ID_CREATE(stat_idx,
> queue_id);
> -			snprintf(xstats_names[id_idx].name,
> -				 RTE_EVENT_DEV_XSTATS_NAME_SIZE,
> +			xstats_id = DSW_XSTATS_ID_CREATE(stat_idx,
> queue_id);
> +			snprintf(xstats_name, sizeof(xstats_name),
>  				 dsw_port_xstats[stat_idx].name_fmt, port_id,
>  				 queue_id);
>  			queue_id++;
>  		} else {
> -			ids[id_idx] = stat_idx;
> -			snprintf(xstats_names[id_idx].name,
> -				 RTE_EVENT_DEV_XSTATS_NAME_SIZE,
> +			xstats_id = stat_idx;
> +			snprintf(xstats_name, sizeof(xstats_name),
>  				 dsw_port_xstats[stat_idx].name_fmt,
> port_id);
>  		}
> 
> +		fn(xstats_name, RTE_EVENT_DEV_XSTATS_PORT, port_id,
> +		   xstats_id, fn_data);
> +
>  		if (!(xstat->per_queue && queue_id < dsw->num_queues)) {
>  			stat_idx++;
>  			queue_id = 0;
>  		}
>  	}
> -	return id_idx;
> +}
> +
> +struct store_ctx {
> +	struct rte_event_dev_xstats_name *names;
> +	unsigned int *ids;
> +	unsigned int count;
> +	unsigned int capacity;
> +};
> +
> +static void
> +dsw_xstats_store_stat(const char *xstats_name,
> +		      enum rte_event_dev_xstats_mode mode,
> +		      uint8_t queue_port_id, unsigned int xstats_id,
> +		      void *data)
> +{
> +	struct store_ctx *ctx = data;
> +
> +	RTE_SET_USED(mode);
> +	RTE_SET_USED(queue_port_id);
> +
> +	if (ctx->count < ctx->capacity) {
> +		strcpy(ctx->names[ctx->count].name, xstats_name);
> +		ctx->ids[ctx->count] = xstats_id;
> +	}
> +
> +	ctx->count++;
>  }
> 
>  int
> @@ -205,16 +232,24 @@ dsw_xstats_get_names(const struct rte_eventdev
> *dev,
>  		     enum rte_event_dev_xstats_mode mode,
>  		     uint8_t queue_port_id,
>  		     struct rte_event_dev_xstats_name *xstats_names,
> -		     unsigned int *ids, unsigned int size)
> +		     unsigned int *ids, unsigned int capacity)
>  {
>  	struct dsw_evdev *dsw = dsw_pmd_priv(dev);
> 
> +	struct store_ctx ctx = {
> +		.names = xstats_names,
> +		.ids = ids,
> +		.capacity = capacity
> +	};
> +
>  	switch (mode) {
>  	case RTE_EVENT_DEV_XSTATS_DEVICE:
> -		return dsw_xstats_dev_get_names(xstats_names, ids, size);
> +		dsw_xstats_dev_foreach(dsw_xstats_store_stat, &ctx);
> +		return ctx.count;
>  	case RTE_EVENT_DEV_XSTATS_PORT:
> -		return dsw_xstats_port_get_names(dsw, queue_port_id,
> -						 xstats_names, ids, size);
> +		dsw_xstats_port_foreach(dsw, queue_port_id,
> +					dsw_xstats_store_stat, &ctx);
> +		return ctx.count;
>  	case RTE_EVENT_DEV_XSTATS_QUEUE:
>  		return 0;
>  	default:
> @@ -278,11 +313,48 @@ dsw_xstats_get(const struct rte_eventdev *dev,
>  	return 0;
>  }
> 
> -uint64_t dsw_xstats_get_by_name(const struct rte_eventdev *dev,
> -				const char *name, unsigned int *id)
> +struct find_ctx {
> +	const struct rte_eventdev *dev;
> +	const char *name;
> +	unsigned int *id;
> +	uint64_t value;
> +};
> +
> +static void
> +dsw_xstats_find_stat(const char *xstats_name,
> +		     enum rte_event_dev_xstats_mode mode,
> +		     uint8_t queue_port_id, unsigned int xstats_id,
> +		     void *data)
>  {
> -	RTE_SET_USED(dev);
> -	RTE_SET_USED(name);
> -	RTE_SET_USED(id);
> -	return 0;
> +	struct find_ctx *ctx = data;
> +
> +	if (strcmp(ctx->name, xstats_name) == 0) {
> +		if (ctx->id != NULL)
> +			*ctx->id = xstats_id;
> +		dsw_xstats_get(ctx->dev, mode, queue_port_id, &xstats_id,
> +			       &ctx->value, 1);
> +	}
> +}
> +
> +uint64_t
> +dsw_xstats_get_by_name(const struct rte_eventdev *dev, const char *name,
> +		       unsigned int *id)
> +{
> +	struct dsw_evdev *dsw = dsw_pmd_priv(dev);
> +	uint16_t port_id;
> +
> +	struct find_ctx ctx = {
> +		.dev = dev,
> +		.name = name,
> +		.id = id,
> +		.value = -EINVAL
> +	};
> +
> +	dsw_xstats_dev_foreach(dsw_xstats_find_stat, &ctx);
> +
> +	for (port_id = 0; port_id < dsw->num_ports; port_id++)
> +		dsw_xstats_port_foreach(dsw, port_id, dsw_xstats_find_stat,
> +					&ctx);
> +
> +	return ctx.value;
>  }
> diff --git a/drivers/event/sw/sw_evdev_xstats.c
> b/drivers/event/sw/sw_evdev_xstats.c
> index 90664903b..02f787418 100644
> --- a/drivers/event/sw/sw_evdev_xstats.c
> +++ b/drivers/event/sw/sw_evdev_xstats.c
> @@ -391,8 +391,6 @@ sw_xstats_get_names(const struct rte_eventdev *dev,
>  	const struct sw_evdev *sw = sw_pmd_priv_const(dev);
>  	unsigned int i;
>  	unsigned int xidx = 0;
> -	RTE_SET_USED(mode);
> -	RTE_SET_USED(queue_port_id);
> 
>  	uint32_t xstats_mode_count = 0;
>  	uint32_t start_offset = 0;
> --
> 2.17.1


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

* [dpdk-dev] [PATCH] event/dsw: add by-name xstats retrieval
@ 2019-12-12 18:44 Mattias Rönnblom
  0 siblings, 0 replies; 2+ messages in thread
From: Mattias Rönnblom @ 2019-12-12 18:44 UTC (permalink / raw)
  To: dev, jerinj; +Cc: niclas.storm, Mattias Rönnblom

Implement rte_event_dev_stats_by_name().

Suggested-by: Niclas Storm <niclas.storm@ericsson.com>
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 drivers/event/dsw/dsw_xstats.c     | 144 +++++++++++++++++++++--------
 drivers/event/sw/sw_evdev_xstats.c |   2 -
 2 files changed, 108 insertions(+), 38 deletions(-)

diff --git a/drivers/event/dsw/dsw_xstats.c b/drivers/event/dsw/dsw_xstats.c
index bf2eec527..c3f5db89c 100644
--- a/drivers/event/dsw/dsw_xstats.c
+++ b/drivers/event/dsw/dsw_xstats.c
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Ericsson AB
+ * Copyright(c) 2018-2019 Ericsson AB
  */
 
 #include "dsw_evdev.h"
@@ -150,54 +150,81 @@ static struct dsw_xstats_port dsw_port_xstats[] = {
 	  false }
 };
 
-static int
-dsw_xstats_dev_get_names(struct rte_event_dev_xstats_name *xstats_names,
-			 unsigned int *ids, unsigned int size)
+typedef
+void (*dsw_xstats_foreach_fn)(const char *xstats_name,
+			      enum rte_event_dev_xstats_mode mode,
+			      uint8_t queue_port_id, unsigned int xstats_id,
+			      void *data);
+
+static void
+dsw_xstats_dev_foreach(dsw_xstats_foreach_fn fn, void *fn_data)
 {
 	unsigned int i;
 
-	for (i = 0; i < RTE_DIM(dsw_dev_xstats) && i < size; i++) {
-		ids[i] = i;
-		strcpy(xstats_names[i].name, dsw_dev_xstats[i].name);
-	}
-
-	return i;
+	for (i = 0; i < RTE_DIM(dsw_dev_xstats); i++)
+		fn(dsw_dev_xstats[i].name, RTE_EVENT_DEV_XSTATS_DEVICE, 0,
+		   i, fn_data);
 }
 
-static int
-dsw_xstats_port_get_names(struct dsw_evdev *dsw, uint8_t port_id,
-			  struct rte_event_dev_xstats_name *xstats_names,
-			  unsigned int *ids, unsigned int size)
+static void
+dsw_xstats_port_foreach(struct dsw_evdev *dsw, uint8_t port_id,
+			dsw_xstats_foreach_fn fn, void *fn_data)
 {
-	uint8_t queue_id = 0;
-	unsigned int id_idx;
+	uint8_t queue_id;
 	unsigned int stat_idx;
 
-	for (id_idx = 0, stat_idx = 0;
-	     id_idx < size && stat_idx < RTE_DIM(dsw_port_xstats);
-	     id_idx++) {
+	for (stat_idx = 0, queue_id = 0;
+	     stat_idx < RTE_DIM(dsw_port_xstats);) {
 		struct dsw_xstats_port *xstat = &dsw_port_xstats[stat_idx];
+		char xstats_name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
+		unsigned int xstats_id;
 
 		if (xstat->per_queue) {
-			ids[id_idx] = DSW_XSTATS_ID_CREATE(stat_idx, queue_id);
-			snprintf(xstats_names[id_idx].name,
-				 RTE_EVENT_DEV_XSTATS_NAME_SIZE,
+			xstats_id = DSW_XSTATS_ID_CREATE(stat_idx, queue_id);
+			snprintf(xstats_name, sizeof(xstats_name),
 				 dsw_port_xstats[stat_idx].name_fmt, port_id,
 				 queue_id);
 			queue_id++;
 		} else {
-			ids[id_idx] = stat_idx;
-			snprintf(xstats_names[id_idx].name,
-				 RTE_EVENT_DEV_XSTATS_NAME_SIZE,
+			xstats_id = stat_idx;
+			snprintf(xstats_name, sizeof(xstats_name),
 				 dsw_port_xstats[stat_idx].name_fmt, port_id);
 		}
 
+		fn(xstats_name, RTE_EVENT_DEV_XSTATS_PORT, port_id,
+		   xstats_id, fn_data);
+
 		if (!(xstat->per_queue && queue_id < dsw->num_queues)) {
 			stat_idx++;
 			queue_id = 0;
 		}
 	}
-	return id_idx;
+}
+
+struct store_ctx {
+	struct rte_event_dev_xstats_name *names;
+	unsigned int *ids;
+	unsigned int count;
+	unsigned int capacity;
+};
+
+static void
+dsw_xstats_store_stat(const char *xstats_name,
+		      enum rte_event_dev_xstats_mode mode,
+		      uint8_t queue_port_id, unsigned int xstats_id,
+		      void *data)
+{
+	struct store_ctx *ctx = data;
+
+	RTE_SET_USED(mode);
+	RTE_SET_USED(queue_port_id);
+
+	if (ctx->count < ctx->capacity) {
+		strcpy(ctx->names[ctx->count].name, xstats_name);
+		ctx->ids[ctx->count] = xstats_id;
+	}
+
+	ctx->count++;
 }
 
 int
@@ -205,16 +232,24 @@ dsw_xstats_get_names(const struct rte_eventdev *dev,
 		     enum rte_event_dev_xstats_mode mode,
 		     uint8_t queue_port_id,
 		     struct rte_event_dev_xstats_name *xstats_names,
-		     unsigned int *ids, unsigned int size)
+		     unsigned int *ids, unsigned int capacity)
 {
 	struct dsw_evdev *dsw = dsw_pmd_priv(dev);
 
+	struct store_ctx ctx = {
+		.names = xstats_names,
+		.ids = ids,
+		.capacity = capacity
+	};
+
 	switch (mode) {
 	case RTE_EVENT_DEV_XSTATS_DEVICE:
-		return dsw_xstats_dev_get_names(xstats_names, ids, size);
+		dsw_xstats_dev_foreach(dsw_xstats_store_stat, &ctx);
+		return ctx.count;
 	case RTE_EVENT_DEV_XSTATS_PORT:
-		return dsw_xstats_port_get_names(dsw, queue_port_id,
-						 xstats_names, ids, size);
+		dsw_xstats_port_foreach(dsw, queue_port_id,
+					dsw_xstats_store_stat, &ctx);
+		return ctx.count;
 	case RTE_EVENT_DEV_XSTATS_QUEUE:
 		return 0;
 	default:
@@ -278,11 +313,48 @@ dsw_xstats_get(const struct rte_eventdev *dev,
 	return 0;
 }
 
-uint64_t dsw_xstats_get_by_name(const struct rte_eventdev *dev,
-				const char *name, unsigned int *id)
+struct find_ctx {
+	const struct rte_eventdev *dev;
+	const char *name;
+	unsigned int *id;
+	uint64_t value;
+};
+
+static void
+dsw_xstats_find_stat(const char *xstats_name,
+		     enum rte_event_dev_xstats_mode mode,
+		     uint8_t queue_port_id, unsigned int xstats_id,
+		     void *data)
 {
-	RTE_SET_USED(dev);
-	RTE_SET_USED(name);
-	RTE_SET_USED(id);
-	return 0;
+	struct find_ctx *ctx = data;
+
+	if (strcmp(ctx->name, xstats_name) == 0) {
+		if (ctx->id != NULL)
+			*ctx->id = xstats_id;
+		dsw_xstats_get(ctx->dev, mode, queue_port_id, &xstats_id,
+			       &ctx->value, 1);
+	}
+}
+
+uint64_t
+dsw_xstats_get_by_name(const struct rte_eventdev *dev, const char *name,
+		       unsigned int *id)
+{
+	struct dsw_evdev *dsw = dsw_pmd_priv(dev);
+	uint16_t port_id;
+
+	struct find_ctx ctx = {
+		.dev = dev,
+		.name = name,
+		.id = id,
+		.value = -EINVAL
+	};
+
+	dsw_xstats_dev_foreach(dsw_xstats_find_stat, &ctx);
+
+	for (port_id = 0; port_id < dsw->num_ports; port_id++)
+		dsw_xstats_port_foreach(dsw, port_id, dsw_xstats_find_stat,
+					&ctx);
+
+	return ctx.value;
 }
diff --git a/drivers/event/sw/sw_evdev_xstats.c b/drivers/event/sw/sw_evdev_xstats.c
index 90664903b..02f787418 100644
--- a/drivers/event/sw/sw_evdev_xstats.c
+++ b/drivers/event/sw/sw_evdev_xstats.c
@@ -391,8 +391,6 @@ sw_xstats_get_names(const struct rte_eventdev *dev,
 	const struct sw_evdev *sw = sw_pmd_priv_const(dev);
 	unsigned int i;
 	unsigned int xidx = 0;
-	RTE_SET_USED(mode);
-	RTE_SET_USED(queue_port_id);
 
 	uint32_t xstats_mode_count = 0;
 	uint32_t start_offset = 0;
-- 
2.17.1


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

end of thread, other threads:[~2020-01-14 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 15:03 [dpdk-dev] [PATCH] event/dsw: add by-name xstats retrieval Jerin Jacob Kollanukkaran
  -- strict thread matches above, loose matches on Subject: below --
2019-12-12 18:44 Mattias Rönnblom

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