Subject: Re: [PATCH v2] net: filter: Just In Time compiler

From: Avi Kivity <[email-masked]>
Date: Thu, 14 Apr 2011 18:53:26 +0300

On 04/14/2011 06:45 PM, Eric Dumazet wrote:
> Le jeudi 14 avril 2011 à 18:41 +0300, Avi Kivity a écrit :
>
> >  I'm talking about optimizing the generated code.  For example, bpf has
> >  just two registers so a complex program generates a lot of loads and
> >  stores.  An optimizing compiler can use extra target registers to avoid
> >  those spills, and doesn't need to keep A and X in fixed registers.
> >
>
> Thats not exactly true.
>
> A bpf filter also uses up to 16 mem[] 'registers'.
>

That's what I referred as loads and stores.  Since you can't use mem[] 
to index into a packet, you have to spill X into mem[], calculate a new 
X, use it to access the packet, and reload X.

> A risc cpu (with a lot of registers) could use registers to hold part of
> the mem[] array.

An optimizing compiler will dynamically assign mem[] into registers, 
even on i386.  Liveness analysis means the same machine register can be 
used for different mem[] locations.

> >  If you translate the bpf program to C and optimize that with gcc you'll
> >  probably get much better machine code that the jit in the patch.
> >
>
> Well, gcc wont optimize a lot a bpf program if you ask me.

IMO, it will.  I'll try to have gcc optimize your example filter later.

> You would better make tcpdump not generate bpf but direct C code.

That involves breaking the interface (plus, we might not trust tcpdump).

-- 
error compiling committee.c: too many arguments to function