From: David S. Miller Date: Sun, 3 May 2009 21:43:10 +0000 (-0700) Subject: net: Avoid modulus in skb_tx_hash() for forwarding case. X-Git-Tag: v2.6.31-rc1~330^2~489 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=513de11bba246b7a67df4c314d9fc936b6a75d0e;p=~emulex%2Finfiniband.git net: Avoid modulus in skb_tx_hash() for forwarding case. Based almost entirely upon a patch by Eric Dumazet. The common case is to have num-tx-queues <= num_rx_queues and even if num_tx_queues is larger it will not be significantly larger. Therefore, a subtraction loop is always going to be faster than modulus. Signed-off-by: David S. Miller --- diff --git a/net/core/dev.c b/net/core/dev.c index 81442957c5c..3c8073fe970 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1735,8 +1735,12 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) { u32 hash; - if (skb_rx_queue_recorded(skb)) - return skb_get_rx_queue(skb) % dev->real_num_tx_queues; + if (skb_rx_queue_recorded(skb)) { + hash = skb_get_rx_queue(skb); + while (unlikely (hash >= dev->real_num_tx_queues)) + hash -= dev->real_num_tx_queues; + return hash; + } if (skb->sk && skb->sk->sk_hash) hash = skb->sk->sk_hash;