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

gro: Optimise IPv4 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 does some obvious changes to use 2-byte and 4-byte
operations instead of byte-oriented ones where possible. Bit
ops are also used to replace logical ops to reduce branching.

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

+7 -6
+7 -6
net/ipv4/af_inet.c
··· 1263 1263 if (!ops || !ops->gro_receive) 1264 1264 goto out_unlock; 1265 1265 1266 - if (iph->version != 4 || iph->ihl != 5) 1266 + if (*(u8 *)iph != 0x45) 1267 1267 goto out_unlock; 1268 1268 1269 1269 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) ··· 1281 1281 1282 1282 iph2 = ip_hdr(p); 1283 1283 1284 - if (iph->protocol != iph2->protocol || 1285 - iph->tos != iph2->tos || 1286 - memcmp(&iph->saddr, &iph2->saddr, 8)) { 1284 + if ((iph->protocol ^ iph2->protocol) | 1285 + (iph->tos ^ iph2->tos) | 1286 + (iph->saddr ^ iph2->saddr) | 1287 + (iph->daddr ^ iph2->daddr)) { 1287 1288 NAPI_GRO_CB(p)->same_flow = 0; 1288 1289 continue; 1289 1290 } 1290 1291 1291 1292 /* All fields must match except length and checksum. */ 1292 1293 NAPI_GRO_CB(p)->flush |= 1293 - memcmp(&iph->frag_off, &iph2->frag_off, 4) || 1294 - (u16)(ntohs(iph2->id) + NAPI_GRO_CB(p)->count) != id; 1294 + (iph->ttl ^ iph2->ttl) | 1295 + ((u16)(ntohs(iph2->id) + NAPI_GRO_CB(p)->count) ^ id); 1295 1296 1296 1297 NAPI_GRO_CB(p)->flush |= flush; 1297 1298 }