netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: yoshfuji@linux-ipv6.org
Cc: shemminger@vyatta.com, dada1@cosmosbay.com, netdev@vger.kernel.org
Subject: Re: [PATCH 3/6] IPV4 : use xor rather than multiple ands for route compare
Date: Thu, 10 Apr 2008 03:56:18 -0700 (PDT)	[thread overview]
Message-ID: <20080410.035618.217931997.davem@davemloft.net> (raw)
In-Reply-To: <20080410.180148.120248426.yoshfuji@linux-ipv6.org>

From: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>
Date: Thu, 10 Apr 2008 18:01:48 +0900 (JST)

> In article <20080410.015118.103465510.davem@davemloft.net> (at Thu, 10 Apr 2008 01:51:18 -0700 (PDT)), David Miller <davem@davemloft.net> says:
> 
> > From: Stephen Hemminger <shemminger@vyatta.com>
> > Date: Tue, 1 Apr 2008 13:08:42 -0700
> > 
> > > The flow fields are all together, and the other parameters are local variables
> > > in registers so that compare should be in one cache line.
> > > 
> > > --- a/net/ipv4/route.c	2008-03-31 17:12:30.000000000 -0700
> > > +++ b/net/ipv4/route.c	2008-04-01 13:05:46.000000000 -0700
> > > @@ -2079,12 +2079,12 @@ int ip_route_input(struct sk_buff *skb, 
> > >  	rcu_read_lock();
> > >  	for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
> > >  	     rth = rcu_dereference(rth->u.dst.rt_next)) {
> > > -		if (rth->fl.fl4_dst == daddr &&
> > > -		    rth->fl.fl4_src == saddr &&
> > > -		    rth->fl.iif == iif &&
> > > -		    rth->fl.oif == 0 &&
> > > +		if (((rth->fl.fl4_dst ^ daddr) |
> > > +		     (rth->fl.fl4_src ^ saddr) |
> > > +		     (rth->fl.iif ^ iif) |
> > > +		     rth->fl.oif |
> > > +		     (rth->fl.fl4_tos ^ tos)) == 0 &&
> > >  		    rth->fl.mark == skb->mark &&
> > > -		    rth->fl.fl4_tos == tos &&
> > >  		    net_eq(dev_net(rth->u.dst.dev), net) &&
> > >  		    rth->rt_genid == atomic_read(&rt_genid)) {
> > >  			dst_use(&rth->u.dst, jiffies);
> > 
> > Eric, any objections to this version?
> 
> I'm not Eric, but well, I'm now doubting if this is really good.
> If the comparision chain is long and it is unlikely to pass all the tests,
> it would be better to cut the line.
> If we use "or", we need to run through the test, in ayn case.

Actually the case you mention it is part of the incentive for
this change.

Branch prediction fares very poorly in such cases, and
therefore it is better to mispredict one branch over
all the data items in the same cache line than any one
of several such branches.  The above new sequence gets
emitted by the compiler as several integer operations and
one branch.  As long as all the data items are in the
same cacheline, this is optimal.

We made such a change for ethernet address comparisons a
few years ago.  At the time Eric showed that it mattered
a lot for Athlon processors.

  reply	other threads:[~2008-04-10 10:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080401004708.009204033@vyatta.com>
2008-04-01  0:47 ` [PATCH 1/6] socket: sk_filter minor cleanups Stephen Hemminger
2008-04-10  8:39   ` David Miller
2008-04-01  0:47 ` [PATCH 2/6] socket: sk_filter deinline Stephen Hemminger
2008-04-10  8:49   ` David Miller
2008-04-01  0:47 ` [PATCH 3/6] IPV4 : use xor rather than multiple ands for route compare Stephen Hemminger
2008-04-01  5:52   ` Eric Dumazet
2008-04-01 20:08     ` Stephen Hemminger
2008-04-10  8:51       ` David Miller
2008-04-10  9:01         ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-10 10:56           ` David Miller [this message]
2008-04-10 12:17             ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-10  9:26         ` Eric Dumazet
2008-04-10 11:00           ` David Miller
2008-04-01  0:47 ` [PATCH 4/6] IPV4: route inline changes Stephen Hemminger
2008-04-10  8:53   ` David Miller
2008-04-01  0:47 ` [PATCH 5/6] IPV4: route use jhash3 Stephen Hemminger
2008-04-10  8:54   ` David Miller
2008-04-01  0:47 ` [PATCH 6/6] IPV4: route rekey timer can be deferrable Stephen Hemminger
2008-04-10  8:55   ` David Miller

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=20080410.035618.217931997.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dada1@cosmosbay.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    --cc=yoshfuji@linux-ipv6.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).