Commit e88721f8 authored by Krishna Kumar's avatar Krishna Kumar Committed by David S. Miller

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: default avatarKrishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 38bb045d
...@@ -1745,17 +1745,11 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -1745,17 +1745,11 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
} }
static u32 skb_tx_hashrnd; static u32 skb_tx_hashrnd;
static int skb_tx_hashrnd_initialized = 0;
static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb) static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb)
{ {
u32 hash; u32 hash;
if (unlikely(!skb_tx_hashrnd_initialized)) {
get_random_bytes(&skb_tx_hashrnd, 4);
skb_tx_hashrnd_initialized = 1;
}
if (skb_rx_queue_recorded(skb)) { if (skb_rx_queue_recorded(skb)) {
hash = skb_get_rx_queue(skb); hash = skb_get_rx_queue(skb);
} else if (skb->sk && skb->sk->sk_hash) { } else if (skb->sk && skb->sk->sk_hash) {
...@@ -5291,6 +5285,14 @@ static int __init net_dev_init(void) ...@@ -5291,6 +5285,14 @@ static int __init net_dev_init(void)
subsys_initcall(net_dev_init); subsys_initcall(net_dev_init);
static int __init initialize_hashrnd(void)
{
get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd));
return 0;
}
late_initcall_sync(initialize_hashrnd);
EXPORT_SYMBOL(__dev_get_by_index); EXPORT_SYMBOL(__dev_get_by_index);
EXPORT_SYMBOL(__dev_get_by_name); EXPORT_SYMBOL(__dev_get_by_name);
EXPORT_SYMBOL(__dev_remove_pack); EXPORT_SYMBOL(__dev_remove_pack);
......
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