Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gro: Optimise TCP packet reception

gro: Optimise TCP packet reception

As this function can be called more than half a million times for
10GbE, it's important to optimise it as much as we can.

This patch uses bit ops to logical ops, as well as open coding
memcmp to exploit alignment properties.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Herbert Xu and committed by
David S. Miller
aa6320d3 a5ad24be

+8 -7
+8 -7
net/ipv4/tcp.c
··· 2478 2478 struct tcphdr *th2; 2479 2479 unsigned int thlen; 2480 2480 unsigned int flags; 2481 - unsigned int total; 2482 2481 unsigned int mss = 1; 2483 2482 int flush = 1; 2483 + int i; 2484 2484 2485 2485 th = skb_gro_header(skb, sizeof(*th)); 2486 2486 if (unlikely(!th)) ··· 2504 2504 2505 2505 th2 = tcp_hdr(p); 2506 2506 2507 - if (th->source != th2->source || th->dest != th2->dest) { 2507 + if ((th->source ^ th2->source) | (th->dest ^ th2->dest)) { 2508 2508 NAPI_GRO_CB(p)->same_flow = 0; 2509 2509 continue; 2510 2510 } ··· 2519 2519 flush |= flags & TCP_FLAG_CWR; 2520 2520 flush |= (flags ^ tcp_flag_word(th2)) & 2521 2521 ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH); 2522 - flush |= th->ack_seq != th2->ack_seq || th->window != th2->window; 2523 - flush |= memcmp(th + 1, th2 + 1, thlen - sizeof(*th)); 2522 + flush |= (th->ack_seq ^ th2->ack_seq) | (th->window ^ th2->window); 2523 + for (i = sizeof(*th); !flush && i < thlen; i += 4) 2524 + flush |= *(u32 *)((u8 *)th + i) ^ 2525 + *(u32 *)((u8 *)th2 + i); 2524 2526 2525 - total = skb_gro_len(p); 2526 2527 mss = skb_shinfo(p)->gso_size; 2527 2528 2528 - flush |= skb_gro_len(skb) > mss || !skb_gro_len(skb); 2529 - flush |= ntohl(th2->seq) + total != ntohl(th->seq); 2529 + flush |= (skb_gro_len(skb) > mss) | !skb_gro_len(skb); 2530 + flush |= (ntohl(th2->seq) + skb_gro_len(p)) ^ ntohl(th->seq); 2530 2531 2531 2532 if (flush || skb_gro_receive(head, skb)) { 2532 2533 mss = 1;