DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] raw/cnxk_gpio: switch to dynamic logging
@ 2023-11-03 21:09 Tomasz Duszynski
  2023-12-05  9:37 ` Jerin Jacob Kollanukkaran
  0 siblings, 1 reply; 3+ messages in thread
From: Tomasz Duszynski @ 2023-11-03 21:09 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski; +Cc: jerinj, stephen

Dynamically allocated log type is a standard approach among all drivers.
Switch to it.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c          | 22 ++++++++++++----------
 drivers/raw/cnxk_gpio/cnxk_gpio.h          |  7 +++++++
 drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c | 19 ++++++++-----------
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 29c2506726..ebc914afcf 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -10,6 +10,7 @@
 #include <rte_eal.h>
 #include <rte_kvargs.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_rawdev_pmd.h>
 
 #include <roc_api.h>
@@ -213,13 +214,13 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 		errno = 0;
 		val = strtol(token, NULL, 10);
 		if (errno) {
-			RTE_LOG(ERR, PMD, "failed to parse %s\n", token);
+			CNXK_GPIO_LOG(ERR, "failed to parse %s", token);
 			ret = -errno;
 			goto out;
 		}
 
 		if (val < 0 || val >= gpiochip->num_gpios) {
-			RTE_LOG(ERR, PMD, "gpio%d out of 0-%d range\n", val,
+			CNXK_GPIO_LOG(ERR, "gpio%d out of 0-%d range", val,
 				gpiochip->num_gpios - 1);
 			ret = -EINVAL;
 			goto out;
@@ -229,7 +230,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 			if (list[i] != val)
 				continue;
 
-			RTE_LOG(WARNING, PMD, "gpio%d already allowed\n", val);
+			CNXK_GPIO_LOG(WARNING, "gpio%d already allowed", val);
 			break;
 		}
 		if (i == queue)
@@ -396,7 +397,7 @@ cnxk_gpio_queue_setup(struct rte_rawdev *dev, uint16_t queue_id,
 			return ret;
 		}
 	} else {
-		RTE_LOG(WARNING, PMD, "using existing gpio%d\n", gpio->num);
+		CNXK_GPIO_LOG(WARNING, "using existing gpio%d", gpio->num);
 	}
 
 	gpiochip->gpios[num] = gpio;
@@ -645,7 +646,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct rte_rawdev_buf *rbuf)
 
 	/* get rid of last response if any */
 	if (gpio->rsp) {
-		RTE_LOG(WARNING, PMD, "previous response got overwritten\n");
+		CNXK_GPIO_LOG(WARNING, "previous response got overwritten");
 		rte_free(gpio->rsp);
 	}
 	gpio->rsp = rsp;
@@ -739,7 +740,7 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
 	cnxk_gpio_format_name(name, sizeof(name));
 	rawdev = rte_rawdev_pmd_allocate(name, sizeof(*gpiochip), rte_socket_id());
 	if (!rawdev) {
-		RTE_LOG(ERR, PMD, "failed to allocate %s rawdev\n", name);
+		CNXK_GPIO_LOG(ERR, "failed to allocate %s rawdev", name);
 		return -ENOMEM;
 	}
 
@@ -768,7 +769,7 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
 	snprintf(buf, sizeof(buf), "%s/gpiochip%d/base", CNXK_GPIO_CLASS_PATH, gpiochip->num);
 	ret = cnxk_gpio_read_attr_int(buf, &gpiochip->base);
 	if (ret) {
-		RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
+		CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
 		goto out;
 	}
 
@@ -776,20 +777,20 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
 	snprintf(buf, sizeof(buf), "%s/gpiochip%d/ngpio", CNXK_GPIO_CLASS_PATH, gpiochip->num);
 	ret = cnxk_gpio_read_attr_int(buf, &gpiochip->num_gpios);
 	if (ret) {
-		RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
+		CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
 		goto out;
 	}
 	gpiochip->num_queues = gpiochip->num_gpios;
 
 	ret = cnxk_gpio_parse_allowlist(gpiochip, params->allowlist);
 	if (ret) {
-		RTE_LOG(ERR, PMD, "failed to parse allowed gpios\n");
+		CNXK_GPIO_LOG(ERR, "failed to parse allowed gpios");
 		goto out;
 	}
 
 	gpiochip->gpios = rte_calloc(NULL, gpiochip->num_gpios, sizeof(struct cnxk_gpio *), 0);
 	if (!gpiochip->gpios) {
-		RTE_LOG(ERR, PMD, "failed to allocate gpios memory\n");
+		CNXK_GPIO_LOG(ERR, "failed to allocate gpios memory");
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -849,3 +850,4 @@ RTE_PMD_REGISTER_VDEV(cnxk_gpio, cnxk_gpio_drv);
 RTE_PMD_REGISTER_PARAM_STRING(cnxk_gpio,
 		"gpiochip=<int> "
 		"allowlist=<list>");
+RTE_LOG_REGISTER_DEFAULT(cnxk_gpio_rawdev_logtype, WARNING);
diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.h b/drivers/raw/cnxk_gpio/cnxk_gpio.h
index e62f78a760..a2a6b9469b 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.h
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.h
@@ -5,6 +5,13 @@
 #ifndef _CNXK_GPIO_H_
 #define _CNXK_GPIO_H_
 
+#include <rte_log.h>
+
+extern int cnxk_gpio_rawdev_logtype;
+
+#define CNXK_GPIO_LOG(level, fmt, args...) \
+	rte_log(RTE_LOG_ ## level, cnxk_gpio_rawdev_logtype, "%s(): " fmt "\n", __func__, ##args)
+
 struct cnxk_gpiochip;
 
 struct cnxk_gpio {
diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
index 10742b5dc4..a462871c4a 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
@@ -56,7 +56,7 @@ cnxk_gpio_read_attr(char *attr, char *val)
 
 #define CNXK_GPIO_ERR_STR(err, str, ...) do {                                  \
 	if (err) {                                                             \
-		RTE_LOG(ERR, PMD, "%s:%d: " str " (%d)\n", __func__, __LINE__, \
+		CNXK_GPIO_LOG(ERR, "%s:%d: " str " (%d)", __func__, __LINE__, \
 			##__VA_ARGS__, err);                                   \
 		goto out;                                                      \
 	}                                                                      \
@@ -330,30 +330,28 @@ cnxk_gpio_selftest(uint16_t dev_id)
 	for (i = 0; i < queues; i++) {
 		ret = rte_rawdev_queue_conf_get(dev_id, i, &conf, sizeof(conf));
 		if (ret) {
-			RTE_LOG(ERR, PMD,
-				"failed to read queue configuration (%d)\n",
-				ret);
+			CNXK_GPIO_LOG(ERR, "failed to read queue configuration (%d)", ret);
 			goto out;
 		}
 
-		RTE_LOG(INFO, PMD, "testing queue%d (gpio%d)\n", i, conf.gpio);
+		CNXK_GPIO_LOG(INFO, "testing queue%d (gpio%d)", i, conf.gpio);
 
 		if (conf.size != 1) {
-			RTE_LOG(ERR, PMD, "wrong queue size received\n");
+			CNXK_GPIO_LOG(ERR, "wrong queue size received\n");
 			ret = -EIO;
 			goto out;
 		}
 
 		ret = rte_rawdev_queue_setup(dev_id, i, NULL, 0);
 		if (ret) {
-			RTE_LOG(ERR, PMD, "failed to setup queue (%d)\n", ret);
+			CNXK_GPIO_LOG(ERR, "failed to setup queue (%d)", ret);
 			goto out;
 		}
 
 		gpio = gpiochip->gpios[conf.gpio];
 		snprintf(buf, sizeof(buf), CNXK_GPIO_PATH_FMT, gpio->num);
 		if (!cnxk_gpio_attr_exists(buf)) {
-			RTE_LOG(ERR, PMD, "%s does not exist\n", buf);
+			CNXK_GPIO_LOG(ERR, "%s does not exist", buf);
 			ret = -ENOENT;
 			goto release;
 		}
@@ -371,13 +369,12 @@ cnxk_gpio_selftest(uint16_t dev_id)
 		ret2 = ret;
 		ret = rte_rawdev_queue_release(dev_id, i);
 		if (ret) {
-			RTE_LOG(ERR, PMD, "failed to release queue (%d)\n",
-				ret);
+			CNXK_GPIO_LOG(ERR, "failed to release queue (%d)", ret);
 			break;
 		}
 
 		if (cnxk_gpio_attr_exists(buf)) {
-			RTE_LOG(ERR, PMD, "%s still exists\n", buf);
+			CNXK_GPIO_LOG(ERR, "%s still exists", buf);
 			ret = -EIO;
 			break;
 		}
-- 
2.34.1


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

* RE: [PATCH] raw/cnxk_gpio: switch to dynamic logging
  2023-11-03 21:09 [PATCH] raw/cnxk_gpio: switch to dynamic logging Tomasz Duszynski
@ 2023-12-05  9:37 ` Jerin Jacob Kollanukkaran
  2024-02-21  1:54   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Jerin Jacob Kollanukkaran @ 2023-12-05  9:37 UTC (permalink / raw)
  To: Tomasz Duszynski, dev, Jakub Palider, Tomasz Duszynski; +Cc: stephen



