diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-10-13 02:56:11 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-10-16 14:13:22 -0400 |
commit | 874ffa8f72444d6253d2669fed304875c128f86b (patch) | |
tree | 1b00dc1984fa2984020c06fbc1e48b8c00366f02 /net/ipv4 | |
parent | a0a4a85a15df6335e3d11f83b2ac06ebebea313f (diff) |
fib_trie: use fls() instead of open coded loop
fib_table_lookup() might use fls() to speedup an open coded loop.
Noticed while doing a profile analysis.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/fib_trie.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 271c89bdf049..31494f335686 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -1384,8 +1384,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp, | |||
1384 | t_key cindex = 0; | 1384 | t_key cindex = 0; |
1385 | int current_prefix_length = KEYLENGTH; | 1385 | int current_prefix_length = KEYLENGTH; |
1386 | struct tnode *cn; | 1386 | struct tnode *cn; |
1387 | t_key node_prefix, key_prefix, pref_mismatch; | 1387 | t_key pref_mismatch; |
1388 | int mp; | ||
1389 | 1388 | ||
1390 | rcu_read_lock(); | 1389 | rcu_read_lock(); |
1391 | 1390 | ||
@@ -1500,10 +1499,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp, | |||
1500 | * matching prefix. | 1499 | * matching prefix. |
1501 | */ | 1500 | */ |
1502 | 1501 | ||
1503 | node_prefix = mask_pfx(cn->key, cn->pos); | 1502 | pref_mismatch = mask_pfx(cn->key ^ key, cn->pos); |
1504 | key_prefix = mask_pfx(key, cn->pos); | ||
1505 | pref_mismatch = key_prefix^node_prefix; | ||
1506 | mp = 0; | ||
1507 | 1503 | ||
1508 | /* | 1504 | /* |
1509 | * In short: If skipped bits in this node do not match | 1505 | * In short: If skipped bits in this node do not match |
@@ -1511,13 +1507,9 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp, | |||
1511 | * state.directly. | 1507 | * state.directly. |
1512 | */ | 1508 | */ |
1513 | if (pref_mismatch) { | 1509 | if (pref_mismatch) { |
1514 | while (!(pref_mismatch & (1<<(KEYLENGTH-1)))) { | 1510 | int mp = KEYLENGTH - fls(pref_mismatch); |
1515 | mp++; | ||
1516 | pref_mismatch = pref_mismatch << 1; | ||
1517 | } | ||
1518 | key_prefix = tkey_extract_bits(cn->key, mp, cn->pos-mp); | ||
1519 | 1511 | ||
1520 | if (key_prefix != 0) | 1512 | if (tkey_extract_bits(cn->key, mp, cn->pos - mp) != 0) |
1521 | goto backtrace; | 1513 | goto backtrace; |
1522 | 1514 | ||
1523 | if (current_prefix_length >= cn->pos) | 1515 | if (current_prefix_length >= cn->pos) |