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

perf bpf: Convert legacy map definition to BTF-defined

The libbpf is switching off support for legacy map definitions [1],
which will break the perf llvm tests.

Moving the base source map definition to BTF-defined, so we need
to use -g compile option for to add debug/BTF info.

[1] https://lore.kernel.org/bpf/20220627211527.2245459-1-andrii@kernel.org/

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20220704152721.352046-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
8b1e1a03 6d518ac7

+24 -13
+23 -12
tools/perf/tests/bpf-script-example.c
··· 17 17 static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) = 18 18 (void *) BPF_FUNC_map_update_elem; 19 19 20 - struct bpf_map_def { 21 - unsigned int type; 22 - unsigned int key_size; 23 - unsigned int value_size; 24 - unsigned int max_entries; 25 - }; 20 + /* 21 + * Following macros are taken from tools/lib/bpf/bpf_helpers.h, 22 + * and are used to create BTF defined maps. It is easier to take 23 + * 2 simple macros, than being able to include above header in 24 + * runtime. 25 + * 26 + * __uint - defines integer attribute of BTF map definition, 27 + * Such attributes are represented using a pointer to an array, 28 + * in which dimensionality of array encodes specified integer 29 + * value. 30 + * 31 + * __type - defines pointer variable with typeof(val) type for 32 + * attributes like key or value, which will be defined by the 33 + * size of the type. 34 + */ 35 + #define __uint(name, val) int (*name)[val] 36 + #define __type(name, val) typeof(val) *name 26 37 27 38 #define SEC(NAME) __attribute__((section(NAME), used)) 28 - struct bpf_map_def SEC("maps") flip_table = { 29 - .type = BPF_MAP_TYPE_ARRAY, 30 - .key_size = sizeof(int), 31 - .value_size = sizeof(int), 32 - .max_entries = 1, 33 - }; 39 + struct { 40 + __uint(type, BPF_MAP_TYPE_ARRAY); 41 + __uint(max_entries, 1); 42 + __type(key, int); 43 + __type(value, int); 44 + } flip_table SEC(".maps"); 34 45 35 46 SEC("func=do_epoll_wait") 36 47 int bpf_func__SyS_epoll_pwait(void *ctx)
+1 -1
tools/perf/util/llvm-utils.c
··· 25 25 "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \ 26 26 "-Wno-unused-value -Wno-pointer-sign " \ 27 27 "-working-directory $WORKING_DIR " \ 28 - "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE" 28 + "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -g -O2 -o - $LLVM_OPTIONS_PIPE" 29 29 30 30 struct llvm_param llvm_param = { 31 31 .clang_path = "clang",