diff options
author | Changli Gao <xiaosuo@gmail.com> | 2010-04-25 01:50:10 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-04-25 01:50:10 -0400 |
commit | 8c52d509e84bbf26cffb8b6e75b399689af67885 (patch) | |
tree | d26461f82d204e044f68a8f85b4b4ea71682b09d /net | |
parent | bf73130d7f98c8c4db143e2dc4982f4eefd5d5e5 (diff) |
rps: optimize rps_get_cpu()
optimize rps_get_cpu().
don't initialize ports when we can get the ports. one memory access
for ports than two.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/dev.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index a4a7c36917d1..4d43f1a80f74 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -2229,7 +2229,11 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | |||
2229 | int cpu = -1; | 2229 | int cpu = -1; |
2230 | u8 ip_proto; | 2230 | u8 ip_proto; |
2231 | u16 tcpu; | 2231 | u16 tcpu; |
2232 | u32 addr1, addr2, ports, ihl; | 2232 | u32 addr1, addr2, ihl; |
2233 | union { | ||
2234 | u32 v32; | ||
2235 | u16 v16[2]; | ||
2236 | } ports; | ||
2233 | 2237 | ||
2234 | if (skb_rx_queue_recorded(skb)) { | 2238 | if (skb_rx_queue_recorded(skb)) { |
2235 | u16 index = skb_get_rx_queue(skb); | 2239 | u16 index = skb_get_rx_queue(skb); |
@@ -2275,7 +2279,6 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | |||
2275 | default: | 2279 | default: |
2276 | goto done; | 2280 | goto done; |
2277 | } | 2281 | } |
2278 | ports = 0; | ||
2279 | switch (ip_proto) { | 2282 | switch (ip_proto) { |
2280 | case IPPROTO_TCP: | 2283 | case IPPROTO_TCP: |
2281 | case IPPROTO_UDP: | 2284 | case IPPROTO_UDP: |
@@ -2285,25 +2288,20 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | |||
2285 | case IPPROTO_SCTP: | 2288 | case IPPROTO_SCTP: |
2286 | case IPPROTO_UDPLITE: | 2289 | case IPPROTO_UDPLITE: |
2287 | if (pskb_may_pull(skb, (ihl * 4) + 4)) { | 2290 | if (pskb_may_pull(skb, (ihl * 4) + 4)) { |
2288 | __be16 *hports = (__be16 *) (skb->data + (ihl * 4)); | 2291 | ports.v32 = * (__force u32 *) (skb->data + (ihl * 4)); |
2289 | u32 sport, dport; | 2292 | if (ports.v16[1] < ports.v16[0]) |
2290 | 2293 | swap(ports.v16[0], ports.v16[1]); | |
2291 | sport = (__force u16) hports[0]; | 2294 | break; |
2292 | dport = (__force u16) hports[1]; | ||
2293 | if (dport < sport) | ||
2294 | swap(sport, dport); | ||
2295 | ports = (sport << 16) + dport; | ||
2296 | } | 2295 | } |
2297 | break; | ||
2298 | |||
2299 | default: | 2296 | default: |
2297 | ports.v32 = 0; | ||
2300 | break; | 2298 | break; |
2301 | } | 2299 | } |
2302 | 2300 | ||
2303 | /* get a consistent hash (same value on both flow directions) */ | 2301 | /* get a consistent hash (same value on both flow directions) */ |
2304 | if (addr2 < addr1) | 2302 | if (addr2 < addr1) |
2305 | swap(addr1, addr2); | 2303 | swap(addr1, addr2); |
2306 | skb->rxhash = jhash_3words(addr1, addr2, ports, hashrnd); | 2304 | skb->rxhash = jhash_3words(addr1, addr2, ports.v32, hashrnd); |
2307 | if (!skb->rxhash) | 2305 | if (!skb->rxhash) |
2308 | skb->rxhash = 1; | 2306 | skb->rxhash = 1; |
2309 | 2307 | ||