linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf tools: Convert legacy map definition to  BTF-defined
@ 2022-06-29 11:27 Jiri Olsa
  2022-06-29 16:43 ` Ian Rogers
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2022-06-29 11:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Peter Zijlstra, Ingo Molnar, Mark Rutland, Namhyung Kim,
	Alexander Shishkin, Ian Rogers, linux-perf-users, bpf,
	Andrii Nakryiko

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 | 15 +++++++++------
 tools/perf/util/llvm-utils.c          |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c
index ab4b98b3165d..065a4ac5d8e5 100644
--- a/tools/perf/tests/bpf-script-example.c
+++ b/tools/perf/tests/bpf-script-example.c
@@ -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)
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",
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf tools: Convert legacy map definition to BTF-defined
  2022-06-29 11:27 [PATCH] perf tools: Convert legacy map definition to BTF-defined Jiri Olsa
@ 2022-06-29 16:43 ` Ian Rogers
  2022-06-29 16:53   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2022-06-29 16:43 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Namhyung Kim, Alexander Shishkin, linux-perf-users,
	bpf, Andrii Nakryiko

On Wed, Jun 29, 2022 at 4: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>
> ---
>  tools/perf/tests/bpf-script-example.c | 15 +++++++++------
>  tools/perf/util/llvm-utils.c          |  2 +-
>  2 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c
> index ab4b98b3165d..065a4ac5d8e5 100644
> --- a/tools/perf/tests/bpf-script-example.c
> +++ b/tools/perf/tests/bpf-script-example.c
> @@ -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

> +
>  #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",
> --
> 2.35.3
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf tools: Convert legacy map definition to BTF-defined
  2022-06-29 16:43 ` Ian Rogers
@ 2022-06-29 16:53   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-06-29 16:53 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Jiri Olsa, lkml, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Namhyung Kim, Alexander Shishkin, linux-perf-users, bpf,
	Andrii Nakryiko

Em Wed, Jun 29, 2022 at 09:43:17AM -0700, Ian Rogers escreveu:
> On Wed, Jun 29, 2022 at 4: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>
> > ---
> >  tools/perf/tests/bpf-script-example.c | 15 +++++++++------
> >  tools/perf/util/llvm-utils.c          |  2 +-
> >  2 files changed, 10 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c
> > index ab4b98b3165d..065a4ac5d8e5 100644
> > --- a/tools/perf/tests/bpf-script-example.c
> > +++ b/tools/perf/tests/bpf-script-example.c
> > @@ -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).

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

- Arnaldo
 
> Thanks,
> Ian
> 
> > +
> >  #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",
> > --
> > 2.35.3
> >

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-29 16:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-29 11:27 [PATCH] perf tools: Convert legacy map definition to BTF-defined Jiri Olsa
2022-06-29 16:43 ` Ian Rogers
2022-06-29 16:53   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).