Skip to content

Commit

Permalink
xdp-bench: Introduce xdp_read_data_load_bytes_prog
Browse files Browse the repository at this point in the history
This commit introduces xdp_read_data_load_bytes_prog to xdp-bench.
This program uses the bpf_xdp_load_bytes helper for packet data access.
In contrast, xdp_read_data_prog uses direct packet access.

This addition aligns with the existing behavior of -p parse-ip:
- 'xdp-bench -p read-data' loads xdp_read_data_prog.
- 'xdp-bench -p read-data -l load-bytes' loads xdp_read_data_load_bytes_prog.

Signed-off-by: Nimrod Oren <noren@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
  • Loading branch information
nimrod-oren committed Mar 25, 2024
1 parent 6f9ae82 commit 87915eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions xdp-bench/tests/test-xdp-bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test_xdp_load_bytes()

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

Expand Down
20 changes: 20 additions & 0 deletions xdp-bench/xdp_basic.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ int xdp_read_data_prog(struct xdp_md *ctx)
return ret;
}

SEC("xdp")
int xdp_read_data_load_bytes_prog(struct xdp_md *ctx)
{
int err, offset = 0;
struct ethhdr eth;
int ret = action;

err = bpf_xdp_load_bytes(ctx, offset, &eth, sizeof(eth));
if (err)
return err;

if (bpf_ntohs(eth.h_proto) < ETH_P_802_3_MIN)
ret = XDP_ABORTED;

if (record_stats(ctx->rx_queue_index, ret==action))
return XDP_ABORTED;

return ret;
}

SEC("xdp")
int xdp_swap_macs_prog(struct xdp_md *ctx)
{
Expand Down
6 changes: 3 additions & 3 deletions xdp-bench/xdp_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ static int do_basic(const struct basic_opts *opt, enum xdp_action action)
mask |= SAMPLE_RXQ_STATS;
}

if (opt->load_mode == BASIC_LOAD_BYTES && opt->program_mode != BASIC_PARSE_IPHDR) {
pr_warn("Setting '-l load-bytes' only works with '-p parse-ip'\n");
if (opt->load_mode == BASIC_LOAD_BYTES && opt->program_mode == BASIC_SWAP_MACS) {
pr_warn("Setting '-l load-bytes' doesn't work with '-p swap-macs'\n");
ret = EXIT_FAIL_BPF;
goto end_destroy;
}
Expand All @@ -88,7 +88,7 @@ static int do_basic(const struct basic_opts *opt, enum xdp_action action)
opts.prog_name = "xdp_basic_prog";
break;
case BASIC_READ_DATA:
opts.prog_name = "xdp_read_data_prog";
opts.prog_name = (opt->load_mode == BASIC_LOAD_BYTES) ? "xdp_read_data_load_bytes_prog" : "xdp_read_data_prog";
break;
case BASIC_PARSE_IPHDR:
opts.prog_name = (opt->load_mode == BASIC_LOAD_BYTES) ? "xdp_parse_load_bytes_prog" : "xdp_parse_prog";
Expand Down

0 comments on commit 87915eb

Please sign in to comment.