[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1305836814.3156.21.camel@edumazet-laptop>
Date: Thu, 19 May 2011 22:26:54 +0200
From: Eric Dumazet <eric.dumazet@...il.com>
To: Tom Herbert <therbert@...gle.com>
Cc: davem@...emloft.net, netdev@...r.kernel.org
Subject: Re: [PATCH 2/4] rps: Add flag to skb to indicate rxhash is on L4
tuple
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@...gle.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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists