[dpdk-dev] [PATCH] enic: disable debug traces

Adrien Mazarguil adrien.mazarguil at 6wind.com
Mon Apr 13 12:32:40 CEST 2015


On Thu, Apr 09, 2015 at 09:28:53AM -0700, Stephen Hemminger wrote:
> On Thu, 9 Apr 2015 10:32:24 +0200
> Adrien Mazarguil <adrien.mazarguil at 6wind.com> wrote:
> 
> > >  
> > > +#ifdef RTE_LIBRTE_ENIC_DEBUG
> > >  #define ENICPMD_FUNC_TRACE() \
> > >  	RTE_LOG(DEBUG, PMD, "ENICPMD trace: %s\n", __func__)
> > > +#else
> > > +#define ENICPMD_FUNC_TRACE() do {} while (0)  
> > 
> > How about defining it as (void)0 instead of an empty do/while block?
> > 
> > Doing so will prevent warnings if this macro happens to be used in an
> > expression. RTE_LOG() supports it.
> 
> I kind of like the Linux printk trick since it then preserves the format checking
> even if compiled out.
> 
> /*
>  * Dummy printk for disabled debugging statements to use whilst maintaining
>  * gcc's format and side-effect checking.
>  */
> static inline __printf(1, 2)
> int no_printk(const char *fmt, ...)
> {
> 	return 0;
> }
> 
> /* pr_devel() should produce zero code unless DEBUG is defined */
> #ifdef DEBUG
> #define pr_devel(fmt, ...) \
> 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
> #else
> #define pr_devel(fmt, ...) \
> 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
> #endif

My only concern with this is that it cannot be done in a ISO C compliant
manner easily.

While "__printf()" can be defined to nothing when dealing with compilers
that do not support extensions, ", ## __VAR_ARGS__" will most likely fail
with -pedantic.

-- 
Adrien Mazarguil
6WIND


More information about the dev mailing list