[PATCH net-next-2.6] rps: consistent rxhash

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Tuesday, April 20, 2010 - 12:56 am

In case we compute a software skb->rxhash, we can generate a consistent
hash : Its value will be the same in both flow directions.

This helps some workloads, like conntracking, since the same state needs
to be accessed in both directions.

tbench + RFS + this patch gives better results than tbench with default
kernel configuration (no RPS, no RFS)

Also fixed some sparse warnings.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/core/dev.c |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 05a2b29..cb150ec 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1974,7 +1974,7 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb)
 	if (skb->sk && skb->sk->sk_hash)
 		hash = skb->sk->sk_hash;
 	else
-		hash = skb->protocol;
+		hash = (__force u16) skb->protocol;
 
 	hash = jhash_1word(hash, hashrnd);
 
@@ -2253,8 +2253,8 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
 
 		ip = (struct iphdr *) skb->data;
 		ip_proto = ip->protocol;
-		addr1 = ip->saddr;
-		addr2 = ip->daddr;
+		addr1 = (__force u32) ip->saddr;
+		addr2 = (__force u32) ip->daddr;
 		ihl = ip->ihl;
 		break;
 	case __constant_htons(ETH_P_IPV6):
@@ -2263,8 +2263,8 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
 
 		ip6 = (struct ipv6hdr *) skb->data;
 		ip_proto = ip6->nexthdr;
-		addr1 = ip6->saddr.s6_addr32[3];
-		addr2 = ip6->daddr.s6_addr32[3];
+		addr1 = (__force u32) ip6->saddr.s6_addr32[3];
+		addr2 = (__force u32) ip6->daddr.s6_addr32[3];
 		ihl = (40 >> 2);
 		break;
 	default:
@@ -2279,14 +2279,25 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
 	case IPPROTO_AH:
 	case IPPROTO_SCTP:
 	case IPPROTO_UDPLITE:
-		if (pskb_may_pull(skb, (ihl * 4) + 4))
-			ports = *((u32 *) (skb->data + (ihl * 4)));
+		if (pskb_may_pull(skb, (ihl * 4) + 4)) {
+			__be16 *hports = (__be16 *) (skb->data + (ihl * 4));
+			u32 sport, dport;
+
+			sport = (__force u16) hports[0];
+			dport = (__force u16) hports[1];
+			if (dport < sport)
+				swap(sport, dport);
+			ports = (sport << 16) + dport;
+		}
 		break;
 
 	default:
 		break;
 	}
 
+	/* get a consistent hash (same value on both flow directions) */
+	if (addr2 < addr1)
+		swap(addr1, addr2);
 	skb->rxhash = jhash_3words(addr1, addr2, ports, hashrnd);
 	if (!skb->rxhash)
 		skb->rxhash = 1;


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Thu Apr 15, 10:47 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Thu Apr 15, 11:33 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Thu Apr 15, 11:56 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 12:18 am)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Fri Apr 16, 12:26 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 12:48 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Andi Kleen, (Fri Apr 16, 4:57 am)
Re: [PATCH v5] rfs: Receive Flow Steering, jamal, (Fri Apr 16, 6:32 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Andi Kleen, (Fri Apr 16, 6:42 am)
Re: [PATCH v5] rfs: Receive Flow Steering, jamal, (Fri Apr 16, 7:05 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Andi Kleen, (Fri Apr 16, 8:28 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Fri Apr 16, 8:35 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 11:15 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Fri Apr 16, 11:35 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 11:53 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 12:37 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Fri Apr 16, 1:42 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 2:12 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Fri Apr 16, 2:25 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Fri Apr 16, 3:49 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Fri Apr 16, 3:53 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Fri Apr 16, 3:57 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Fri Apr 16, 5:22 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Fri Apr 16, 5:58 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Sat Apr 17, 9:10 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Sat Apr 17, 10:38 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Changli Gao, (Sat Apr 17, 5:06 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Franco Fichtner, (Sun Apr 18, 4:06 am)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Mon Apr 19, 1:09 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Mon Apr 19, 1:23 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Mon Apr 19, 1:32 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Mon Apr 19, 2:19 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Changli Gao, (Mon Apr 19, 4:38 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Mon Apr 19, 10:59 pm)
[PATCH net-next-2.6] rps: consistent rxhash, Eric Dumazet, (Tue Apr 20, 12:56 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, David Miller, (Tue Apr 20, 1:18 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Franco Fichtner, (Tue Apr 20, 5:48 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Eric Dumazet, (Tue Apr 20, 6:16 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Franco Fichtner, (Tue Apr 20, 7:03 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Eric Dumazet, (Tue Apr 20, 7:57 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Tom Herbert, (Tue Apr 20, 8:04 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Tom Herbert, (Tue Apr 20, 8:09 am)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Tue Apr 20, 8:39 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, David Miller, (Tue Apr 20, 2:41 pm)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Changli Gao, (Tue Apr 20, 4:35 pm)
Re: [PATCH net-next-2.6] rps: consistent rxhash, David Miller, (Tue Apr 20, 4:38 pm)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Franco Fichtner, (Wed Apr 21, 2:29 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Eric Dumazet, (Wed Apr 21, 2:39 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Franco Fichtner, (Wed Apr 21, 4:06 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Eric Dumazet, (Wed Apr 21, 4:16 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Tom Herbert, (Wed Apr 21, 12:12 pm)
Re: [PATCH net-next-2.6] rps: consistent rxhash, David Miller, (Fri Apr 23, 1:44 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Mon Apr 26, 1:41 am)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Tue Apr 27, 2:59 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, Eric Dumazet, (Tue Apr 27, 3:08 pm)
Re: [PATCH v5] rfs: Receive Flow Steering, David Miller, (Tue Apr 27, 3:10 pm)
Re: [PATCH net-next-2.6] rps: consistent rxhash, David Miller, (Thu May 6, 1:06 am)
Re: [PATCH net-next-2.6] rps: consistent rxhash, Tom Herbert, (Thu May 6, 7:45 am)