Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tests: Call test_attr__open() directly

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
8366f0d2 b1f815c4

+15 -22
+2 -20
tools/perf/perf-sys.h
··· 9 9 10 10 struct perf_event_attr; 11 11 12 - extern bool test_attr__enabled; 13 - void test_attr__ready(void); 14 - void test_attr__init(void); 15 - void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, 16 - int fd, int group_fd, unsigned long flags); 17 - 18 - #ifndef HAVE_ATTR_TEST 19 - #define HAVE_ATTR_TEST 1 20 - #endif 21 - 22 12 static inline int 23 13 sys_perf_event_open(struct perf_event_attr *attr, 24 14 pid_t pid, int cpu, int group_fd, 25 15 unsigned long flags) 26 16 { 27 - int fd; 28 - 29 - fd = syscall(__NR_perf_event_open, attr, pid, cpu, 30 - group_fd, flags); 31 - 32 - #if HAVE_ATTR_TEST 33 - if (unlikely(test_attr__enabled)) 34 - test_attr__open(attr, pid, cpu, fd, group_fd, flags); 35 - #endif 36 - return fd; 17 + return syscall(__NR_perf_event_open, attr, pid, cpu, 18 + group_fd, flags); 37 19 } 38 20 39 21 #endif /* _PERF_SYS_H */
+1 -1
tools/perf/tests/attr.c
··· 30 30 #include <sys/types.h> 31 31 #include <sys/stat.h> 32 32 #include <unistd.h> 33 - #include "../perf-sys.h" 34 33 #include <subcmd/exec-cmd.h> 35 34 #include "event.h" 35 + #include "util.h" 36 36 #include "tests.h" 37 37 38 38 #define ENV "PERF_TEST_ATTR"
+5
tools/perf/util/evsel.c
··· 1680 1680 1681 1681 FD(evsel, cpu, thread) = fd; 1682 1682 1683 + if (unlikely(test_attr__enabled)) { 1684 + test_attr__open(&evsel->core.attr, pid, cpus->map[cpu], 1685 + fd, group_fd, flags); 1686 + } 1687 + 1683 1688 if (fd < 0) { 1684 1689 err = -errno; 1685 1690
+1 -1
tools/perf/util/python.c
··· 17 17 #include "mmap.h" 18 18 #include "util/env.h" 19 19 #include <internal/lib.h> 20 - #include "../perf-sys.h" 20 + #include "util.h" 21 21 22 22 #if PY_MAJOR_VERSION < 3 23 23 #define _PyUnicode_FromString(arg) \
+6
tools/perf/util/util.h
··· 62 62 #endif 63 63 #endif 64 64 65 + extern bool test_attr__enabled; 66 + void test_attr__ready(void); 67 + void test_attr__init(void); 68 + struct perf_event_attr; 69 + void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, 70 + int fd, int group_fd, unsigned long flags); 65 71 #endif /* GIT_COMPAT_UTIL_H */