-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathxdp_socket.c
More file actions
73 lines (59 loc) · 1.48 KB
/
xdp_socket.c
File metadata and controls
73 lines (59 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <bpf/bpf.h>
#include <stdbool.h>
#include <linux/bpf.h>
#include <pthread.h>
#include <bpf/libbpf.h>
#include <sys/resource.h>
#include <linux/if_link.h>
#include <xdp/libxdp.h>
#include "logging.h"
#include "xdp-bench.h"
#include "xdp_sample.h"
const struct xsk_opts defaults_xsk = {
.attach_mode = XDP_MODE_NATIVE,
.interval = 2,
.retries = 3,
.frame_size = 4096,
.batch_size = 64,
.tx_pkt_size = 64,
.sched_policy = XSK_SCHED_OTHER,
.clock = XSK_CLOCK_MONOTONIC,
};
static int do_xsk(const struct xsk_opts *opt,
enum xsk_benchmark_type bench)
{
struct xsk_ctx *ctx;
pthread_t pt;
int ret;
ret = xsk_validate_opts(opt);
if (ret)
return ret;
ctx = xsk_ctx__create(opt, bench);
ret = libxdp_get_error(ctx);
if (ret)
return ret;
pr_info("%s packets on %s (ifindex %d; queue %d; driver %s) using AF_XDP sockets\n",
bench == XSK_BENCH_RXDROP ? "Dropping" : "Hairpinning",
opt->iface.ifname, opt->iface.ifindex, opt->queue_idx, get_driver_name(opt->iface.ifindex));
ret = xsk_start_bench(ctx, &pt);
if (ret)
goto out;
ret = xsk_stats_poller(ctx);
pthread_join(pt, NULL);
out:
xsk_ctx__destroy(ctx);
return ret;
}
int do_xsk_drop(const void *cfg, __unused const char *pin_root_path)
{
const struct xsk_opts *opt = cfg;
return do_xsk(opt, XSK_BENCH_RXDROP);
}
int do_xsk_tx(const void *cfg, __unused const char *pin_root_path)
{
const struct xsk_opts *opt = cfg;
return do_xsk(opt, XSK_BENCH_L2FWD);
}