Re: can someone explain "inline" once and for all?
From: Adrian Bunk
Date: Fri Jan 19 2007 - 09:14:13 EST
On Fri, Jan 19, 2007 at 03:01:44PM +0200, Pekka Enberg wrote:
> On 1/19/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
> >is there a simple explanation for how to *properly* define inline
> >routines in the kernel? and maybe this can be added to the
> >CodingStyle guide (he mused, wistfully).
>
> AFAIK __always_inline is the only reliable way to force inlining where
> it matters for correctness (for example, when playing tricks with
> __builtin_return_address like we do in the slab).
>
> Anything else is just a hint to the compiler that might be ignored if
> the optimizer thinks it knows better.
With the current implementation in the kernel (and considering that
CONFIG_FORCED_INLINING was implemented in a way that it never had any
effect), __always_inline and inline are currently equivalent.
__always_inline is mostly an annotation that really bad things might
happen if the code doesn't get inlined.
But I'm not sure whether such a distinction is required at all - the
rule of thumb should be that static functions in headers should be
inline (otherwise, they belong into a C file), and functions in C files
should never be marked inline. [1]
cu
Adrian
[1] For the latter there might be a handful of exceptions in the whole
kernel in real fastpath code, but usually gcc knows best when to
inline a function - and we have a global CONFIG_CC_OPTIMIZE_FOR_SIZE
knob for influencing the decision.
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
-
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/