diff options
author | Krishna Kumar <krkumar2@in.ibm.com> | 2009-02-18 20:55:02 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-02-18 20:55:02 -0500 |
commit | e88721f87d8caa679e62d6004a9a5661f1ac7b0e (patch) | |
tree | 4e5ad54f7445631ac2ec5750dbe245e6c26a140c /net/core | |
parent | 38bb045d493cc166920834087acd934dedc1b5d5 (diff) |
net: Optimize skb_tx_hash() by eliminating a comparison
Optimize skb_tx_hash() by eliminating a comparison that executes for
every packet. skb_tx_hashrnd initialization is moved to a later part of
the startup sequence, namely after the "random" driver is initialized.
Rebooted the system three times and verified that the code generates
different random numbers each time.
Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/dev.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index d393fc997cd9..5493394118fb 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -1745,17 +1745,11 @@ out_kfree_skb: | |||
1745 | } | 1745 | } |
1746 | 1746 | ||
1747 | static u32 skb_tx_hashrnd; | 1747 | static u32 skb_tx_hashrnd; |
1748 | static int skb_tx_hashrnd_initialized = 0; | ||
1749 | 1748 | ||
1750 | static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb) | 1749 | static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb) |
1751 | { | 1750 | { |
1752 | u32 hash; | 1751 | u32 hash; |
1753 | 1752 | ||
1754 | if (unlikely(!skb_tx_hashrnd_initialized)) { | ||
1755 | get_random_bytes(&skb_tx_hashrnd, 4); | ||
1756 | skb_tx_hashrnd_initialized = 1; | ||
1757 | } | ||
1758 | |||
1759 | if (skb_rx_queue_recorded(skb)) { | 1753 | if (skb_rx_queue_recorded(skb)) { |
1760 | hash = skb_get_rx_queue(skb); | 1754 | hash = skb_get_rx_queue(skb); |
1761 | } else if (skb->sk && skb->sk->sk_hash) { | 1755 | } else if (skb->sk && skb->sk->sk_hash) { |
@@ -5291,6 +5285,14 @@ out: | |||
5291 | 5285 | ||
5292 | subsys_initcall(net_dev_init); | 5286 | subsys_initcall(net_dev_init); |
5293 | 5287 | ||
5288 | static int __init initialize_hashrnd(void) | ||
5289 | { | ||
5290 | get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd)); | ||
5291 | return 0; | ||
5292 | } | ||
5293 | |||
5294 | late_initcall_sync(initialize_hashrnd); | ||
5295 | |||
5294 | EXPORT_SYMBOL(__dev_get_by_index); | 5296 | EXPORT_SYMBOL(__dev_get_by_index); |
5295 | EXPORT_SYMBOL(__dev_get_by_name); | 5297 | EXPORT_SYMBOL(__dev_get_by_name); |
5296 | EXPORT_SYMBOL(__dev_remove_pack); | 5298 | EXPORT_SYMBOL(__dev_remove_pack); |