* Inlined functions in network code @ 2012-03-09 18:41 Łukasz Czyż 2012-03-09 19:02 ` Mulyadi Santosa 0 siblings, 1 reply; 5+ messages in thread From: Łukasz Czyż @ 2012-03-09 18:41 UTC (permalink / raw) To: kernelnewbies Hello I implemented stateful IPv6-IPv4 NAT translator which works on top of netfilter. It is fully functional now, 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? Translator is released under GPLv2 license. You can find more info about it at http://czyzu.pl/xlat.html Lukasz ^ permalink raw reply [flat|nested] 5+ messages in thread
* Inlined functions in network code 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-11 12:30 ` Bernd Petrovitsch 0 siblings, 2 replies; 5+ messages in thread From: Mulyadi Santosa @ 2012-03-09 19:02 UTC (permalink / raw) To: kernelnewbies Hi :) On Sat, Mar 10, 2012 at 01:41, ?ukasz Czy? <perlowy.dzem@gmail.com> wrote: > Hello > > I implemented stateful IPv6-IPv4 NAT translator which works on top of > netfilter. It is fully functional now, congratulations! A nice achievement IMHO.... :) is it merged with linux kernel mainline? >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. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* Inlined functions in network code 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 1 sibling, 1 reply; 5+ messages in thread From: Łukasz Czyż @ 2012-03-10 10:50 UTC (permalink / raw) To: kernelnewbies > > congratulations! A nice achievement IMHO.... :) > Thanks :) > > is it merged with linux kernel mainline? > No. I am not sure if it good enough to be merged, I would like to get some opinions before I ask to add it to mainline. > > 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. > Generally I am aware about advantages of inlining, but I also read in CodingStyle document about its disadvantages, that is where my question came from :) Maybe I should ask about it on some other list? Lukasz Czyz ^ permalink raw reply [flat|nested] 5+ messages in thread
* Inlined functions in network code 2012-03-10 10:50 ` Łukasz Czyż @ 2012-03-10 23:44 ` richard -rw- weinberger 0 siblings, 0 replies; 5+ messages in thread From: richard -rw- weinberger @ 2012-03-10 23:44 UTC (permalink / raw) To: kernelnewbies On Sat, Mar 10, 2012 at 11:50 AM, ?ukasz Czy? <perlowy.dzem@gmail.com> wrote: > No. I am not sure if it good enough to be merged, I would like to get > some opinions before I ask to add it to mainline. Submit a patch to netdev/netfilter-devel and you'll get a review. -- Thanks, //richard ^ permalink raw reply [flat|nested] 5+ messages in thread
* Inlined functions in network code 2012-03-09 19:02 ` Mulyadi Santosa 2012-03-10 10:50 ` Łukasz Czyż @ 2012-03-11 12:30 ` Bernd Petrovitsch 1 sibling, 0 replies; 5+ messages in thread From: Bernd Petrovitsch @ 2012-03-11 12:30 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-03-11 12:30 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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).