From: Eric Dumazet <eric.dumazet@gmail.com>
To: Rui Ueyama <rui314@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] net: filter: Convert the BPF VM to threaded code
Date: Sat, 30 Jul 2011 08:04:59 +0200 [thread overview]
Message-ID: <1312005899.2873.70.camel@edumazet-laptop> (raw)
In-Reply-To: <CACKH++afaAaa7a6ViYjo_PjpF1bXYtOuJaa-4umEOSVgW1+g3w@mail.gmail.com>
Le vendredi 29 juillet 2011 à 22:09 -0700, Rui Ueyama a écrit :
> 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.
>
...
> Tcpdump I used is this: tcpdump -p -n -s -i lo net 192.168.2.0/24
>
Thanks for providing numbers. Was it on 32 or 64bit kernel ?
Have you done a test with a cold instruction cache ?
Your patch adds 540 bytes of code, so its a potential latency increase.
# size net/core/filter.o net/core/filter.o.old
text data bss dec hex filename
4243 0 0 4243 1093 net/core/filter.o
3703 24 0 3727 e8f net/core/filter.o.old
Each 'NEXT' translates to :
4db: 83 c3 08 add $0x8,%ebx
4de: 0f b7 03 movzwl (%ebx),%eax
4e1: 8b 04 85 00 02 00 00 mov 0x200(,%eax,4),%eax
4e8: ff e0 jmp *%eax
And this is on i386, expect more on cpus with 32bit fixed
instructions ...
We can remove one branch per BPF instruction with following patch :
diff --git a/net/core/filter.c b/net/core/filter.c
index 36f975f..377f3ca 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -119,16 +119,14 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
u32 tmp;
int k;
+ fentry--;
/*
* Process array of filter instructions.
*/
- for (;; fentry++) {
-#if defined(CONFIG_X86_32)
+ for (;;) {
#define K (fentry->k)
-#else
- const u32 K = fentry->k;
-#endif
+ fentry++;
switch (fentry->code) {
case BPF_S_ALU_ADD_X:
A += X;
next prev parent reply other threads:[~2011-07-30 6:07 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
2011-07-30 6:04 ` Eric Dumazet [this message]
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=1312005899.2873.70.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=rui314@gmail.com \
/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