diff options
author | Daniel T. Lee <danieltimlee@gmail.com> | 2020-10-11 03:17:34 +0900 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-10-11 12:14:36 -0700 |
commit | 321f6324500eb2ec75b6fcff7dcd66d64ba18529 (patch) | |
tree | 97287b42afa877971bfa2c065438a47c9b369170 /samples/bpf/xdp_sample_pkts_kern.c | |
parent | 151936bf51afcdd6db52b3b73e339d021064b0ea (diff) | |
download | linux-321f6324500eb2ec75b6fcff7dcd66d64ba18529.tar.bz2 |
samples: bpf: Refactor XDP kern program maps with BTF-defined map
Most of the samples were converted to use the new BTF-defined MAP as
they moved to libbpf, but some of the samples were missing.
Instead of using the previous BPF MAP definition, this commit refactors
xdp_monitor and xdp_sample_pkts_kern MAP definition with the new
BTF-defined MAP format.
Also, this commit removes the max_entries attribute at PERF_EVENT_ARRAY
map type. The libbpf's bpf_object__create_map() will automatically
set max_entries to the maximum configured number of CPUs on the host.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201010181734.1109-4-danieltimlee@gmail.com
Diffstat (limited to 'samples/bpf/xdp_sample_pkts_kern.c')
-rw-r--r-- | samples/bpf/xdp_sample_pkts_kern.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/samples/bpf/xdp_sample_pkts_kern.c b/samples/bpf/xdp_sample_pkts_kern.c index 33377289e2a8..9cf76b340dd7 100644 --- a/samples/bpf/xdp_sample_pkts_kern.c +++ b/samples/bpf/xdp_sample_pkts_kern.c @@ -5,14 +5,12 @@ #include <bpf/bpf_helpers.h> #define SAMPLE_SIZE 64ul -#define MAX_CPUS 128 - -struct bpf_map_def SEC("maps") my_map = { - .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .key_size = sizeof(int), - .value_size = sizeof(u32), - .max_entries = MAX_CPUS, -}; + +struct { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(u32)); +} my_map SEC(".maps"); SEC("xdp_sample") int xdp_sample_prog(struct xdp_md *ctx) |