Commit de5a1f3c authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

net: gro: minor optimization for dev_gro_receive()

While inspecting some perf report, I noticed that the compiler
emits suboptimal code for the napi CB initialization, fetching
and storing multiple times the memory for flags bitfield.
This is with gcc 10.3.1, but I observed the same with older compiler
versions.

We can help the compiler to do a nicer work clearing several
fields at once using an u32 alias. The generated code is quite
smaller, with the same number of conditional.

Before:
objdump -t net/core/gro.o | grep " F .text"
0000000000000bb0 l     F .text	0000000000000357 dev_gro_receive

After:
0000000000000bb0 l     F .text	000000000000033c dev_gro_receive

v1  -> v2:
 - use struct_group (Alexander and Alex)

RFC -> v1:
 - use __struct_group to delimit the zeroed area (Alexander)
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7881453e
...@@ -29,46 +29,50 @@ struct napi_gro_cb { ...@@ -29,46 +29,50 @@ struct napi_gro_cb {
/* Number of segments aggregated. */ /* Number of segments aggregated. */
u16 count; u16 count;
/* Start offset for remote checksum offload */ /* Used in ipv6_gro_receive() and foo-over-udp */
u16 gro_remcsum_start; u16 proto;
/* jiffies when first packet was created/queued */ /* jiffies when first packet was created/queued */
unsigned long age; unsigned long age;
/* Used in ipv6_gro_receive() and foo-over-udp */ /* portion of the cb set to zero at every gro iteration */
u16 proto; struct_group(zeroed,
/* Start offset for remote checksum offload */
u16 gro_remcsum_start;
/* This is non-zero if the packet may be of the same flow. */ /* This is non-zero if the packet may be of the same flow. */
u8 same_flow:1; u8 same_flow:1;
/* Used in tunnel GRO receive */ /* Used in tunnel GRO receive */
u8 encap_mark:1; u8 encap_mark:1;
/* GRO checksum is valid */ /* GRO checksum is valid */
u8 csum_valid:1; u8 csum_valid:1;
/* Number of checksums via CHECKSUM_UNNECESSARY */ /* Number of checksums via CHECKSUM_UNNECESSARY */
u8 csum_cnt:3; u8 csum_cnt:3;
/* Free the skb? */ /* Free the skb? */
u8 free:2; u8 free:2;
#define NAPI_GRO_FREE 1 #define NAPI_GRO_FREE 1
#define NAPI_GRO_FREE_STOLEN_HEAD 2 #define NAPI_GRO_FREE_STOLEN_HEAD 2
/* Used in foo-over-udp, set in udp[46]_gro_receive */ /* Used in foo-over-udp, set in udp[46]_gro_receive */
u8 is_ipv6:1; u8 is_ipv6:1;
/* Used in GRE, set in fou/gue_gro_receive */ /* Used in GRE, set in fou/gue_gro_receive */
u8 is_fou:1; u8 is_fou:1;
/* Used to determine if flush_id can be ignored */ /* Used to determine if flush_id can be ignored */
u8 is_atomic:1; u8 is_atomic:1;
/* Number of gro_receive callbacks this packet already went through */ /* Number of gro_receive callbacks this packet already went through */
u8 recursion_counter:4; u8 recursion_counter:4;
/* GRO is done by frag_list pointer chaining. */ /* GRO is done by frag_list pointer chaining. */
u8 is_flist:1; u8 is_flist:1;
);
/* used to support CHECKSUM_COMPLETE for tunneling protocols */ /* used to support CHECKSUM_COMPLETE for tunneling protocols */
__wsum csum; __wsum csum;
......
...@@ -459,29 +459,22 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff ...@@ -459,29 +459,22 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
skb_set_network_header(skb, skb_gro_offset(skb)); skb_set_network_header(skb, skb_gro_offset(skb));
skb_reset_mac_len(skb); skb_reset_mac_len(skb);
NAPI_GRO_CB(skb)->same_flow = 0; BUILD_BUG_ON(sizeof_field(struct napi_gro_cb, zeroed) != sizeof(u32));
BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct napi_gro_cb, zeroed),
sizeof(u32))); /* Avoid slow unaligned acc */
*(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0;
NAPI_GRO_CB(skb)->flush = skb_is_gso(skb) || skb_has_frag_list(skb); NAPI_GRO_CB(skb)->flush = skb_is_gso(skb) || skb_has_frag_list(skb);
NAPI_GRO_CB(skb)->free = 0;
NAPI_GRO_CB(skb)->encap_mark = 0;
NAPI_GRO_CB(skb)->recursion_counter = 0;
NAPI_GRO_CB(skb)->is_fou = 0;
NAPI_GRO_CB(skb)->is_atomic = 1; NAPI_GRO_CB(skb)->is_atomic = 1;
NAPI_GRO_CB(skb)->gro_remcsum_start = 0;
/* Setup for GRO checksum validation */ /* Setup for GRO checksum validation */
switch (skb->ip_summed) { switch (skb->ip_summed) {
case CHECKSUM_COMPLETE: case CHECKSUM_COMPLETE:
NAPI_GRO_CB(skb)->csum = skb->csum; NAPI_GRO_CB(skb)->csum = skb->csum;
NAPI_GRO_CB(skb)->csum_valid = 1; NAPI_GRO_CB(skb)->csum_valid = 1;
NAPI_GRO_CB(skb)->csum_cnt = 0;
break; break;
case CHECKSUM_UNNECESSARY: case CHECKSUM_UNNECESSARY:
NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1; NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1;
NAPI_GRO_CB(skb)->csum_valid = 0;
break; break;
default:
NAPI_GRO_CB(skb)->csum_cnt = 0;
NAPI_GRO_CB(skb)->csum_valid = 0;
} }
pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment