netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.h.duyck@redhat.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net
Subject: [next-next PATCH 1/7] fib_trie: Use index & (~0ul << n->bits) instead of index >> n->bits
Date: Thu, 22 Jan 2015 15:51:08 -0800	[thread overview]
Message-ID: <20150122235108.5779.95865.stgit@ahduyck-vm-fedora20> (raw)
In-Reply-To: <20150122234652.5779.44251.stgit@ahduyck-vm-fedora20>

In doing performance testing and analysis of the changes I recently found
that by shifting the index I had created an unnecessary dependency.

I have updated the code so that we instead shift a mask by bits and then
just test against that as that should save us about 2 CPU cycles since we
can generate the mask while the key and pos are being processed.

Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
---
 net/ipv4/fib_trie.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 281e5e0..dea2f80 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -961,12 +961,12 @@ static struct tnode *fib_find_node(struct trie *t, u32 key)
 		 * prefix plus zeros for the bits in the cindex. The index
 		 * is the difference between the key and this value.  From
 		 * this we can actually derive several pieces of data.
-		 *   if !(index >> bits)
-		 *     we know the value is cindex
-		 *   else
+		 *   if (index & (~0ul << bits))
 		 *     we have a mismatch in skip bits and failed
+		 *   else
+		 *     we know the value is cindex
 		 */
-		if (index >> n->bits)
+		if (index & (~0ul << n->bits))
 			return NULL;
 
 		/* we have found a leaf. Prefixes have already been compared */
@@ -1301,12 +1301,12 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
 		 * prefix plus zeros for the "bits" in the prefix. The index
 		 * is the difference between the key and this value.  From
 		 * this we can actually derive several pieces of data.
-		 *   if !(index >> bits)
-		 *     we know the value is child index
-		 *   else
+		 *   if (index & (~0ul << bits))
 		 *     we have a mismatch in skip bits and failed
+		 *   else
+		 *     we know the value is cindex
 		 */
-		if (index >> n->bits)
+		if (index & (~0ul << n->bits))
 			break;
 
 		/* we have found a leaf. Prefixes have already been compared */

  reply	other threads:[~2015-01-22 23:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-22 23:51 [next-next PATCH 0/7] Fixes and improvements for recent fib_trie updates Alexander Duyck
2015-01-22 23:51 ` Alexander Duyck [this message]
2015-01-22 23:51 ` [next-next PATCH 2/7] fib_trie: Fix RCU bug and merge similar bits of inflate/halve Alexander Duyck
2015-01-22 23:51 ` [next-next PATCH 3/7] fib_trie: Fall back to slen update on inflate/halve failure Alexander Duyck
2015-01-22 23:51 ` [next-next PATCH 4/7] fib_trie: Add collapse() and should_collapse() to resize Alexander Duyck
2015-01-22 23:51 ` [next-next PATCH 5/7] fib_trie: Use empty_children instead of counting empty nodes in stats collection Alexander Duyck
2015-01-22 23:51 ` [next-next PATCH 6/7] fib_trie: Move fib_find_alias to file where it is used Alexander Duyck
2015-01-22 23:51 ` [next-next PATCH 7/7] fib_trie: Various clean-ups for handling slen Alexander Duyck
2015-01-25 22:47 ` [next-next PATCH 0/7] Fixes and improvements for recent fib_trie updates 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=20150122235108.5779.95865.stgit@ahduyck-vm-fedora20 \
    --to=alexander.h.duyck@redhat.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 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).