diff mbox series

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

Message ID 20191001113307.27796-2-bjorn.topel@gmail.com
State Not Applicable
Delegated to: BPF Maintainers
Headers show
Series perf tools: optional compile time test_attr__* depenency for perf-sys.h | expand

Commit Message

Björn Töpel Oct. 1, 2019, 11:33 a.m. UTC
From: Björn Töpel <bjorn.topel@intel.com>

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 <bjorn.topel@intel.com>
---
 tools/perf/perf-sys.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Song Liu Oct. 2, 2019, 9 p.m. UTC | #1
On Tue, Oct 1, 2019 at 4:35 AM Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> From: Björn Töpel <bjorn.topel@intel.com>
>
> 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 <bjorn.topel@intel.com>

Acked-by: Song Liu <songliubraving@fb.com>
Arnaldo Carvalho de Melo Oct. 3, 2019, 1:50 p.m. UTC | #2
Em Tue, Oct 01, 2019 at 01:33:06PM +0200, Björn Töpel escreveu:
> From: Björn Töpel <bjorn.topel@intel.com>
> 
> 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 <bjorn.topel@intel.com>
> ---
>  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
diff mbox series

Patch

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