diff mbox series

[net-next] xdp: Adjust xdp_frame layout to avoid using bitfields

Message ID 166393728005.2213882.4162674859542409548.stgit@firesoul (mailing list archive)
State Accepted
Commit b860a1b964be7917ed3dcaa674ec0a2ba0a62aa0
Delegated to: Netdev Maintainers
Headers show
Series [net-next] xdp: Adjust xdp_frame layout to avoid using bitfields | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4377 this patch: 4377
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 1057 this patch: 1057
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4566 this patch: 4566
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jesper Dangaard Brouer Sept. 23, 2022, 12:48 p.m. UTC
Practical experience (and advice from Alexei) tell us that bitfields in
structs lead to un-optimized assemply code. I've verified this change
does lead to better x86_64 assemply, 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>
---
 include/net/xdp.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Sept. 27, 2022, 12:20 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 23 Sep 2022 14:48:00 +0200 you wrote:
> Practical experience (and advice from Alexei) tell us that bitfields in
> structs lead to un-optimized assemply code. I've verified this change
> does lead to better x86_64 assemply, 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.
> 
> [...]

Here is the summary with links:
  - [net-next] xdp: Adjust xdp_frame layout to avoid using bitfields
    https://git.kernel.org/netdev/net-next/c/b860a1b964be

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 04c852c7a77f..55dbc68bfffc 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -164,13 +164,13 @@  struct xdp_frame {
 	void *data;
 	u16 len;
 	u16 headroom;
-	u32 metasize:8;
-	u32 frame_sz:24;
+	u32 metasize; /* uses lower 8-bits */
 	/* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time,
 	 * while mem info is valid on remote CPU.
 	 */
 	struct xdp_mem_info mem;
 	struct net_device *dev_rx; /* used by cpumap */
+	u32 frame_sz;
 	u32 flags; /* supported values defined in xdp_buff_flags */
 };