raw/cnxk_gpio: switch to dynamic logging

Message ID 20231103210952.2447882-1-tduszynski@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series raw/cnxk_gpio: switch to dynamic logging |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Tomasz Duszynski Nov. 3, 2023, 9:09 p.m. UTC
  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(-)
  

Comments

Jerin Jacob Kollanukkaran Dec. 5, 2023, 9:37 a.m. UTC | #1
> -----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
  
Thomas Monjalon Feb. 21, 2024, 1:54 a.m. UTC | #2
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?
  

Patch

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;
 		}