All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH 3/6] IPV4 : use xor rather than multiple ands for route compare
Date: Mon, 31 Mar 2008 17:47:11 -0700	[thread overview]
Message-ID: <20080401004724.601457403@vyatta.com> (raw)
In-Reply-To: 20080401004708.009204033@vyatta.com

[-- Attachment #1: route-compare --]
[-- Type: text/plain, Size: 1275 bytes --]

The comparison in ip_route_input is a hot path, by recoding the C
"and" as bit operations, fewer conditional branches get generated
so the code should be faster. Maybe someday Gcc will be smart
enough to do this?

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

--- a/net/ipv4/route.c	2008-03-31 10:57:30.000000000 -0700
+++ b/net/ipv4/route.c	2008-03-31 11:10:44.000000000 -0700
@@ -2079,14 +2079,14 @@ 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 &&
-		    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)) {
+		if (((rth->fl.fl4_dst ^ daddr) |
+		     (rth->fl.fl4_src ^ saddr) |
+		     (rth->fl.iif ^ iif) |
+		     rth->fl.oif |
+		     (rth->fl.mark ^ skb->mark) |
+		     (rth->fl.fl4_tos ^ tos) |
+		     (rth->rt_genid ^ atomic_read(&rt_genid))) == 0 &&
+		    net_eq(dev_net(rth->u.dst.dev), net)) {
 			dst_use(&rth->u.dst, jiffies);
 			RT_CACHE_STAT_INC(in_hit);
 			rcu_read_unlock();

-- 


  parent reply	other threads:[~2008-04-01  2:31 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 ` Stephen Hemminger [this message]
2008-04-01  5:52   ` [PATCH 3/6] IPV4 : use xor rather than multiple ands for route compare 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
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=20080401004724.601457403@vyatta.com \
    --to=shemminger@vyatta.com \
    --cc=davem@davemloft.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.