optimizing out inline functions
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Sam Ravnborg
Quoted 1 line · Steve French
In trying to remove some macros, I ran across another kernel style
<<--SNIP-->>
Quoted 11 lines
With reference to a recent thread about kconfig
I would prefer:
static inline voidsome_debug_function(var1){ if (KCONFIG_DEBUG_SOMETHING) { something = var1; printk(some debug text); } }
Quoted 5 lines
But we do not have
KCONFIG_DEBUG_SOMETHINGavailable 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
}
BUT, this probably violates some styling rules.
James
}
Hi,
Quoted 24 lines · James Kosin
Quoted 2 lines · Sam Ravnborg
Quoted 1 line · Steve French
In trying to remove some macros, I ran across another kernel style
<<--SNIP-->>
Quoted 11 lines
With reference to a recent thread about kconfig
I would prefer:
static inline voidsome_debug_function(var1){ if (KCONFIG_DEBUG_SOMETHING) { something = var1; printk(some debug text); } }Quoted 5 lines
But we do not have
KCONFIG_DEBUG_SOMETHINGavailable 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)
Quoted 8 lines
{ #ifdef KCONFIG_DEBUG_SOMETHING something = var1; printk(some debug text); #endif }BUT, this probably violates some styling rules.
Without indenting the ifdefs, I think this solution is the best.
It gives you the advantages of type checking but saves a superfluous prototype.
Hannes
Quoted 5 lines · Johannes Weiner
Quoted 4 lines · James Kosin
Quoted 4 lines
But we do not have
KCONFIG_DEBUG_SOMETHINGavailable so the second best is to use an empty function to keep the typechecking in place.
IIRC gcc optimize both away.
Quoted 8 lines
Quoted 8 lines
Another way would be to have:
static inline voidsome_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
Quoted 43 lines · Johannes Weiner
Hi,
Quoted 28 lines · James Kosin
Quoted 4 lines · Sam Ravnborg
Quoted 2 lines · Steve French
In trying to remove some macros, I ran across another kernel style
<<--SNIP-->>
Quoted 11 lines
With reference to a recent thread about kconfig
I would prefer:
static inline voidsome_debug_function(var1){ if (KCONFIG_DEBUG_SOMETHING) { something = var1; printk(some debug text); } }Quoted 6 lines
But we do not have
KCONFIG_DEBUG_SOMETHINGavailable 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)Quoted 9 lines
{ #ifdef KCONFIG_DEBUG_SOMETHING something = var1; printk(some debug text); #endif }BUT, this probably violates some styling rules.
Quoted 8 lines
Without indenting the ifdefs, I think this solution is the best.
It gives you the advantages of type checking but saves a superfluous prototype.
Hannes
Actually, Joe Perches, gave a good reason for using the MACRO #define method; so, this could really turn into an interesting discussion. Pros and Cons are always interesting when there is more than one way to do something.
James
Quoted 43 lines · Johannes Weiner
Hi,
Quoted 28 lines · James Kosin
Quoted 4 lines · Sam Ravnborg
Quoted 2 lines · Steve French
In trying to remove some macros, I ran across another kernel style
<<--SNIP-->>
Quoted 11 lines
With reference to a recent thread about kconfig
I would prefer:
static inline voidsome_debug_function(var1){ if (KCONFIG_DEBUG_SOMETHING) { something = var1; printk(some debug text); } }Quoted 6 lines
But we do not have
KCONFIG_DEBUG_SOMETHINGavailable 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)Quoted 9 lines
{ #ifdef KCONFIG_DEBUG_SOMETHING something = var1; printk(some debug text); #endif }BUT, this probably violates some styling rules.
Quoted 8 lines
Without indenting the ifdefs, I think this solution is the best.
It gives you the advantages of type checking but saves a superfluous prototype.
Hannes
Actually, Joe Perches, gave a good reason for using the MACRO #define method; so, this could really turn into an interesting discussion. Pros and Cons are always interesting when there is more than one way to do something.
James