LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Adrian Bunk <bunk@stusta.de>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: "Robert P. J. Day" <rpjday@mindspring.com>,
	Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: Re: can someone explain "inline" once and for all?
Date: Fri, 19 Jan 2007 15:13:55 +0100	[thread overview]
Message-ID: <20070119141355.GM9093@stusta.de> (raw)
In-Reply-To: <84144f020701190501x5d1efb49u87dc9537bfe1e791@mail.gmail.com>

On Fri, Jan 19, 2007 at 03:01:44PM +0200, Pekka Enberg wrote:
> On 1/19/07, Robert P. J. Day <rpjday@mindspring.com> 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


  parent reply	other threads:[~2007-01-19 14:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-19 11:56 Robert P. J. Day
2007-01-19 13:01 ` Pekka Enberg
2007-01-19 13:19   ` Robert P. J. Day
2007-01-19 14:13   ` Adrian Bunk [this message]
2007-01-19 14:44     ` Robert P. J. Day
2007-01-19 14:53     ` Robert P. J. Day
2007-01-19 13:37 ` Andreas Schwab
2007-01-19 13:48   ` Robert P. J. Day
2007-01-19 13:58     ` Andreas Schwab
2007-01-19 14:00       ` Robert P. J. Day
2007-01-19 17:15 ` Alexandre Oliva
2007-01-19 17:36   ` Adrian Bunk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070119141355.GM9093@stusta.de \
    --to=bunk@stusta.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=rpjday@mindspring.com \
    --subject='Re: can someone explain "inline" once and for all?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).