提交 874ffa8f 编写于 作者: E Eric Dumazet 提交者: David S. Miller

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: NEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 a0a4a85a
...@@ -1384,8 +1384,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp, ...@@ -1384,8 +1384,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp,
t_key cindex = 0; t_key cindex = 0;
int current_prefix_length = KEYLENGTH; int current_prefix_length = KEYLENGTH;
struct tnode *cn; struct tnode *cn;
t_key node_prefix, key_prefix, pref_mismatch; t_key pref_mismatch;
int mp;
rcu_read_lock(); rcu_read_lock();
...@@ -1500,10 +1499,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp, ...@@ -1500,10 +1499,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp,
* matching prefix. * matching prefix.
*/ */
node_prefix = mask_pfx(cn->key, cn->pos); pref_mismatch = mask_pfx(cn->key ^ key, cn->pos);
key_prefix = mask_pfx(key, cn->pos);
pref_mismatch = key_prefix^node_prefix;
mp = 0;
/* /*
* In short: If skipped bits in this node do not match * 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,13 +1507,9 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi *flp,
* state.directly. * state.directly.
*/ */
if (pref_mismatch) { if (pref_mismatch) {
while (!(pref_mismatch & (1<<(KEYLENGTH-1)))) { int mp = KEYLENGTH - fls(pref_mismatch);
mp++;
pref_mismatch = pref_mismatch << 1;
}
key_prefix = tkey_extract_bits(cn->key, mp, cn->pos-mp);
if (key_prefix != 0) if (tkey_extract_bits(cn->key, mp, cn->pos - mp) != 0)
goto backtrace; goto backtrace;
if (current_prefix_length >= cn->pos) if (current_prefix_length >= cn->pos)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册