Commit 5c74501f authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipv4: save cpu cycles from check_leaf()

Compiler is not smart enough to avoid double BSWAP instructions in
ntohl(inet_make_mask(plen)).

Lets cache this value in struct leaf_info, (fill a hole on 64bit arches)

With route cache disabled, this saves ~2% of cpu in udpflood bench on
x86_64 machine.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d3aaeb38
...@@ -110,9 +110,10 @@ struct leaf { ...@@ -110,9 +110,10 @@ struct leaf {
struct leaf_info { struct leaf_info {
struct hlist_node hlist; struct hlist_node hlist;
struct rcu_head rcu;
int plen; int plen;
u32 mask_plen; /* ntohl(inet_make_mask(plen)) */
struct list_head falh; struct list_head falh;
struct rcu_head rcu;
}; };
struct tnode { struct tnode {
...@@ -451,6 +452,7 @@ static struct leaf_info *leaf_info_new(int plen) ...@@ -451,6 +452,7 @@ static struct leaf_info *leaf_info_new(int plen)
struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL); struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL);
if (li) { if (li) {
li->plen = plen; li->plen = plen;
li->mask_plen = ntohl(inet_make_mask(plen));
INIT_LIST_HEAD(&li->falh); INIT_LIST_HEAD(&li->falh);
} }
return li; return li;
...@@ -1359,10 +1361,8 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, ...@@ -1359,10 +1361,8 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l,
hlist_for_each_entry_rcu(li, node, hhead, hlist) { hlist_for_each_entry_rcu(li, node, hhead, hlist) {
struct fib_alias *fa; struct fib_alias *fa;
int plen = li->plen;
__be32 mask = inet_make_mask(plen);
if (l->key != (key & ntohl(mask))) if (l->key != (key & li->mask_plen))
continue; continue;
list_for_each_entry_rcu(fa, &li->falh, fa_list) { list_for_each_entry_rcu(fa, &li->falh, fa_list) {
...@@ -1394,7 +1394,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, ...@@ -1394,7 +1394,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l,
#ifdef CONFIG_IP_FIB_TRIE_STATS #ifdef CONFIG_IP_FIB_TRIE_STATS
t->stats.semantic_match_passed++; t->stats.semantic_match_passed++;
#endif #endif
res->prefixlen = plen; res->prefixlen = li->plen;
res->nh_sel = nhsel; res->nh_sel = nhsel;
res->type = fa->fa_type; res->type = fa->fa_type;
res->scope = fa->fa_info->fib_scope; res->scope = fa->fa_info->fib_scope;
...@@ -1402,7 +1402,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, ...@@ -1402,7 +1402,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l,
res->table = tb; res->table = tb;
res->fa_head = &li->falh; res->fa_head = &li->falh;
if (!(fib_flags & FIB_LOOKUP_NOREF)) if (!(fib_flags & FIB_LOOKUP_NOREF))
atomic_inc(&res->fi->fib_clntref); atomic_inc(&fi->fib_clntref);
return 0; return 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment