Skip to contentSkip to conversation

perf tools: Convert legacy map definition to BTF-defined

PATCH Superseded Jiri Olsa 3 participants 3 messages Jun 29, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 perf tools: 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/[email protected]/

---
 tools/perf/tests/bpf-script-example.c | 15 +++++++++------
 tools/perf/util/llvm-utils.c          |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)
tools/perf/tests/bpf-script-example.c +9 -6
index ab4b98b3165d..065a4ac5d8e5 100644
@@ -24,13 +24,16 @@ struct bpf_map_def {
 	unsigned int max_entries;
 };
 
+#define __uint(name, val) int (*name)[val]
+#define __type(name, val) typeof(val) *name
+
 #define SEC(NAME) __attribute__((section(NAME), used))
-struct bpf_map_def SEC("maps") flip_table = {
-	.type = BPF_MAP_TYPE_ARRAY,
-	.key_size = sizeof(int),
-	.value_size = sizeof(int),
-	.max_entries = 1,
-};
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, int);
+	__type(value, int);
+} flip_table SEC(".maps");
 
 SEC("func=do_epoll_wait")
 int bpf_func__SyS_epoll_pwait(void *ctx)
tools/perf/util/llvm-utils.c +1 -1
index 96c8ef60f4f8..2dc797007419 100644
@@ -25,7 +25,7 @@
 		"$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
 		"-Wno-unused-value -Wno-pointer-sign "		\
 		"-working-directory $WORKING_DIR "		\
-		"-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
+		"-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -g -O2 -o - $LLVM_OPTIONS_PIPE"
 
 struct llvm_param llvm_param = {
 	.clang_path = "clang",
Signature · 1 line
2.35.3
reviewer
#1 lore raw
Quoted 19 lines · Jiri Olsa

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/[email protected]/

---
 tools/perf/tests/bpf-script-example.c | 15 +++++++++------
 tools/perf/util/llvm-utils.c          |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)
tools/perf/tests/bpf-script-example.c +0 -0
index ab4b98b3165d..065a4ac5d8e5 100644

tools/perf/tests/bpf-script-example.c struct bpf_map_def { · line 28

Quoted 5 lines
tools/perf/tests/bpf-script-example.c +2 -0
@@ -24,13 +24,16 @@ struct bpf_map_def {
        unsigned int max_entries;
 };
 
+#define __uint(name, val) int (*name)[val]
+#define __type(name, val) typeof(val) *name

This is probably worth a comment, reading it hurts :-) I expect that libbpf provides a definition that the rest of the world uses.

Fwiw, the pre bpf counters BPF in perf needs a good overhaul. Arnaldo mentioned switching perf trace's BPF to use BPF skeletons in another post. The tests we have on event filters are flaky. One fewer bpf.h in the world seems like a service to humanity (I'm looking at you tools/perf/include/bpf/bpf.h).

Thanks,
Ian

Quoted 33 lines
tools/perf/tests/bpf-script-example.c +7 -6
+
 #define SEC(NAME) __attribute__((section(NAME), used))
-struct bpf_map_def SEC("maps") flip_table = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(int),
-       .value_size = sizeof(int),
-       .max_entries = 1,
-};
+struct {
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, int);
+       __type(value, int);
+} flip_table SEC(".maps");
 
 SEC("func=do_epoll_wait")
 int bpf_func__SyS_epoll_pwait(void *ctx)
tools/perf/util/llvm-utils.c +1 -2
index 96c8ef60f4f8..2dc797007419 100644
@@ -25,7 +25,7 @@
                "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
                "-Wno-unused-value -Wno-pointer-sign "          \
                "-working-directory $WORKING_DIR "              \
-               "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
+               "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -g -O2 -o - $LLVM_OPTIONS_PIPE"
 
 struct llvm_param llvm_param = {
        .clang_path = "clang",
--

2.35.3

#2 lore raw

Em Wed, Jun 29, 2022 at 09:43:17AM -0700, Ian Rogers escreveu:

Quoted 28 lines · Jiri Olsa
Quoted 18 lines

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/[email protected]/

---
 tools/perf/tests/bpf-script-example.c | 15 +++++++++------
 tools/perf/util/llvm-utils.c          |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)
tools/perf/tests/bpf-script-example.c +0 -0
index ab4b98b3165d..065a4ac5d8e5 100644

tools/perf/tests/bpf-script-example.c struct bpf_map_def { · line 28

Quoted 5 lines
tools/perf/tests/bpf-script-example.c +2 -0
@@ -24,13 +24,16 @@ struct bpf_map_def {
        unsigned int max_entries;
 };
 
+#define __uint(name, val) int (*name)[val]
+#define __type(name, val) typeof(val) *name

This is probably worth a comment, reading it hurts :-) I expect that libbpf provides a definition that the rest of the world uses.

Quoted 5 lines

Fwiw, the pre bpf counters BPF in perf needs a good overhaul. Arnaldo mentioned switching perf trace's BPF to use BPF skeletons in another post. The tests we have on event filters are flaky. One fewer bpf.h in the world seems like a service to humanity (I'm looking at you tools/perf/include/bpf/bpf.h).

Yeah, bring perf trace to the modern world :-)

- Arnaldo

Quoted 36 lines

Thanks,
Ian

Quoted 33 lines
tools/perf/tests/bpf-script-example.c +7 -6
+
 #define SEC(NAME) __attribute__((section(NAME), used))
-struct bpf_map_def SEC("maps") flip_table = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(int),
-       .value_size = sizeof(int),
-       .max_entries = 1,
-};
+struct {
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, int);
+       __type(value, int);
+} flip_table SEC(".maps");
 
 SEC("func=do_epoll_wait")
 int bpf_func__SyS_epoll_pwait(void *ctx)
tools/perf/util/llvm-utils.c +1 -2
index 96c8ef60f4f8..2dc797007419 100644
@@ -25,7 +25,7 @@
                "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
                "-Wno-unused-value -Wno-pointer-sign "          \
                "-working-directory $WORKING_DIR "              \
-               "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
+               "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -g -O2 -o - $LLVM_OPTIONS_PIPE"
 
 struct llvm_param llvm_param = {
        .clang_path = "clang",
--

2.35.3

Signature · 1 line
- Arnaldo