Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpftool: Update btf_dump__new() and perf_buffer__new_raw() calls

Use v1.0-compatible variants of btf_dump and perf_buffer "constructors".
This is also a demonstration of reusing struct perf_buffer_raw_opts as
OPTS-style option struct for new perf_buffer__new_raw() API.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211111053624.190580-10-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
164b04f2 eda8bfa5

+5 -8
+1 -1
tools/bpf/bpftool/btf.c
··· 418 418 struct btf_dump *d; 419 419 int err = 0, i; 420 420 421 - d = btf_dump__new(btf, NULL, NULL, btf_dump_printf); 421 + d = btf_dump__new(btf, btf_dump_printf, NULL, NULL); 422 422 if (IS_ERR(d)) 423 423 return PTR_ERR(d); 424 424
+1 -1
tools/bpf/bpftool/gen.c
··· 218 218 char sec_ident[256], map_ident[256]; 219 219 int i, err = 0; 220 220 221 - d = btf_dump__new(btf, NULL, NULL, codegen_btf_dump_printf); 221 + d = btf_dump__new(btf, codegen_btf_dump_printf, NULL, NULL); 222 222 if (IS_ERR(d)) 223 223 return PTR_ERR(d); 224 224
+3 -6
tools/bpf/bpftool/map_perf_ring.c
··· 124 124 .wakeup_events = 1, 125 125 }; 126 126 struct bpf_map_info map_info = {}; 127 - struct perf_buffer_raw_opts opts = {}; 127 + LIBBPF_OPTS(perf_buffer_raw_opts, opts); 128 128 struct event_pipe_ctx ctx = { 129 129 .all_cpus = true, 130 130 .cpu = -1, ··· 190 190 ctx.idx = 0; 191 191 } 192 192 193 - opts.attr = &perf_attr; 194 - opts.event_cb = print_bpf_output; 195 - opts.ctx = &ctx; 196 193 opts.cpu_cnt = ctx.all_cpus ? 0 : 1; 197 194 opts.cpus = &ctx.cpu; 198 195 opts.map_keys = &ctx.idx; 199 - 200 - pb = perf_buffer__new_raw(map_fd, MMAP_PAGE_CNT, &opts); 196 + pb = perf_buffer__new_raw(map_fd, MMAP_PAGE_CNT, &perf_attr, 197 + print_bpf_output, &ctx, &opts); 201 198 err = libbpf_get_error(pb); 202 199 if (err) { 203 200 p_err("failed to create perf buffer: %s (%d)",