From: Rui Ueyama <rui314@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] net: filter: Convert the BPF VM to threaded code
Date: Fri, 29 Jul 2011 22:09:36 -0700 [thread overview]
Message-ID: <CACKH++afaAaa7a6ViYjo_PjpF1bXYtOuJaa-4umEOSVgW1+g3w@mail.gmail.com> (raw)
In-Reply-To: <1311931816.2843.3.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>
The result of benchmark looks good. A simple benchmark that sends 10M UDP
packets to lo took 76.24 seconds on average on Core 2 Duo L7500@1.6GHz.when
tcpdump is running. With this patch it took 75.41 seconds, which means we save
80ns for each packet on that processor.
I think converting the VM to threaded code is low hanging fruit, even
if we'd have
JIT compilers for popular architectures. Most of the lines in my patch
are indentation
change, so the actual change is not big.
Vanilla kernel:
(without tcpdump)
ruiu@blue:~$ time ./udpflood 10000000
real 0m57.909s
user 0m1.368s
sys 0m56.484s
ruiu@blue:~$ time ./udpflood 10000000
real 0m57.686s
user 0m1.360s
sys 0m56.288s
ruiu@blue:~$ time ./udpflood 10000000
real 0m58.457s
user 0m1.300s
sys 0m57.116s
(with tcpdump)
ruiu@blue:~$ time ./udpflood 10000000
real 1m16.025s
user 0m1.464s
sys 1m14.505s
ruiu@blue:~$ time ./udpflood 10000000
real 1m15.860s
user 0m1.232s
sys 1m14.573s
ruiu@blue:~$ time ./udpflood 10000000
real 1m16.861s
user 0m1.504s
sys 1m15.301s
Kernel with the patch:
(without tcpdump)
ruiu@blue:~$ time ./udpflood 10000000
real 0m59.272s
user 0m1.308s
sys 0m57.924s
ruiu@blue:~$ time ./udpflood 10000000
real 0m59.624s
user 0m1.336s
sys 0m58.244s
ruiu@blue:~$ time ./udpflood 10000000
real 0m59.340s
user 0m1.240s
sys 0m58.056s
(with tcpdump)
ruiu@blue:~$ time ./udpflood 10000000
real 1m15.392s
user 0m1.372s
sys 1m13.965s
ruiu@blue:~$ time ./udpflood 10000000
real 1m15.352s
user 0m1.452s
sys 1m13.845s
ruiu@blue:~$ time ./udpflood 10000000
real 1m15.508s
user 0m1.464s
sys 1m13.989s
Tcpdump I used is this: tcpdump -p -n -s -i lo net 192.168.2.0/24
On Fri, Jul 29, 2011 at 2:30 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le vendredi 29 juillet 2011 à 01:10 -0700, Rui Ueyama a écrit :
>> Convert the BPF VM to threaded code to improve performance.
>>
>> The BPF VM is basically a big for loop containing a switch statement. That is
>> slow because for each instruction it checks the for loop condition and does the
>> conditional branch of the switch statement.
>>
>> This patch eliminates the conditional branch, by replacing it with jump table
>> using GCC's labels-as-values feature. The for loop condition check can also be
>> removed, because the filter code always end with a RET instruction.
>>
>
> Well...
>
>
>> +#define NEXT goto *jump_table[(++fentry)->code]
>> +
>> + /* Dispatch the first instruction */
>> + goto *jump_table[fentry->code];
>
> This is the killer, as this cannot be predicted by the cpu.
>
> Do you have benchmark results to provide ?
>
> We now have BPF JIT on x86_64 and powerpc, and possibly on MIPS and ARM
> on a near future.
>
>
>
>
next prev parent reply other threads:[~2011-07-30 5:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-29 8:10 [PATCH] net: filter: Convert the BPF VM to threaded code Rui Ueyama
2011-07-29 9:30 ` Eric Dumazet
2011-07-30 5:09 ` Rui Ueyama [this message]
2011-07-30 6:04 ` Eric Dumazet
2011-07-30 6:20 ` Eric Dumazet
2011-07-30 9:55 ` Francois Romieu
2011-08-01 18:16 ` Hagen Paul Pfeifer
2011-08-01 18:37 ` Eric Dumazet
2011-08-02 0:57 ` David Miller
2011-08-09 5:00 ` Eric Dumazet
2011-08-09 8:29 ` Hagen Paul Pfeifer
2011-08-09 8:36 ` Eric Dumazet
2011-08-09 8:53 ` Hagen Paul Pfeifer
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=CACKH++afaAaa7a6ViYjo_PjpF1bXYtOuJaa-4umEOSVgW1+g3w@mail.gmail.com \
--to=rui314@gmail.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.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).