> -----Original Message-----
> From: Tomasz Duszynski <tduszynski@marvell.com>
> Sent: Saturday, November 4, 2023 2:40 AM
> To: dev@dpdk.org; Jakub Palider <jpalider@marvell.com>; Tomasz Duszynski
> <tduszynski@marvell.com>
> Cc: Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> stephen@networkplumber.org
> Subject: [PATCH] raw/cnxk_gpio: switch to dynamic logging
> 
> Dynamically allocated log type is a standard approach among all drivers.
> Switch to it.
> 
> Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>


Applied to dpdk-next-net-mrvl/for-main. Thanks


> ---
>  drivers/raw/cnxk_gpio/cnxk_gpio.c          | 22 ++++++++++++----------
>  drivers/raw/cnxk_gpio/cnxk_gpio.h          |  7 +++++++
>  drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c | 19 ++++++++-----------
>  3 files changed, 27 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c
> b/drivers/raw/cnxk_gpio/cnxk_gpio.c
> index 29c2506726..ebc914afcf 100644
> --- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
> +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
> @@ -10,6 +10,7 @@
>  #include <rte_eal.h>
>  #include <rte_kvargs.h>
>  #include <rte_lcore.h>
> +#include <rte_log.h>
>  #include <rte_rawdev_pmd.h>
> 
>  #include <roc_api.h>
> @@ -213,13 +214,13 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip
> *gpiochip, char *allowlist)
>  		errno = 0;
>  		val = strtol(token, NULL, 10);
>  		if (errno) {
> -			RTE_LOG(ERR, PMD, "failed to parse %s\n", token);
> +			CNXK_GPIO_LOG(ERR, "failed to parse %s", token);
>  			ret = -errno;
>  			goto out;
>  		}
> 
>  		if (val < 0 || val >= gpiochip->num_gpios) {
> -			RTE_LOG(ERR, PMD, "gpio%d out of 0-%d range\n",
> val,
> +			CNXK_GPIO_LOG(ERR, "gpio%d out of 0-%d range",
> val,
>  				gpiochip->num_gpios - 1);
>  			ret = -EINVAL;
>  			goto out;
> @@ -229,7 +230,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip
> *gpiochip, char *allowlist)
>  			if (list[i] != val)
>  				continue;
> 
> -			RTE_LOG(WARNING, PMD, "gpio%d already
> allowed\n", val);
> +			CNXK_GPIO_LOG(WARNING, "gpio%d already
> allowed", val);
>  			break;
>  		}
>  		if (i == queue)
> @@ -396,7 +397,7 @@ cnxk_gpio_queue_setup(struct rte_rawdev *dev,
> uint16_t queue_id,
>  			return ret;
>  		}
>  	} else {
> -		RTE_LOG(WARNING, PMD, "using existing gpio%d\n", gpio-
> >num);
> +		CNXK_GPIO_LOG(WARNING, "using existing gpio%d", gpio-
> >num);
>  	}
> 
>  	gpiochip->gpios[num] = gpio;
> @@ -645,7 +646,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct
> rte_rawdev_buf *rbuf)
> 
>  	/* get rid of last response if any */
>  	if (gpio->rsp) {
> -		RTE_LOG(WARNING, PMD, "previous response got
> overwritten\n");
> +		CNXK_GPIO_LOG(WARNING, "previous response got
> overwritten");
>  		rte_free(gpio->rsp);
>  	}
>  	gpio->rsp = rsp;
> @@ -739,7 +740,7 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
>  	cnxk_gpio_format_name(name, sizeof(name));
>  	rawdev = rte_rawdev_pmd_allocate(name, sizeof(*gpiochip),
> rte_socket_id());
>  	if (!rawdev) {
> -		RTE_LOG(ERR, PMD, "failed to allocate %s rawdev\n", name);
> +		CNXK_GPIO_LOG(ERR, "failed to allocate %s rawdev", name);
>  		return -ENOMEM;
>  	}
> 
> @@ -768,7 +769,7 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
>  	snprintf(buf, sizeof(buf), "%s/gpiochip%d/base",
> CNXK_GPIO_CLASS_PATH, gpiochip->num);
>  	ret = cnxk_gpio_read_attr_int(buf, &gpiochip->base);
>  	if (ret) {
> -		RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
> +		CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
>  		goto out;
>  	}
> 
> @@ -776,20 +777,20 @@ cnxk_gpio_probe(struct rte_vdev_device *dev)
>  	snprintf(buf, sizeof(buf), "%s/gpiochip%d/ngpio",
> CNXK_GPIO_CLASS_PATH, gpiochip->num);
>  	ret = cnxk_gpio_read_attr_int(buf, &gpiochip->num_gpios);
>  	if (ret) {
> -		RTE_LOG(ERR, PMD, "failed to read %s\n", buf);
> +		CNXK_GPIO_LOG(ERR, "failed to read %s", buf);
>  		goto out;
>  	}
>  	gpiochip->num_queues = gpiochip->num_gpios;
> 
>  	ret = cnxk_gpio_parse_allowlist(gpiochip, params->allowlist);
>  	if (ret) {
> -		RTE_LOG(ERR, PMD, "failed to parse allowed gpios\n");
> +		CNXK_GPIO_LOG(ERR, "failed to parse allowed gpios");
>  		goto out;
>  	}
> 
>  	gpiochip->gpios = rte_calloc(NULL, gpiochip->num_gpios, sizeof(struct
> cnxk_gpio *), 0);
>  	if (!gpiochip->gpios) {
> -		RTE_LOG(ERR, PMD, "failed to allocate gpios memory\n");
> +		CNXK_GPIO_LOG(ERR, "failed to allocate gpios memory");
>  		ret = -ENOMEM;
>  		goto out;
>  	}
> @@ -849,3 +850,4 @@ RTE_PMD_REGISTER_VDEV(cnxk_gpio, cnxk_gpio_drv);
> RTE_PMD_REGISTER_PARAM_STRING(cnxk_gpio,
>  		"gpiochip=<int> "
>  		"allowlist=<list>");
> +RTE_LOG_REGISTER_DEFAULT(cnxk_gpio_rawdev_logtype, WARNING);
> diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.h
> b/drivers/raw/cnxk_gpio/cnxk_gpio.h
> index e62f78a760..a2a6b9469b 100644
> --- a/drivers/raw/cnxk_gpio/cnxk_gpio.h
> +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.h
> @@ -5,6 +5,13 @@
>  #ifndef _CNXK_GPIO_H_
>  #define _CNXK_GPIO_H_
> 
> +#include <rte_log.h>
> +
> +extern int cnxk_gpio_rawdev_logtype;
> +
> +#define CNXK_GPIO_LOG(level, fmt, args...) \
> +	rte_log(RTE_LOG_ ## level, cnxk_gpio_rawdev_logtype, "%s(): " fmt
> +"\n", __func__, ##args)
> +
>  struct cnxk_gpiochip;
> 
>  struct cnxk_gpio {
> diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
> b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
> index 10742b5dc4..a462871c4a 100644
> --- a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
> +++ b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
> @@ -56,7 +56,7 @@ cnxk_gpio_read_attr(char *attr, char *val)
> 
>  #define CNXK_GPIO_ERR_STR(err, str, ...) do {                                  \
>  	if (err) {                                                             \
> -		RTE_LOG(ERR, PMD, "%s:%d: " str " (%d)\n", __func__,
> __LINE__, \
> +		CNXK_GPIO_LOG(ERR, "%s:%d: " str " (%d)", __func__,
> __LINE__, \
>  			##__VA_ARGS__, err);                                   \
>  		goto out;                                                      \
>  	}                                                                      \
> @@ -330,30 +330,28 @@ cnxk_gpio_selftest(uint16_t dev_id)
>  	for (i = 0; i < queues; i++) {
>  		ret = rte_rawdev_queue_conf_get(dev_id, i, &conf,
> sizeof(conf));
>  		if (ret) {
> -			RTE_LOG(ERR, PMD,
> -				"failed to read queue configuration (%d)\n",
> -				ret);
> +			CNXK_GPIO_LOG(ERR, "failed to read queue
> configuration (%d)", ret);
>  			goto out;
>  		}
> 
> -		RTE_LOG(INFO, PMD, "testing queue%d (gpio%d)\n", i,
> conf.gpio);
> +		CNXK_GPIO_LOG(INFO, "testing queue%d (gpio%d)", i,
> conf.gpio);
> 
>  		if (conf.size != 1) {
> -			RTE_LOG(ERR, PMD, "wrong queue size received\n");
> +			CNXK_GPIO_LOG(ERR, "wrong queue size received\n");
>  			ret = -EIO;
>  			goto out;
>  		}
> 
>  		ret = rte_rawdev_queue_setup(dev_id, i, NULL, 0);
>  		if (ret) {
> -			RTE_LOG(ERR, PMD, "failed to setup queue (%d)\n",
> ret);
> +			CNXK_GPIO_LOG(ERR, "failed to setup queue (%d)",
> ret);
>  			goto out;
>  		}
> 
>  		gpio = gpiochip->gpios[conf.gpio];
>  		snprintf(buf, sizeof(buf), CNXK_GPIO_PATH_FMT, gpio->num);
>  		if (!cnxk_gpio_attr_exists(buf)) {
> -			RTE_LOG(ERR, PMD, "%s does not exist\n", buf);
> +			CNXK_GPIO_LOG(ERR, "%s does not exist", buf);
>  			ret = -ENOENT;
>  			goto release;
>  		}
> @@ -371,13 +369,12 @@ cnxk_gpio_selftest(uint16_t dev_id)
>  		ret2 = ret;
>  		ret = rte_rawdev_queue_release(dev_id, i);
>  		if (ret) {
> -			RTE_LOG(ERR, PMD, "failed to release queue (%d)\n",
> -				ret);
> +			CNXK_GPIO_LOG(ERR, "failed to release queue (%d)",
> ret);
>  			break;
>  		}
> 
>  		if (cnxk_gpio_attr_exists(buf)) {
> -			RTE_LOG(ERR, PMD, "%s still exists\n", buf);
> +			CNXK_GPIO_LOG(ERR, "%s still exists", buf);
>  			ret = -EIO;
>  			break;
>  		}
> --
> 2.34.1


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

* Re: [PATCH] raw/cnxk_gpio: switch to dynamic logging
  2023-12-05  9:37 ` Jerin Jacob Kollanukkaran
@ 2024-02-21  1:54   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2024-02-21  1:54 UTC (permalink / raw)
  To: Tomasz Duszynski, stephen
  Cc: dev, Jakub Palider, Jerin Jacob Kollanukkaran, david.marchand

05/12/2023 10:37, Jerin Jacob Kollanukkaran:
> From: Tomasz Duszynski <tduszynski@marvell.com>
> > Dynamically allocated log type is a standard approach among all drivers.
> > Switch to it.
> > 
> > Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
> 
> 
> Applied to dpdk-next-net-mrvl/for-main. Thanks

Sorry, a patch from Stephen has been merged first in the main tree.

The main difference is on log registration:
Stephen's patch:
	RTE_LOG_REGISTER_SUFFIX(cnxk_logtype_gpio, gpio, INFO);
Tomasz' patch:
	RTE_LOG_REGISTER_DEFAULT(cnxk_gpio_rawdev_logtype, WARNING);

Please could you send a rebased patch?




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

end of thread, other threads:[~2024-02-21  1:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03 21:09 [PATCH] raw/cnxk_gpio: switch to dynamic logging Tomasz Duszynski
2023-12-05  9:37 ` Jerin Jacob Kollanukkaran
2024-02-21  1:54   ` Thomas Monjalon

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