Skip to content

Commit

Permalink
xdp-bench: Change the -l option to be a mode setting option
Browse files Browse the repository at this point in the history
In anticipation of adding more modes in the future, change the -l option to
be a mode option setting instead of a boolean switch. Also add
documentation for the option.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
  • Loading branch information
tohojo committed Jun 8, 2023
1 parent 968ce1f commit 310f645
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 7 deletions.
45 changes: 45 additions & 0 deletions xdp-bench/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ flushing it back out if writing).

The default for this option is =no-touch=.

** -l, --load-mode <MODE>
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with =-p parse-ip=). The following modes are
available:

#+begin_src sh
dpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
#+end_src

This can be used to benchmark the various packet access modes supported by the
kernel.

The default for this option is =dpa=.

** -r, --rxq-stats
If set, the XDP program will also gather statistics on which receive queue index
each packet was received on. This is displayed in the extended output mode along
Expand Down Expand Up @@ -138,6 +153,21 @@ following actions are available:

The default for this option is =no-touch=.

** -l, --load-mode <MODE>
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with =-p parse-ip=). The following modes are
available:

#+begin_src sh
dpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
#+end_src

This can be used to benchmark the various packet access modes supported by the
kernel.

The default for this option is =dpa=.

** -r, --rxq-stats
If set, the XDP program will also gather statistics on which receive queue index
each packet was received on. This is displayed in the extended output mode along
Expand Down Expand Up @@ -203,6 +233,21 @@ allows this function to be turned off.

The default for this option is =swap-macs=.

** -l, --load-mode <MODE>
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with =-p parse-ip=). The following modes are
available:

#+begin_src sh
dpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
#+end_src

This can be used to benchmark the various packet access modes supported by the
kernel.

The default for this option is =dpa=.

** -r, --rxq-stats
If set, the XDP program will also gather statistics on which receive queue index
each packet was received on. This is displayed in the extended output mode along
Expand Down
2 changes: 1 addition & 1 deletion xdp-bench/tests/test-xdp-bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_xdp_load_bytes()
export XDP_SAMPLE_IMMEDIATE_EXIT=1

for action in drop pass tx; do
check_run $XDP_BENCH $action $NS -p parse-ip -l -vv
check_run $XDP_BENCH $action $NS -p parse-ip -l load-bytes -vv
done
}

Expand Down
65 changes: 64 additions & 1 deletion xdp-bench/xdp-bench.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "xdp-bench" "8" "JUNE 1, 2023" "V1.3.1" "A simple XDP benchmarking tool"
.TH "xdp-bench" "8" "JUNE 2, 2023" "V1.3.1" "A simple XDP benchmarking tool"

.SH "NAME"
XDP-bench \- a simple XDP benchmarking tool
Expand Down Expand Up @@ -90,6 +90,27 @@ flushing it back out if writing).
.PP
The default for this option is \fIno\-touch\fP.

.SS "-l, --load-mode <MODE>"
.PP
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with \fI\-p parse\-ip\fP). The following modes are
available:

.RS
.nf
\fCdpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
\fP
.fi
.RE

.PP
This can be used to benchmark the various packet access modes supported by the
kernel.

.PP
The default for this option is \fIdpa\fP.

.SS "-r, --rxq-stats"
.PP
If set, the XDP program will also gather statistics on which receive queue index
Expand Down Expand Up @@ -168,6 +189,27 @@ swap-macs - Swap the source and destination MAC addresses before passing
.PP
The default for this option is \fIno\-touch\fP.

.SS "-l, --load-mode <MODE>"
.PP
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with \fI\-p parse\-ip\fP). The following modes are
available:

.RS
.nf
\fCdpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
\fP
.fi
.RE

.PP
This can be used to benchmark the various packet access modes supported by the
kernel.

.PP
The default for this option is \fIdpa\fP.

.SS "-r, --rxq-stats"
.PP
If set, the XDP program will also gather statistics on which receive queue index
Expand Down Expand Up @@ -251,6 +293,27 @@ allows this function to be turned off.
.PP
The default for this option is \fIswap\-macs\fP.

.SS "-l, --load-mode <MODE>"
.PP
Specify which mechanism xdp-bench should use to load the packet data when
parsing the IP header (used with \fI\-p parse\-ip\fP). The following modes are
available:

.RS
.nf
\fCdpa - Use traditional Direct Packet Access from the XDP program
load-bytes - Use the xdp_load_bytes() helper function to load the data
\fP
.fi
.RE

.PP
This can be used to benchmark the various packet access modes supported by the
kernel.

.PP
The default for this option is \fIdpa\fP.

.SS "-r, --rxq-stats"
.PP
If set, the XDP program will also gather statistics on which receive queue index
Expand Down
14 changes: 11 additions & 3 deletions xdp-bench/xdp-bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ struct enum_val basic_program_modes[] = {
{NULL, 0}
};

struct enum_val basic_load_modes[] = {
{"dpa", BASIC_LOAD_DPA},
{"load-bytes", BASIC_LOAD_BYTES},
{NULL, 0}
};

struct enum_val cpumap_remote_actions[] = {
{"disabled", ACTION_DISABLED},
{"drop", ACTION_DROP},
Expand Down Expand Up @@ -70,12 +76,14 @@ struct prog_option basic_options[] = {
DEFINE_OPTION("program-mode", OPT_ENUM, struct basic_opts, program_mode,
.typearg = basic_program_modes,
.hidden = true),
DEFINE_OPTION("load-mode", OPT_ENUM, struct basic_opts, load_mode,
.short_opt = 'l',
.metavar = "<mode>",
.typearg = basic_load_modes,
.help = "How to load data when parsing IP header (with -p parse-ip; default dpa)"),
DEFINE_OPTION("rxq-stats", OPT_BOOL, struct basic_opts, rxq_stats,
.short_opt = 'r',
.help = "Collect per-RXQ drop statistics"),
DEFINE_OPTION("load-bytes", OPT_BOOL, struct basic_opts, load_bytes,
.short_opt = 'l',
.help = "Use xdp_load_bytes() helper when parsing IP header"),
DEFINE_OPTION("interval", OPT_U32, struct basic_opts, interval,
.short_opt = 'i',
.metavar = "<seconds>",
Expand Down
7 changes: 6 additions & 1 deletion xdp-bench/xdp-bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ enum basic_program_mode {
BASIC_SWAP_MACS,
};

enum basic_load_mode {
BASIC_LOAD_DPA,
BASIC_LOAD_BYTES,
};

struct basic_opts {
bool extended;
bool rxq_stats;
bool load_bytes;
__u32 interval;
enum xdp_attach_mode mode;
enum basic_program_mode program_mode;
enum basic_load_mode load_mode;
struct iface iface_in;
};

Expand Down
2 changes: 1 addition & 1 deletion xdp-bench/xdp_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static int do_basic(const struct basic_opts *opt, enum xdp_action action)
opts.prog_name = "xdp_read_data_prog";
break;
case BASIC_PARSE_IPHDR:
opts.prog_name = opt->load_bytes ? "xdp_parse_load_bytes_prog" : "xdp_parse_prog";
opts.prog_name = (opt->load_mode == BASIC_LOAD_BYTES) ? "xdp_parse_load_bytes_prog" : "xdp_parse_prog";
break;
case BASIC_SWAP_MACS:
opts.prog_name = "xdp_swap_macs_prog";
Expand Down

0 comments on commit 310f645

Please sign in to comment.