Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Tom Herbert <therbert@google.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH 2/4] rps: Add flag to skb to indicate rxhash is on L4 tuple
Date: Thu, 19 May 2011 22:26:54 +0200	[thread overview]
Message-ID: <1305836814.3156.21.camel@edumazet-laptop> (raw)
In-Reply-To: <alpine.DEB.2.00.1105190827240.12799@pokey.mtv.corp.google.com>

Le jeudi 19 mai 2011 à 08:39 -0700, Tom Herbert a écrit :
> The l4_rxhash flag was added to the skb structure to indicate
> that the rxhash value was computed over the 4 tuple for the
> packet which includes the port information in the encapsulated
> transport packet.  This is used by the stack to preserve the
> rxhash value in __skb_rx_tunnel.
> 
> Signed-off-by: Tom Herbert <therbert@google.com>
> ---
>  include/linux/skbuff.h |    5 +++--
>  include/net/dst.h      |    9 ++++++++-
>  include/net/sock.h     |   14 +++++++++++---
>  net/core/dev.c         |   17 +++++++++++------
>  net/core/skbuff.c      |    1 +
>  net/ipv4/tcp_ipv4.c    |    4 ++--
>  net/ipv4/udp.c         |    4 ++--
>  7 files changed, 38 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 79aafbb..4fab336 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -397,6 +397,7 @@ struct sk_buff {
>  	__u8			ndisc_nodetype:2;
>  #endif
>  	__u8			ooo_okay:1;
> +	__u8			l4_rxhash:1;
>  	kmemcheck_bitfield_end(flags2);
>  
>  	/* 0/13 bit hole */
> @@ -555,11 +556,11 @@ extern unsigned int   skb_find_text(struct sk_buff *skb, unsigned int from,
>  				    unsigned int to, struct ts_config *config,
>  				    struct ts_state *state);
>  
> -extern __u32 __skb_get_rxhash(struct sk_buff *skb);
> +extern void __skb_get_rxhash(struct sk_buff *skb);
>  static inline __u32 skb_get_rxhash(struct sk_buff *skb)
>  {
>  	if (!skb->rxhash)
> -		skb->rxhash = __skb_get_rxhash(skb);
> +		__skb_get_rxhash(skb);
>  
>  	return skb->rxhash;
>  }
> diff --git a/include/net/dst.h b/include/net/dst.h
> index 07a0402..17ff602 100644
> --- a/include/net/dst.h
> +++ b/include/net/dst.h
> @@ -307,7 +307,14 @@ static inline void skb_dst_force(struct sk_buff *skb)
>  static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
>  {
>  	skb->dev = dev;
> -	skb->rxhash = 0;
> +
> +	/*
> +	 * Clear rxhash so that we can reculate the hash for the

typo ?

> +	 * encapsulated packet, unless we have already determine the hash
> +	 * over the L4 4-tuple.
> +	 */
> +	if (!skb->l4_rxhash)
> +		skb->rxhash = 0;
>  	skb_set_queue_mapping(skb, 0);
>  	skb_dst_drop(skb);
>  	nf_reset(skb);
> diff --git a/include/net/sock.h b/include/net/sock.h
> index f2046e4..e670c41 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -685,16 +685,24 @@ static inline void sock_rps_reset_flow(const struct sock *sk)
>  #endif
>  }
>  
> -static inline void sock_rps_save_rxhash(struct sock *sk, u32 rxhash)
> +static inline void sock_rps_save_rxhash(struct sock *sk, struct sk_buff *skb)

const struct sk_buff *skb ?

>  {
>  #ifdef CONFIG_RPS
> -	if (unlikely(sk->sk_rxhash != rxhash)) {
> +	if (unlikely(sk->sk_rxhash != skb->rxhash)) {
>  		sock_rps_reset_flow(sk);
> -		sk->sk_rxhash = rxhash;
> +		sk->sk_rxhash = skb->rxhash;
>  	}
>  #endif
>  }
>  
> +static inline void sock_rps_reset_rxhash(struct sock *sk)
> +{
> +#ifdef CONFIG_RPS
> +	sock_rps_reset_flow(sk);
> +	sk->sk_rxhash = 0;
> +#endif
> +}
> +
>  #define sk_wait_event(__sk, __timeo, __condition)			\
>  	({	int __rc;						\
>  		release_sock(__sk);					\
> diff --git a/net/core/dev.c b/net/core/dev.c
> index a40eea9..37ddece 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -2014,8 +2014,10 @@ static inline void skb_orphan_try(struct sk_buff *skb)
>  		/* skb_tx_hash() wont be able to get sk.
>  		 * We copy sk_hash into skb->rxhash
>  		 */
> -		if (!skb->rxhash)
> +		if (!skb->rxhash) {
>  			skb->rxhash = sk->sk_hash;
> +			skb->l4_rxhash = 1;

Why do you set l4_rxhash here ?

> +		}
>  		skb_orphan(skb);
>  	}
>  }
> @@ -2499,12 +2501,13 @@ static inline void ____napi_schedule(struct softnet_data *sd,
>  
>  /*
>   * __skb_get_rxhash: calculate a flow hash based on src/dst addresses
> - * and src/dst port numbers. Returns a non-zero hash number on success
> - * and 0 on failure.
> + * and src/dst port numbers.  Sets rxhash in skb to non-zero hash value
> + * on success, zero indicates no valid hash.  Also, sets l4_rxhash in skb
> + * if hash is a canonical 4-tuple hash over transport ports.
>   */
> -__u32 __skb_get_rxhash(struct sk_buff *skb)
> +void __skb_get_rxhash(struct sk_buff *skb)
>  {
> -	int nhoff, hash = 0, poff;
> +	int nhoff, hash = 0, l4hash = 0, poff;
>  	const struct ipv6hdr *ip6;
>  	const struct iphdr *ip;
>  	u8 ip_proto;
> @@ -2554,6 +2557,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
>  			ports.v32 = * (__force u32 *) (skb->data + nhoff);
>  			if (ports.v16[1] < ports.v16[0])
>  				swap(ports.v16[0], ports.v16[1]);
> +			l4hash = 1;

maybe directly set skb->l4_rxhash = 1 here ?

		
>  		}
>  	}
>  
> @@ -2566,7 +2570,8 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
>  		hash = 1;
>  
>  done:
> -	return hash;
> +	skb->rxhash = hash;
> +	skb->l4_rxhash = l4hash;

and remove this line.  (gcc is pretty expensive here for a one bit
field)


Thanks



      reply	other threads:[~2011-05-19 20:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-19 15:39 [PATCH 2/4] rps: Add flag to skb to indicate rxhash is on L4 tuple Tom Herbert
2011-05-19 20:26 ` Eric Dumazet [this message]

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=1305836814.3156.21.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=therbert@google.com \
    /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