From: bernd@petrovitsch.priv.at (Bernd Petrovitsch)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Inlined functions in network code
Date: Sun, 11 Mar 2012 13:30:23 +0100 [thread overview]
Message-ID: <1331469024.17330.157.camel@thorin> (raw)
In-Reply-To: <CAGdaadbSEETKsUAG=f=7j6TdHcVdh=WNWjyi8QBNqi3WvjckGA@mail.gmail.com>
Hi!
On Sam, 2012-03-10 at 02:02 +0700, Mulyadi Santosa wrote:
[....]
> On Sat, Mar 10, 2012 at 01:41, ?ukasz Czy? <perlowy.dzem@gmail.com> wrote:
[....]
> >I only have a doubt about
> > criterion when to declare function as inline. Should all functions
> > which are used during packet translation (so they may be called very
> > frequently) be inlined?
>
> perhaps network guys know better, but I think inlining as we all know,
> prevent code path to do jumps. And that will code execution faster,
> especially when it happen many many times (read: millions or more).
> And likely they will stay at the same L1 i-cache or at least
> nearby...so that's nice too :)
>
> IIRC too, "jmp" will screw branch prediction and sometimes will make
> pipeline stall.....So, all in all, it's a matter about speeding about
> code path, especially fast path like what you do.
On the other hand, if a function is "large" and copied several times,
more RAM is used and we have more i-cache pressure. That obviously
doesn't hold for functions thta have one call site.
Apart from that, the "inline" keyword in C is a pure hint to the C
compiler and the C compiler is free to ignore it for whatever reason
(and the C compiler is free to inline functions without that keyword).
So the usual rules are:
a) avoid forward declaration: gcc inlines functions with one call site
without an explicit "inline".
Yes, there are exceptions to this rule.
b) mark all locally only used functions "static" (so that the compiler
knows actually that it isn't called from another file)
c) functions with a loop, if() or switch() shouldn't be inlined anyways
(except of rule a) of course - but that doesn't require an explicit
"inline")
Basically just "inline" functions which are one-liners (or so) and you
would actually make a macro out of it and keep it for parameter type
checking as an inline function.
Posting the patches now to appropriate mailing-lists is the best and you
will get (very probably) feedback from more people - and the ones which
are expected to eventually accept the patches.
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
prev parent reply other threads:[~2012-03-11 12:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-09 18:41 Inlined functions in network code Łukasz Czyż
2012-03-09 19:02 ` Mulyadi Santosa
2012-03-10 10:50 ` Łukasz Czyż
2012-03-10 23:44 ` richard -rw- weinberger
2012-03-11 12:30 ` Bernd Petrovitsch [this message]
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=1331469024.17330.157.camel@thorin \
--to=bernd@petrovitsch.priv.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).