diff mbox

[10/14] ipv4: Use 32-bit loads for ID and length in GRO

Message ID E1M9B5x-0001Sw-RR@gondolin.me.apana.org.au
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Herbert Xu May 27, 2009, 4:50 a.m. UTC
ipv4: Use 32-bit loads for ID and length in GRO

This patch optimises the IPv4 GRO code by using 32-bit loads
(instead of 16-bit ones) on the ID and length checks in the receive
function.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 net/ipv4/af_inet.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--
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

Comments

Andi Kleen May 27, 2009, 6 p.m. UTC | #1
Herbert Xu <herbert@gondor.apana.org.au> writes:

> ipv4: Use 32-bit loads for ID and length in GRO
>
> This patch optimises the IPv4 GRO code by using 32-bit loads
> (instead of 16-bit ones) on the ID and length checks in the receive
> function.

On what architecture is that faster?

At least on x86 they should be the same performance, except that
the 16bit one is one byte larger, but that shouldn't make a difference.

-Andi
Herbert Xu May 27, 2009, 9:26 p.m. UTC | #2
On Wed, May 27, 2009 at 08:00:36PM +0200, Andi Kleen wrote:
>
> On what architecture is that faster?
> 
> At least on x86 they should be the same performance, except that
> the 16bit one is one byte larger, but that shouldn't make a difference.

It shrunk the code by more than a byte, at least with some versions
of gcc on x86-64.

Yes some of these patches might seem a tad trivial, but it does add
up.

Cheers,
diff mbox

Patch

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 644cc55..5abee4c 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1248,9 +1248,9 @@  static struct sk_buff **inet_gro_receive(struct sk_buff **head,
 	struct iphdr *iph;
 	unsigned int hlen;
 	unsigned int off;
+	unsigned int id;
 	int flush = 1;
 	int proto;
-	int id;
 
 	off = skb_gro_offset(skb);
 	hlen = off + sizeof(*iph);
@@ -1274,9 +1274,9 @@  static struct sk_buff **inet_gro_receive(struct sk_buff **head,
 	if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
 		goto out_unlock;
 
-	flush = ntohs(iph->tot_len) != skb_gro_len(skb) ||
-		iph->frag_off != htons(IP_DF);
-	id = ntohs(iph->id);
+	id = ntohl(*(u32 *)&iph->id);
+	flush = (u16)((ntohl(*(u32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
+	id >>= 16;
 
 	for (p = *head; p; p = p->next) {
 		struct iphdr *iph2;