perf tests: Call test_attr__open() directly
authorJiri Olsa <jolsa@redhat.com>
Thu, 27 Aug 2020 19:32:01 +0000 (21:32 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 10 Sep 2020 14:55:37 +0000 (11:55 -0300)
There's no longer need to call test_attr__open() from
sys_perf_event_open(), because both 'perf record' and 'perf stat' call
evsel__open_cpu(), so we can call it directly from there and not polute
the perf-sys.h header.

Committer testing:

Before and after:

  # perf test attr
  17: Setup struct perf_event_attr                                    : Ok
  49: Synthesize attr update                                          : Ok
  # perf test -v attr
  17: Setup struct perf_event_attr                                    :
  --- start ---
  test child forked, pid 2170868
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any_ret'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any_ret'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-C0'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-graph-fp'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-period'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-group-sampling'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-freq'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-detailed-3'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-k'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-k'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-group1'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-u'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-u'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-basic'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any_call'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any_call'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-default'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-graph-dwarf'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-no-buffering'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-raw'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-detailed-2'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-count'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-data'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-any'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-group'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-any'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-any'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-graph-default'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-no-samples'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-C0'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-no-inherit'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-ind_call'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-ind_call'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-basic'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-group1'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-pfm-period'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-pfm-period'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-detailed-1'
  running '/home/acme/libexec/perf-core/tests/attr/test-stat-no-inherit'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-hv'
  unsupp  '/home/acme/libexec/perf-core/tests/attr/test-record-branch-filter-hv'
  running '/home/acme/libexec/perf-core/tests/attr/test-record-group'
  test child finished with 0
  ---- end ----
  Setup struct perf_event_attr: Ok
  49: Synthesize attr update                                          :
  --- start ---
  test child forked, pid 2171004
  test child finished with 0
  ---- end ----
  Synthesize attr update: Ok
  #

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20200827193201.GB127372@krava
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/perf-sys.h
tools/perf/tests/attr.c
tools/perf/util/evsel.c
tools/perf/util/python.c
tools/perf/util/util.h

index 15e458e..7a2264e 100644 (file)
@@ -9,31 +9,13 @@
 
 struct perf_event_attr;
 
-extern bool test_attr__enabled;
-void test_attr__ready(void);
-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);
-
-#ifndef HAVE_ATTR_TEST
-#define HAVE_ATTR_TEST 1
-#endif
-
 static inline int
 sys_perf_event_open(struct perf_event_attr *attr,
                      pid_t pid, int cpu, int group_fd,
                      unsigned long flags)
 {
-       int fd;
-
-       fd = syscall(__NR_perf_event_open, attr, pid, cpu,
-                    group_fd, flags);
-
-#if HAVE_ATTR_TEST
-       if (unlikely(test_attr__enabled))
-               test_attr__open(attr, pid, cpu, fd, group_fd, flags);
-#endif
-       return fd;
+       return syscall(__NR_perf_event_open, attr, pid, cpu,
+                      group_fd, flags);
 }
 
 #endif /* _PERF_SYS_H */
index a9599ab..ec972e0 100644 (file)
@@ -30,9 +30,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include "../perf-sys.h"
 #include <subcmd/exec-cmd.h>
 #include "event.h"
+#include "util.h"
 #include "tests.h"
 
 #define ENV "PERF_TEST_ATTR"
index fd86500..6f0e231 100644 (file)
@@ -1680,6 +1680,11 @@ retry_open:
 
                        FD(evsel, cpu, thread) = fd;
 
+                       if (unlikely(test_attr__enabled)) {
+                               test_attr__open(&evsel->core.attr, pid, cpus->map[cpu],
+                                               fd, group_fd, flags);
+                       }
+
                        if (fd < 0) {
                                err = -errno;
 
index 75a9b1d..74f8594 100644 (file)
@@ -17,7 +17,7 @@
 #include "mmap.h"
 #include "util/env.h"
 #include <internal/lib.h>
-#include "../perf-sys.h"
+#include "util.h"
 
 #if PY_MAJOR_VERSION < 3
 #define _PyUnicode_FromString(arg) \
index f486fdd..ad73705 100644 (file)
@@ -62,4 +62,10 @@ char *perf_exe(char *buf, int len);
 #endif
 #endif
 
+extern bool test_attr__enabled;
+void test_attr__ready(void);
+void test_attr__init(void);
+struct perf_event_attr;
+void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
+                    int fd, int group_fd, unsigned long flags);
 #endif /* GIT_COMPAT_UTIL_H */