Skip to content

Commit

Permalink
net: help compiler generate better code in eth_get_headlen
Browse files Browse the repository at this point in the history
Noticed that the compiler (gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC))
generated suboptimal assembler code in eth_get_headlen().

This early return coding style is usually not an issue, on super scalar CPUs,
but the compiler choose to put the return statement after this very unlikely
branch, thus creating larger jump down to the likely code path.

Performance wise, I could measure slightly less L1-icache-load-misses
and less branch-misses, and an improvement of 1 nanosec with an IP-forwarding
use-case with 257 bytes packets with ixgbe (CPU i7-4790K @ 4.00GHz).

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesper Dangaard Brouer authored and David S. Miller committed Sep 29, 2015
1 parent d2e1339 commit 8a4683a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/ethernet/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ u32 eth_get_headlen(void *data, unsigned int len)
struct flow_keys keys;

/* this should never happen, but better safe than sorry */
if (len < sizeof(*eth))
if (unlikely(len < sizeof(*eth)))
return len;

/* parse any remaining L2/L3 headers, check for L4 */
Expand Down

0 comments on commit 8a4683a

Please sign in to comment.