Skip to content

Commit

Permalink
xdp-bench: Add option to use xdp_load_bytes() helper when parsing IP
Browse files Browse the repository at this point in the history
This adds an option to xdp-bench to use the xdp_load_bytes() helper when
parsing the IP header (for the basic options). This can be used to
benchmark the overhead of xdp_load_bytes() relative to DPA.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo committed Jun 8, 2023
1 parent b43595e commit fcb9822
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 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 @@ -10,6 +10,7 @@ test_basic()
check_run $XDP_BENCH $action $NS -vv
check_run $XDP_BENCH $action $NS -p read-data -vv
check_run $XDP_BENCH $action $NS -p parse-ip -vv
check_run $XDP_BENCH $action $NS -p parse-ip -l -vv
check_run $XDP_BENCH $action $NS -p swap-macs -vv
check_run $XDP_BENCH $action $NS -m skb -vv
check_run $XDP_BENCH $action $NS -e -vv
Expand Down
3 changes: 3 additions & 0 deletions xdp-bench/xdp-bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ struct prog_option basic_options[] = {
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
1 change: 1 addition & 0 deletions xdp-bench/xdp-bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int do_redirect_devmap_multi(const void *cfg, const char *pin_root_path);
struct basic_opts {
bool extended;
bool rxq_stats;
bool load_bytes;
__u32 interval;
enum xdp_attach_mode mode;
enum basic_program_mode program_mode;
Expand Down
49 changes: 47 additions & 2 deletions xdp-bench/xdp_basic.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,50 @@

#include "xdp_basic.shared.h"

#ifndef HAVE_LIBBPF_BPF_PROGRAM__TYPE
static long (*bpf_xdp_load_bytes)(struct xdp_md *xdp_md, __u32 offset, void *buf, __u32 len) = (void *) 189;
#endif

const volatile enum basic_program_mode prog_mode = BASIC_NO_TOUCH;
const volatile bool rxq_stats = 0;
const volatile bool xdp_load_bytes = 0;
const volatile enum xdp_action action = XDP_DROP;

static int parse_ip_header_load(struct xdp_md *ctx)
{
int eth_type, ip_type, err, offset = 0;
struct ipv6hdr ipv6hdr;
struct iphdr iphdr;
struct ethhdr eth;

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

eth_type = eth.h_proto;
offset = sizeof(eth);

if (eth_type == bpf_htons(ETH_P_IP)) {
err = bpf_xdp_load_bytes(ctx, offset, &iphdr, sizeof(iphdr));
if (err)
return err;

ip_type = iphdr.protocol;
if (ip_type < 0)
return ip_type;
} else if (eth_type == bpf_htons(ETH_P_IPV6)) {
err = bpf_xdp_load_bytes(ctx, offset, &ipv6hdr, sizeof(ipv6hdr));
if (err)
return err;

ip_type = ipv6hdr.nexthdr;
if (ip_type < 0)
return ip_type;
}

return 0;
}

static int parse_ip_header(struct xdp_md *ctx)
{
void *data_end = (void *)(long)ctx->data_end;
Expand Down Expand Up @@ -82,8 +122,13 @@ int xdp_basic_prog(struct xdp_md *ctx)
return XDP_ABORTED;
break;
case BASIC_PARSE_IPHDR:
if (parse_ip_header(ctx))
return XDP_ABORTED;
if (xdp_load_bytes) {
if (parse_ip_header_load(ctx))
return XDP_ABORTED;
} else {
if (parse_ip_header(ctx))
return XDP_ABORTED;
}
break;
case BASIC_SWAP_MACS:
swap_src_dst_mac(data);
Expand Down
1 change: 1 addition & 0 deletions xdp-bench/xdp_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static int do_basic(const struct basic_opts *opt, enum xdp_action action)
mask |= SAMPLE_DROP_OK;

skel->rodata->prog_mode = opt->program_mode;
skel->rodata->xdp_load_bytes = opt->load_bytes;
if (opt->rxq_stats) {
skel->rodata->rxq_stats = true;
mask |= SAMPLE_RXQ_STATS;
Expand Down

0 comments on commit fcb9822

Please sign in to comment.