]> git.baikalelectronics.ru Git - kernel.git/commit
xdp: Adjust xdp_frame layout to avoid using bitfields
authorJesper Dangaard Brouer <brouer@redhat.com>
Fri, 23 Sep 2022 12:48:00 +0000 (14:48 +0200)
committerJakub Kicinski <kuba@kernel.org>
Mon, 26 Sep 2022 20:28:19 +0000 (13:28 -0700)
commitc960a94addd8180656a14bba3a0530c194d3d6d3
tree954e0bc69f01b000a72e2424105c74e70c7167ad
parent6c1c901c6f3308bc6dd6fa98e4a9b4e13419c126
xdp: Adjust xdp_frame layout to avoid using bitfields

Practical experience (and advice from Alexei) tell us that bitfields in
structs lead to un-optimized assembly code. I've verified this change
does lead to better x86_64 assembly, both via objdump and playing with
code snippets in godbolt.org.

Using scripts/bloat-o-meter shows the code size is reduced with 24
bytes for xdp_convert_buff_to_frame() that gets inlined e.g. in
i40e_xmit_xdp_tx_ring() which were used for microbenchmarking.

Microbenchmarking results do show improvements, but very small and
varying between 0.5 to 2 nanosec improvement per packet.

The member @metasize is changed from u8 to u32. Future users of this
area could split this into two u16 fields. I've also benchmarked with
two u16 fields showing equal performance gains and code size reduction.

The moved member @frame_sz doesn't change sizeof struct due to existing
padding. Like xdp_buff member @frame_sz is placed next to @flags, which
allows compiler to optimize assignment of these.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/r/166393728005.2213882.4162674859542409548.stgit@firesoul
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/xdp.h