2019-10-01 11:33:53

by Björn Töpel

[permalink] [raw]
Subject: [PATCH 0/2] perf tools: optional compile time test_attr__* depenency for perf-sys.h

This mini series makes it possible to disable the use of test_attr__*
for perf-sys.h users outside perf. E.g., samples/bpf/ uses perf-sys.h
as a syscall wrapper.

Now a user can define HAVE_ATTR_TEST to zero to avoid this, and as a
nice side-effect it also fixes the samples/bpf/ build. ;-)

Björn Töpel (2):
perf tools: Make usage of test_attr__* optional for perf-sys.h
samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

samples/bpf/Makefile | 1 +
tools/perf/perf-sys.h | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)

--
2.20.1


2019-10-01 11:34:07

by Björn Töpel

[permalink] [raw]
Subject: [PATCH 1/2] perf tools: Make usage of test_attr__* optional for perf-sys.h

From: Björn Töpel <[email protected]>

For users of perf-sys.h outside perf, e.g. samples/bpf/bpf_load.c,
it's convenient not to depend on test_attr__*.

After commit 91854f9a077e ("perf tools: Move everything related to
sys_perf_event_open() to perf-sys.h"), all users of perf-sys.h will
depend on test_attr__enabled and test_attr__open.

This commit enables a user to define HAVE_ATTR_TEST to zero in order
to omit the test dependency.

Fixes: 91854f9a077e ("perf tools: Move everything related to sys_perf_event_open() to perf-sys.h")
Signed-off-by: Björn Töpel <[email protected]>
---
tools/perf/perf-sys.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 63e4349a772a..15e458e150bd 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -15,7 +15,9 @@ void test_attr__init(void);
void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
int fd, int group_fd, unsigned long flags);

-#define HAVE_ATTR_TEST
+#ifndef HAVE_ATTR_TEST
+#define HAVE_ATTR_TEST 1
+#endif

static inline int
sys_perf_event_open(struct perf_event_attr *attr,
@@ -27,7 +29,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
fd = syscall(__NR_perf_event_open, attr, pid, cpu,
group_fd, flags);

-#ifdef HAVE_ATTR_TEST
+#if HAVE_ATTR_TEST
if (unlikely(test_attr__enabled))
test_attr__open(attr, pid, cpu, fd, group_fd, flags);
#endif
--
2.20.1

2019-10-01 11:35:35

by Björn Töpel

[permalink] [raw]
Subject: [PATCH 2/2] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

From: Björn Töpel <[email protected]>

To remove that test_attr__{enabled/open} are used by perf-sys.h, we
set HAVE_ATTR_TEST to zero.

Signed-off-by: Björn Töpel <[email protected]>
---
samples/bpf/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 1d9be26b4edd..42b571cde177 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -176,6 +176,7 @@ KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
+KBUILD_HOSTCFLAGS += -DHAVE_ATTR_TEST=0

HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable

--
2.20.1

2019-10-02 21:53:42

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH 1/2] perf tools: Make usage of test_attr__* optional for perf-sys.h

On Tue, Oct 1, 2019 at 4:35 AM Björn Töpel <[email protected]> wrote:
>
> From: Björn Töpel <[email protected]>
>
> For users of perf-sys.h outside perf, e.g. samples/bpf/bpf_load.c,
> it's convenient not to depend on test_attr__*.
>
> After commit 91854f9a077e ("perf tools: Move everything related to
> sys_perf_event_open() to perf-sys.h"), all users of perf-sys.h will
> depend on test_attr__enabled and test_attr__open.
>
> This commit enables a user to define HAVE_ATTR_TEST to zero in order
> to omit the test dependency.
>
> Fixes: 91854f9a077e ("perf tools: Move everything related to sys_perf_event_open() to perf-sys.h")
> Signed-off-by: Björn Töpel <[email protected]>

Acked-by: Song Liu <[email protected]>

2019-10-02 21:55:33

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH 2/2] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

On Tue, Oct 1, 2019 at 4:36 AM Björn Töpel <[email protected]> wrote:
>
> From: Björn Töpel <[email protected]>
>
> To remove that test_attr__{enabled/open} are used by perf-sys.h, we
> set HAVE_ATTR_TEST to zero.
>
> Signed-off-by: Björn Töpel <[email protected]>

Acked-by: Song Liu <[email protected]>

2019-10-03 00:32:50

by KP Singh

[permalink] [raw]
Subject: Re: [PATCH 2/2] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

Tested-by: KP Singh <[email protected]>

I can confirm that samples/bpf are building for me now (x86_64,
clang-8) after applying this series and:

* https://lore.kernel.org/bpf/CAPhsuW5c9v0OnU4g+eYkPjBCuNMjC_69pFhzr=nTfDMAy4bK6w@mail.gmail.com
* https://lore.kernel.org/bpf/[email protected]/

on the current bpf-next/master.


- KP

On Wed, Oct 2, 2019 at 11:00 PM Song Liu <[email protected]> wrote:
>
> On Tue, Oct 1, 2019 at 4:36 AM Björn Töpel <[email protected]> wrote:
> >
> > From: Björn Töpel <[email protected]>
> >
> > To remove that test_attr__{enabled/open} are used by perf-sys.h, we
> > set HAVE_ATTR_TEST to zero.
> >
> > Signed-off-by: Björn Töpel <[email protected]>
>
> Acked-by: Song Liu <[email protected]>

2019-10-03 14:46:04

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 1/2] perf tools: Make usage of test_attr__* optional for perf-sys.h

