1
0

080-19-fib_trie-Use-index-0ul-n-bits-instead-of-index-n-bit.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From: Alexander Duyck <alexander.h.duyck@redhat.com>
  2. Date: Thu, 22 Jan 2015 15:51:08 -0800
  3. Subject: [PATCH] fib_trie: Use index & (~0ul << n->bits) instead of index >>
  4. n->bits
  5. In doing performance testing and analysis of the changes I recently found
  6. that by shifting the index I had created an unnecessary dependency.
  7. I have updated the code so that we instead shift a mask by bits and then
  8. just test against that as that should save us about 2 CPU cycles since we
  9. can generate the mask while the key and pos are being processed.
  10. Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
  11. Signed-off-by: David S. Miller <davem@davemloft.net>
  12. ---
  13. --- a/net/ipv4/fib_trie.c
  14. +++ b/net/ipv4/fib_trie.c
  15. @@ -961,12 +961,12 @@ static struct tnode *fib_find_node(struc
  16. * prefix plus zeros for the bits in the cindex. The index
  17. * is the difference between the key and this value. From
  18. * this we can actually derive several pieces of data.
  19. - * if !(index >> bits)
  20. - * we know the value is cindex
  21. - * else
  22. + * if (index & (~0ul << bits))
  23. * we have a mismatch in skip bits and failed
  24. + * else
  25. + * we know the value is cindex
  26. */
  27. - if (index >> n->bits)
  28. + if (index & (~0ul << n->bits))
  29. return NULL;
  30. /* we have found a leaf. Prefixes have already been compared */
  31. @@ -1301,12 +1301,12 @@ int fib_table_lookup(struct fib_table *t
  32. * prefix plus zeros for the "bits" in the prefix. The index
  33. * is the difference between the key and this value. From
  34. * this we can actually derive several pieces of data.
  35. - * if !(index >> bits)
  36. - * we know the value is child index
  37. - * else
  38. + * if (index & (~0ul << bits))
  39. * we have a mismatch in skip bits and failed
  40. + * else
  41. + * we know the value is cindex
  42. */
  43. - if (index >> n->bits)
  44. + if (index & (~0ul << n->bits))
  45. break;
  46. /* we have found a leaf. Prefixes have already been compared */