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.
Showing the changes to samples (3 of 3 files). Show all
Unified · Split
| @@ -6,21 +6,21 @@ · 5 unmodified lines | |||
| 6 | #include <uapi/linux/bpf.h> | 6 | #include <uapi/linux/bpf.h> |
| 7 | #include <bpf/bpf_helpers.h> | 7 | #include <bpf/bpf_helpers.h> |
| 8 | 8 | ||
| 9 | struct bpf_map_def SEC("maps") redirect_err_cnt = { | 9 | struct { |
| 10 | .type = BPF_MAP_TYPE_PERCPU_ARRAY, | 10 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
| 11 | .key_size = sizeof(u32), | 11 | __type(key, u32); |
| 12 | .value_size = sizeof(u64), | 12 | __type(value, u64); |
| 13 | .max_entries = 2, | 13 | __uint(max_entries, 2); |
| 14 | /* TODO: have entries for all possible errno's */ | 14 | /* TODO: have entries for all possible errno's */ |
| 15 | }; | 15 | } redirect_err_cnt SEC(".maps"); |
| 16 | 16 | ||
| 17 | #define XDP_UNKNOWN XDP_REDIRECT + 1 | 17 | #define XDP_UNKNOWN XDP_REDIRECT + 1 |
| 18 | struct bpf_map_def SEC("maps") exception_cnt = { | 18 | struct { |
| 19 | .type = BPF_MAP_TYPE_PERCPU_ARRAY, | 19 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
| 20 | .key_size = sizeof(u32), | 20 | __type(key, u32); |
| 21 | .value_size = sizeof(u64), | 21 | __type(value, u64); |
| 22 | .max_entries = XDP_UNKNOWN + 1, | 22 | __uint(max_entries, XDP_UNKNOWN + 1); |
| 23 | }; | 23 | } exception_cnt SEC(".maps"); |
| 24 | 24 | ||
| 25 | /* Tracepoint format: /sys/kernel/debug/tracing/events/xdp/xdp_redirect/format | 25 | /* Tracepoint format: /sys/kernel/debug/tracing/events/xdp/xdp_redirect/format |
| 26 | * Code in: kernel/include/trace/events/xdp.h | 26 | * Code in: kernel/include/trace/events/xdp.h |
| @@ -129,19 +129,19 @@ struct datarec { · 102 unmodified lines | |||
| 129 | }; | 129 | }; |
| 130 | #define MAX_CPUS 64 | 130 | #define MAX_CPUS 64 |
| 131 | 131 | ||
| 132 | struct bpf_map_def SEC("maps") cpumap_enqueue_cnt = { | 132 | struct { |
| 133 | .type = BPF_MAP_TYPE_PERCPU_ARRAY, | 133 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
| 134 | .key_size = sizeof(u32), | 134 | __type(key, u32); |
| 135 | .value_size = sizeof(struct datarec), | 135 | __type(value, struct datarec); |
| 136 | .max_entries = MAX_CPUS, | 136 | __uint(max_entries, MAX_CPUS); |
| 137 | }; | 137 | } cpumap_enqueue_cnt SEC(".maps"); |
| 138 | 138 | ||
| 139 | struct bpf_map_def SEC("maps") cpumap_kthread_cnt = { | 139 | struct { |
| 140 | .type = BPF_MAP_TYPE_PERCPU_ARRAY, | 140 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
| 141 | .key_size = sizeof(u32), | 141 | __type(key, u32); |
| 142 | .value_size = sizeof(struct datarec), | 142 | __type(value, struct datarec); |
| 143 | .max_entries = 1, | 143 | __uint(max_entries, 1); |
| 144 | }; | 144 | } cpumap_kthread_cnt SEC(".maps"); |
| 145 | 145 | ||
| 146 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_enqueue/format | 146 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_enqueue/format |
| 147 | * Code in: kernel/include/trace/events/xdp.h | 147 | * Code in: kernel/include/trace/events/xdp.h |
| @@ -210,12 +210,12 @@ int trace_xdp_cpumap_kthread(struct cpumap_kthread_ctx *ctx) · 62 unmodified lines | |||
| 210 | return 0; | 210 | return 0; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | struct bpf_map_def SEC("maps") devmap_xmit_cnt = { | 213 | struct { |
| 214 | .type = BPF_MAP_TYPE_PERCPU_ARRAY, | 214 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
| 215 | .key_size = sizeof(u32), | 215 | __type(key, u32); |
| 216 | .value_size = sizeof(struct datarec), | 216 | __type(value, struct datarec); |
| 217 | .max_entries = 1, | 217 | __uint(max_entries, 1); |
| 218 | }; | 218 | } devmap_xmit_cnt SEC(".maps"); |
| 219 | 219 | ||
| 220 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_devmap_xmit/format | 220 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_devmap_xmit/format |
| 221 | * Code in: kernel/include/trace/events/xdp.h | 221 | * Code in: kernel/include/trace/events/xdp.h |
| @@ -5,14 +5,12 @@ · 4 unmodified lines | |||
| 5 | #include <bpf/bpf_helpers.h> | 5 | #include <bpf/bpf_helpers.h> |
| 6 | 6 | ||
| 7 | #define SAMPLE_SIZE 64ul | 7 | #define SAMPLE_SIZE 64ul |
| 8 | #define MAX_CPUS 128 | 8 | |
| 9 | 9 | struct { | |
| 10 | struct bpf_map_def SEC("maps") my_map = { | 10 | __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); |
| 11 | .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, | 11 | __uint(key_size, sizeof(int)); |
| 12 | .key_size = sizeof(int), | 12 | __uint(value_size, sizeof(u32)); |
| 13 | .value_size = sizeof(u32), | 13 | } my_map SEC(".maps"); |
| 14 | .max_entries = MAX_CPUS, | ||
| 15 | }; | ||
| 16 | 14 | ||
| 17 | SEC("xdp_sample") | 15 | SEC("xdp_sample") |
| 18 | int xdp_sample_prog(struct xdp_md *ctx) | 16 | int xdp_sample_prog(struct xdp_md *ctx) |
| @@ -18,7 +18,6 @@ · 17 unmodified lines | |||
| 18 | 18 | ||
| 19 | #include "perf-sys.h" | 19 | #include "perf-sys.h" |
| 20 | 20 | ||
| 21 | #define MAX_CPUS 128 | ||
| 22 | static int if_idx; | 21 | static int if_idx; |
| 23 | static char *if_name; | 22 | static char *if_name; |
| 24 | static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; | 23 | static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; |