Em Tue, Oct 01, 2019 at 01:33:06PM +0200, Bj?rn T?pel escreveu:
> From: Bj?rn T?pel <[email protected]>
>
> For users of perf-sys.h outside perf, e.g. samples/bpf/bpf_load.c,
> it's convenient not to depend on test_attr__*.
>
> After commit 91854f9a077e ("perf tools: Move everything related to
> sys_perf_event_open() to perf-sys.h"), all users of perf-sys.h will
> depend on test_attr__enabled and test_attr__open.
>
> This commit enables a user to define HAVE_ATTR_TEST to zero in order
> to omit the test dependency.

Woah, I wasn't expecting tools/perf/ stuff to be included from outside
tools/perf/, so thanks for fixing that odd user.

Applied.

- Arnaldo

> Fixes: 91854f9a077e ("perf tools: Move everything related to sys_perf_event_open() to perf-sys.h")
> Signed-off-by: Bj?rn T?pel <[email protected]>
> ---
> tools/perf/perf-sys.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
> index 63e4349a772a..15e458e150bd 100644
> --- a/tools/perf/perf-sys.h
> +++ b/tools/perf/perf-sys.h
> @@ -15,7 +15,9 @@ void test_attr__init(void);
> void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
> int fd, int group_fd, unsigned long flags);
>
> -#define HAVE_ATTR_TEST
> +#ifndef HAVE_ATTR_TEST
> +#define HAVE_ATTR_TEST 1
> +#endif
>
> static inline int
> sys_perf_event_open(struct perf_event_attr *attr,
> @@ -27,7 +29,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
> fd = syscall(__NR_perf_event_open, attr, pid, cpu,
> group_fd, flags);
>
> -#ifdef HAVE_ATTR_TEST
> +#if HAVE_ATTR_TEST
> if (unlikely(test_attr__enabled))
> test_attr__open(attr, pid, cpu, fd, group_fd, flags);
> #endif
> --
> 2.20.1

--

- Arnaldo

2019-10-03 14:46:57

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 2/2] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

Em Thu, Oct 03, 2019 at 02:19:42AM +0200, KP Singh escreveu:
> Tested-by: KP Singh <[email protected]>
>
> I can confirm that samples/bpf are building for me now (x86_64,
> clang-8) after applying this series and:
>
> * https://lore.kernel.org/bpf/CAPhsuW5c9v0OnU4g+eYkPjBCuNMjC_69pFhzr=nTfDMAy4bK6w@mail.gmail.com
> * https://lore.kernel.org/bpf/[email protected]/
>
> on the current bpf-next/master.
>
>
> - KP
>
> On Wed, Oct 2, 2019 at 11:00 PM Song Liu <[email protected]> wrote:
> >
> > On Tue, Oct 1, 2019 at 4:36 AM Bj?rn T?pel <[email protected]> wrote:
> > >
> > > From: Bj?rn T?pel <[email protected]>
> > >
> > > To remove that test_attr__{enabled/open} are used by perf-sys.h, we
> > > set HAVE_ATTR_TEST to zero.
> > >
> > > Signed-off-by: Bj?rn T?pel <[email protected]>
> >
> > Acked-by: Song Liu <[email protected]>

Thanks, applied.

- Arnaldo

2019-10-15 05:44:50

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: perf/core] perf tools: Make usage of test_attr__* optional for perf-sys.h

The following commit has been merged into the perf/core branch of tip:

Commit-ID: 06f84d1989b7e58d56fa2e448664585749d41221
Gitweb: https://git.kernel.org/tip/06f84d1989b7e58d56fa2e448664585749d41221
Author: Björn Töpel <[email protected]>
AuthorDate: Tue, 01 Oct 2019 13:33:06 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf tools: Make usage of test_attr__* optional for perf-sys.h

For users of perf-sys.h outside perf, e.g. samples/bpf/bpf_load.c, it's
convenient not to depend on test_attr__*.

After commit 91854f9a077e ("perf tools: Move everything related to
sys_perf_event_open() to perf-sys.h"), all users of perf-sys.h will
depend on test_attr__enabled and test_attr__open.

This commit enables a user to define HAVE_ATTR_TEST to zero in order
to omit the test dependency.

Fixes: 91854f9a077e ("perf tools: Move everything related to sys_perf_event_open() to perf-sys.h")
Signed-off-by: Björn Töpel <[email protected]>
Acked-by: Song Liu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/perf-sys.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 63e4349..15e458e 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -15,7 +15,9 @@ void test_attr__init(void);
void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
int fd, int group_fd, unsigned long flags);

-#define HAVE_ATTR_TEST
+#ifndef HAVE_ATTR_TEST
+#define HAVE_ATTR_TEST 1
+#endif

static inline int
sys_perf_event_open(struct perf_event_attr *attr,
@@ -27,7 +29,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
fd = syscall(__NR_perf_event_open, attr, pid, cpu,
group_fd, flags);

-#ifdef HAVE_ATTR_TEST
+#if HAVE_ATTR_TEST
if (unlikely(test_attr__enabled))
test_attr__open(attr, pid, cpu, fd, group_fd, flags);
#endif

2019-10-15 05:50:31

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: perf/core] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

The following commit has been merged into the perf/core branch of tip:

Commit-ID: fce9501aec6bdda45ef3a5e365a5e0de7de7fe2d
Gitweb: https://git.kernel.org/tip/fce9501aec6bdda45ef3a5e365a5e0de7de7fe2d
Author: Björn Töpel <[email protected]>
AuthorDate: Tue, 01 Oct 2019 13:33:07 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

To remove that test_attr__{enabled/open} are used by perf-sys.h, we
set HAVE_ATTR_TEST to zero.

Signed-off-by: Björn Töpel <[email protected]>
Tested-by: KP Singh <[email protected]>
Acked-by: Song Liu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
samples/bpf/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 1d9be26..42b571c 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -176,6 +176,7 @@ KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
+KBUILD_HOSTCFLAGS += -DHAVE_ATTR_TEST=0

HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable