Re: optimizing out inline functions

From: Joe Perches
Date: Wed May 28 2008 - 23:49:40 EST


On Thu, 2008-05-29 at 05:27 +0200, Johannes Weiner wrote:
> James Kosin <jkosin@xxxxxxxxxxxxxxxxxx> writes:
> >> But we do not have KCONFIG_DEBUG_SOMETHING available
> >> so the second best is to use an empty function
> >> to keep the typechecking in place.
> >> IIRC gcc optimize both away.
> > Another way would be to have:
> > static inline void some_debug_function(var1)
> > {
> > #ifdef KCONFIG_DEBUG_SOMETHING
> > something = var1;
> > printk(some debug text);
> > #endif
> > }

A potential issue is a possible unnecessary call of any
function used as an argument to some_debug_function.

int unnecessary_debug_test(void)
{
int foo;
[]
return foo;
}

static inline void some_debug_function(int bar)
{
}

some_debug_function(unnecessary_debug_test())

unnecessary_debug_test will still get called

Macro wrappers/statement expressions can be used to avoid
the function call. see kernel.h/pr_debug for an example.

#ifdef DEBUG
/* If you are writing a driver, please use dev_dbg instead */
#define pr_debug(fmt, arg...) \
printk(KERN_DEBUG fmt, ##arg)
#else
#define pr_debug(fmt, arg...) \
({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
#endif


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/