On 21/10/2015 16:47, Stephen Hemminger wrote: > On Wed, 21 Oct 2015 09:38:37 +0000 > "Ananyev, Konstantin" <konstantin.ananyev at intel.com> wrote: > >>>> minor nits: >>>> * this doesn't need to be marked as always inline, >>>> that is as they say in English "shooting a fly with a bazooka" >>> Stephen: >>> always_inline "forces" the compiler to inline this function, like a macro. >>> When should it be used or is it not preferred at all? >> I also don't understand what's wrong with using 'always_inline' here. >> As I understand the author wants compiler to *always inline* that function. >> So seems perfectly ok to use it here. >> As I remember just 'inline' is sort of recommendation that compiler is free >> to ignore. >> Konstantin > I follow Linux/Linus advice and resist the urge to add strong inlining. > The compiler does a good job of deciding to inline, and many times > the reason it chooses for not inlining are quite good like: > - the code is on an unlikely branch > - register pressure means inlining would mean the code would be worse > > Therefore my rules are: > * only use inline for small functions. Let compiler decide on larger > static funcs > * write code where most functions are static (localized scope) where > compiler > can decide > * reserve always inline for things that access hardware and would break if > not inlined. > On the other hand, there are cases where we know the compiler will likely inline, but we also know that not inlining could have a high performance penalty, and in that case marking as "always inline" would be appropriate - even though it is likely unnecessary for most compilers. In such a case, I would expect the verification check to be: explicitly mark the function as *not* to be inlined, and see what the perf drop is. If it's a noticable drop, marking as always-inline is an ok precaution against future compiler changes.
Also, we need to remember that compilers cannot know whether a function is data path or not, and also whether a function will be called per-packet or per-burst. That's only something the programmer will know, and functions called per-packet on the datapath generally need to be inlined for performance. /Bruce /Bruce