[dpdk-dev,1/2] ethdev: move log macro to header

Message ID 20180501172815.214973-1-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Ferruh Yigit May 1, 2018, 5:28 p.m. UTC
  Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_ethdev/rte_ethdev.c | 17 +++++++----------
 lib/librte_ethdev/rte_ethdev.h |  5 +++++
 2 files changed, 12 insertions(+), 10 deletions(-)
  

Comments

Thomas Monjalon May 1, 2018, 6:56 p.m. UTC | #1
01/05/2018 19:28, Ferruh Yigit:
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> -static int ethdev_logtype;
> -
> -#define ethdev_log(level, fmt, ...) \
> -	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
> +int ethdev_logtype;
>  
[...]
> --- a/lib/librte_ethdev/rte_ethdev.h
> +++ b/lib/librte_ethdev/rte_ethdev.h
> +extern int ethdev_logtype;
> +
> +#define RTE_ETHDEV_LOG(level, fmt, ...) \
> +	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)

Why moving this macro in the header file? For using it in inline functions?
Probably worth an explanation in the commit message.
  
Ferruh Yigit May 2, 2018, 9:40 a.m. UTC | #2
On 5/1/2018 7:56 PM, Thomas Monjalon wrote:
> 01/05/2018 19:28, Ferruh Yigit:
>> --- a/lib/librte_ethdev/rte_ethdev.c
>> +++ b/lib/librte_ethdev/rte_ethdev.c
>> -static int ethdev_logtype;
>> -
>> -#define ethdev_log(level, fmt, ...) \
>> -	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
>> +int ethdev_logtype;
>>  
> [...]
>> --- a/lib/librte_ethdev/rte_ethdev.h
>> +++ b/lib/librte_ethdev/rte_ethdev.h
>> +extern int ethdev_logtype;
>> +
>> +#define RTE_ETHDEV_LOG(level, fmt, ...) \
>> +	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
> 
> Why moving this macro in the header file? For using it in inline functions?
> Probably worth an explanation in the commit message.

Yes mainly for RTE_PMD_DEBUG_TRACE usage in header file. The ones in
RTE_ETH_VALID_PORTID_... macros and inline functions, which I didn't update in
this set.

I will update the commit log.
  
Stephen Hemminger May 2, 2018, 2:45 p.m. UTC | #3
On Wed, 2 May 2018 10:40:08 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> On 5/1/2018 7:56 PM, Thomas Monjalon wrote:
> > 01/05/2018 19:28, Ferruh Yigit:  
> >> --- a/lib/librte_ethdev/rte_ethdev.c
> >> +++ b/lib/librte_ethdev/rte_ethdev.c
> >> -static int ethdev_logtype;
> >> -
> >> -#define ethdev_log(level, fmt, ...) \
> >> -	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
> >> +int ethdev_logtype;
> >>    
> > [...]  
> >> --- a/lib/librte_ethdev/rte_ethdev.h
> >> +++ b/lib/librte_ethdev/rte_ethdev.h
> >> +extern int ethdev_logtype;
> >> +
> >> +#define RTE_ETHDEV_LOG(level, fmt, ...) \
> >> +	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)  
> > 
> > Why moving this macro in the header file? For using it in inline functions?
> > Probably worth an explanation in the commit message.  
> 
> Yes mainly for RTE_PMD_DEBUG_TRACE usage in header file. The ones in
> RTE_ETH_VALID_PORTID_... macros and inline functions, which I didn't update in
> this set.
> 
> I will update the commit log.

It would be great to eliminate all usage of PMD log level (and maybe even EAL)
in a future release.
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 5a67e6a7d..a1fbb081d 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -41,10 +41,7 @@ 
 #include "rte_ethdev_driver.h"
 #include "ethdev_profile.h"
 
-static int ethdev_logtype;
-
-#define ethdev_log(level, fmt, ...) \
-	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
+int ethdev_logtype;
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -282,12 +279,12 @@  rte_eth_dev_allocate(const char *name)
 
 	port_id = rte_eth_dev_find_free_port();
 	if (port_id == RTE_MAX_ETHPORTS) {
-		ethdev_log(ERR, "Reached maximum number of Ethernet ports");
+		RTE_ETHDEV_LOG(ERR, "Reached maximum number of Ethernet ports");
 		goto unlock;
 	}
 
 	if (rte_eth_dev_allocated(name) != NULL) {
-		ethdev_log(ERR,
+		RTE_ETHDEV_LOG(ERR,
 			"Ethernet Device with name %s already allocated!",
 			name);
 		goto unlock;
@@ -640,7 +637,7 @@  rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
 
 	/* no point looking at the port count if no port exists */
 	if (!rte_eth_dev_count_total()) {
-		ethdev_log(ERR, "No port found for device (%s)", da.name);
+		RTE_ETHDEV_LOG(ERR, "No port found for device (%s)", da.name);
 		ret = -1;
 		goto err;
 	}
@@ -675,7 +672,7 @@  rte_eth_dev_detach(uint16_t port_id, char *name __rte_unused)
 
 	dev_flags = rte_eth_devices[port_id].data->dev_flags;
 	if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
-		ethdev_log(ERR,
+		RTE_ETHDEV_LOG(ERR,
 			"Port %" PRIu16 " is bonded, cannot detach", port_id);
 		return -ENOTSUP;
 	}
@@ -3202,7 +3199,7 @@  rte_eth_dev_callback_register(uint16_t port_id,
 		return -EINVAL;
 
 	if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
-		ethdev_log(ERR, "Invalid port_id=%d", port_id);
+		RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d", port_id);
 		return -EINVAL;
 	}
 
@@ -3265,7 +3262,7 @@  rte_eth_dev_callback_unregister(uint16_t port_id,
 		return -EINVAL;
 
 	if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
-		ethdev_log(ERR, "Invalid port_id=%d", port_id);
+		RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d", port_id);
 		return -EINVAL;
 	}
 
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 7ccf4bae6..f05095c85 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -159,6 +159,11 @@  extern "C" {
 #include "rte_eth_ctrl.h"
 #include "rte_dev_info.h"
 
+extern int ethdev_logtype;
+
+#define RTE_ETHDEV_LOG(level, fmt, ...) \
+	rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
+
 struct rte_mbuf;
 
 /**