Skip to content

Conversation

@tohojo
Copy link
Member

@tohojo tohojo commented Dec 2, 2025

This PR imports the code from the xdpsock utility in the bpf_examples
repository and incorporates the functionality into xdp-bench (drop and l2fwd)
and xdp-trafficgen (tx).

The xdpsock code is transformed into library functions that can be called from
both the xdp-bench and xdp-trafficgen binaries, and the options are converted
into the xdp-tools parameter framework.

tohojo added 8 commits January 6, 2026 17:10
The xsk_create_umem_rings() function reuses the map variable for the two
mappings which means that the unmap in the error path doesn't get the
right pointer. Fix this by using two different variables for the two
mappings.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Some invocations of usage() didn't use the program name buffer that
includes the command name, leading to confusing output.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Error out if the configured options contain duplicate short options, to
aid with commands that take a lot of options.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Add a .hex value in the options definition that enables parsing integers
as hexadecimal if set.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Add an 'xsk' command to xdp-bench which will be used to run the
AF_XDP-based benchmarks from the xdpsock utility.

This commit only adds the command and option parsing, in preparation for
porting over the xdpsock code.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Update if_xdp.h to a newer version that includes the definitions for
fragments in AF_XDP.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
@tohojo tohojo marked this pull request as ready for review January 6, 2026 16:11
tohojo added 5 commits January 6, 2026 17:23
This includes the xdpsock code from the bpf_examples repository into
lib/util. The code is included as-is, with only a couple of small
changes to make the code compile (fixing "mixed-sign compare" compiler
warnings). The following commits will refactor the code into a library
to be re-used by xdp-bench and xdp-trafficgen.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Instead of typedefs, use __u8/__u16/__u32/__u64 directly everywhere.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
The options should be part of the library so they can be re-used.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Instead of relying on global variables to keep state while running
xdpsock, move all state variables into a context object, and remove the
global variables for the options in favour of an embedded options struct.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Restructure the setup code of xdpsock to get rid of the main() function
and instead introduce a new xsk_ctx__create() function that creates the
previously introduced context object and sets everything up.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
tohojo added 10 commits January 6, 2026 17:23
Wire up the xdpsock library code to implement the xsk-drop and xsk-tx
commands in xdp-bench.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Swap the threads so that packet processing is started in a background
thread and stats output is in the foreground. This makes it possible to
incorporate signal processing as part of the stats output loop, adopting
the signalfd/timerfd approach used by xdp_sample.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Make the stats output more condensed (by default) and better aligned
with the output of xdp_sample used elsewhere.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Use the immediate exit logic from xdp_sample in xdpsock as
well (exporting the function that checks the envvar), so we can use it
in tests.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
The main thread will handle signals and set ctx->benchmark_done if one
is received. Make sure to check this in every loop iteration; otherwise,
when using poll mode, the poller thread won't react to the exit signal
because of the 'continue' inside the poll logic.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Using xdp.frags as the section name instructs libbpf to set the frags
bit when loading the program. There is logic in libxdp to turn this flag
off if the kernel does not support it, but libbpf saves the section
flags in the sec_def cookie which overrides the user-specified flags.

To make the automatic disabling of frags work, remove the .frags suffix
from the xdpsock definition and set the flag using the libxdp API
instead.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Will be used to skip busy poll test if not supported.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Exercise the different options with immediate exit in both xsk-drop and
xsk-tk modes.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Add a test that exercises the different XSK options for xdp-trafficgen.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
@tohojo tohojo merged commit aa6028c into main Jan 6, 2026
73 checks passed
@tohojo tohojo deleted the xdb-bench-xsk branch January 6, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants