netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 10/13]: net: Implement simple sw TX hashing.
Date: Fri, 11 Jul 2008 22:49:47 +0200	[thread overview]
Message-ID: <4877C76B.6010504@cosmosbay.com> (raw)
In-Reply-To: <20080710.035713.204601759.davem@davemloft.net>

David Miller a écrit :
> It just xor hashes over IPv4/IPv6 addresses and ports of transport.
> 
> The only assumption it makes is that skb_network_header() is set
> correctly.
> 
> Signed-off-by: David S. Miller <davem@davemloft.net>
> ---
>  net/core/dev.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 52 insertions(+), 0 deletions(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index db95b49..62459ea 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -121,6 +121,9 @@
>  #include <linux/ctype.h>
>  #include <linux/if_arp.h>
>  #include <linux/if_vlan.h>
> +#include <linux/ip.h>
> +#include <linux/ipv6.h>
> +#include <linux/in.h>
>  
>  #include "net-sysfs.h"
>  
> @@ -1665,6 +1668,53 @@ out_kfree_skb:
>   *          --BLG
>   */
>  
> +static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb)
> +{
> +	u32 *addr, *ports, hash, ihl;
> +	u8 ip_proto;
> +	int alen;
> +
> +	switch (skb->protocol) {
> +	case __constant_htons(ETH_P_IP):
> +		ip_proto = ip_hdr(skb)->protocol;
> +		addr = &ip_hdr(skb)->saddr;
> +		ihl = ip_hdr(skb)->ihl;
> +		alen = 2;
> +		break;
> +	case __constant_htons(ETH_P_IPV6):
> +		ip_proto = ipv6_hdr(skb)->nexthdr;
> +		addr = &ipv6_hdr(skb)->saddr.s6_addr32[0];
> +		ihl = (40 >> 2);
> +		alen = 8;
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	ports = (u32 *) (skb_network_header(skb) + (ihl * 4));
> +
> +	hash = 0;
> +	while (alen--)
> +		hash ^= *addr++;
> +
> +	switch (ip_proto) {
> +	case IPPROTO_TCP:
> +	case IPPROTO_UDP:
> +	case IPPROTO_DCCP:
> +	case IPPROTO_ESP:
> +	case IPPROTO_AH:
> +	case IPPROTO_SCTP:
> +	case IPPROTO_UDPLITE:
> +		hash ^= *ports;
> +		break;
> +
> +	default:
> +		break;
> +	}
> +
> +	return hash % dev->real_num_tx_queues;

simple but expensive... but could be changed to use reciprocal_divide() if necessary...

> +}
> +
>  static struct netdev_queue *dev_pick_tx(struct net_device *dev,
>  					struct sk_buff *skb)
>  {
> @@ -1672,6 +1722,8 @@ static struct netdev_queue *dev_pick_tx(struct net_device *dev,
>  
>  	if (dev->select_queue)
>  		queue_index = dev->select_queue(dev, skb);
> +	else if (dev->real_num_tx_queues)

I guess your intent was to check you have at least 2 queues ?

"else if (dev->real_num_tx_queues > 1)"

> +		queue_index = simple_tx_hash(dev, skb);
>  
>  	skb_set_queue_mapping(skb, queue_index);
>  	return netdev_get_tx_queue(dev, queue_index);





  reply	other threads:[~2008-07-11 20:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10 10:57 [PATCH 10/13]: net: Implement simple sw TX hashing David Miller
2008-07-11 20:49 ` Eric Dumazet [this message]
2008-07-14 11:33   ` Herbert Xu
2008-07-14 11:58     ` David Miller
2008-07-15  6:49       ` Eric Dumazet
2008-07-15  6:58         ` David Miller
2008-07-15 10:45         ` David Miller
2008-07-17 16:16 ` Stephen Hemminger
2008-07-17 16:21   ` Patrick McHardy
2008-07-19  7:26     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4877C76B.6010504@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).