Skip to content

Commit

Permalink
net: Avoid modulus in skb_tx_hash() for forwarding case.
Browse files Browse the repository at this point in the history
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 <davem@davemloft.net>
  • Loading branch information
David S. Miller committed May 3, 2009
1 parent accc5b4 commit 513de11
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 513de11

Please sign in to comment.