diff mbox series

[PATCHv2] perf tools: Convert legacy map definition to BTF-defined

Message ID 20220704152721.352046-1-jolsa@kernel.org (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series [PATCHv2] perf tools: Convert legacy map definition to BTF-defined | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15

Commit Message

Jiri Olsa July 4, 2022, 3:27 p.m. UTC
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>
---
 tools/perf/tests/bpf-script-example.c | 35 ++++++++++++++++++---------
 tools/perf/util/llvm-utils.c          |  2 +-
 2 files changed, 24 insertions(+), 13 deletions(-)

v2 changes:
  - added comments to macros [Ian]
  - removed struct bpf_map_def, it's no longer needed

Comments

Andrii Nakryiko July 6, 2022, 5:08 a.m. UTC | #1
On Mon, Jul 4, 2022 at 8:27 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> 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>
> ---

LGTM. Thanks for taking care of this!

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  tools/perf/tests/bpf-script-example.c | 35 ++++++++++++++++++---------
>  tools/perf/util/llvm-utils.c          |  2 +-
>  2 files changed, 24 insertions(+), 13 deletions(-)
>

[...]
Arnaldo Carvalho de Melo Aug. 1, 2022, 5:43 p.m. UTC | #2
Em Tue, Jul 05, 2022 at 10:08:16PM -0700, Andrii Nakryiko escreveu:
> On Mon, Jul 4, 2022 at 8:27 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > 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>
> > ---
> 
> LGTM. Thanks for taking care of this!
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>

Thanks, applied.

- Arnaldo

 
> >  tools/perf/tests/bpf-script-example.c | 35 ++++++++++++++++++---------
> >  tools/perf/util/llvm-utils.c          |  2 +-
> >  2 files changed, 24 insertions(+), 13 deletions(-)
> >
> 
> [...]
diff mbox series

Patch

diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c
index ab4b98b3165d..7981c69ed1b4 100644
--- a/tools/perf/tests/bpf-script-example.c
+++ b/tools/perf/tests/bpf-script-example.c
@@ -17,20 +17,31 @@  static void *(*bpf_map_lookup_elem)(void *map, void *key) =
 static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
 	(void *) BPF_FUNC_map_update_elem;
 
-struct bpf_map_def {
-	unsigned int type;
-	unsigned int key_size;
-	unsigned int value_size;
-	unsigned int max_entries;
-};
+/*
+ * Following macros are taken from tools/lib/bpf/bpf_helpers.h,
+ * and are used to create BTF defined maps. It is easier to take
+ * 2 simple macros, than being able to include above header in
+ * runtime.
+ *
+ * __uint - defines integer attribute of BTF map definition,
+ * Such attributes are represented using a pointer to an array,
+ * in which dimensionality of array encodes specified integer
+ * value.
+ *
+ * __type - defines pointer variable with typeof(val) type for
+ * attributes like key or value, which will be defined by the
+ * size of the type.
+ */
+#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)
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 96c8ef60f4f8..2dc797007419 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -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",