Skip to content

Commit bd90517

Browse files
Jiri Olsaacmel
authored andcommitted
perf tests: Move test__open_syscall_event_on_all_cpus into separate object
Separating test__open_syscall_event_on_all_cpus test from the builtin-test into open-syscall-all-cpus object. Signed-off-by: Jiri Olsa <[email protected]> Cc: Corey Ashford <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d3b59a3 commit bd90517

File tree

4 files changed

+122
-114
lines changed

4 files changed

+122
-114
lines changed

tools/perf/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ LIB_OBJS += $(OUTPUT)tests/dso-data.o
433433
LIB_OBJS += $(OUTPUT)tests/attr.o
434434
LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o
435435
LIB_OBJS += $(OUTPUT)tests/open-syscall.o
436+
LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o
436437
LIB_OBJS += $(OUTPUT)tests/util.o
437438

438439
BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o

tools/perf/tests/builtin-test.c

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -29,120 +29,6 @@
2929

3030
#include <sched.h>
3131

32-
static int test__open_syscall_event_on_all_cpus(void)
33-
{
34-
int err = -1, fd, cpu;
35-
struct thread_map *threads;
36-
struct cpu_map *cpus;
37-
struct perf_evsel *evsel;
38-
struct perf_event_attr attr;
39-
unsigned int nr_open_calls = 111, i;
40-
cpu_set_t cpu_set;
41-
int id = trace_event__id("sys_enter_open");
42-
43-
if (id < 0) {
44-
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
45-
return -1;
46-
}
47-
48-
threads = thread_map__new(-1, getpid(), UINT_MAX);
49-
if (threads == NULL) {
50-
pr_debug("thread_map__new\n");
51-
return -1;
52-
}
53-
54-
cpus = cpu_map__new(NULL);
55-
if (cpus == NULL) {
56-
pr_debug("cpu_map__new\n");
57-
goto out_thread_map_delete;
58-
}
59-
60-
61-
CPU_ZERO(&cpu_set);
62-
63-
memset(&attr, 0, sizeof(attr));
64-
attr.type = PERF_TYPE_TRACEPOINT;
65-
attr.config = id;
66-
evsel = perf_evsel__new(&attr, 0);
67-
if (evsel == NULL) {
68-
pr_debug("perf_evsel__new\n");
69-
goto out_thread_map_delete;
70-
}
71-
72-
if (perf_evsel__open(evsel, cpus, threads) < 0) {
73-
pr_debug("failed to open counter: %s, "
74-
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
75-
strerror(errno));
76-
goto out_evsel_delete;
77-
}
78-
79-
for (cpu = 0; cpu < cpus->nr; ++cpu) {
80-
unsigned int ncalls = nr_open_calls + cpu;
81-
/*
82-
* XXX eventually lift this restriction in a way that
83-
* keeps perf building on older glibc installations
84-
* without CPU_ALLOC. 1024 cpus in 2010 still seems
85-
* a reasonable upper limit tho :-)
86-
*/
87-
if (cpus->map[cpu] >= CPU_SETSIZE) {
88-
pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
89-
continue;
90-
}
91-
92-
CPU_SET(cpus->map[cpu], &cpu_set);
93-
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
94-
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
95-
cpus->map[cpu],
96-
strerror(errno));
97-
goto out_close_fd;
98-
}
99-
for (i = 0; i < ncalls; ++i) {
100-
fd = open("/etc/passwd", O_RDONLY);
101-
close(fd);
102-
}
103-
CPU_CLR(cpus->map[cpu], &cpu_set);
104-
}
105-
106-
/*
107-
* Here we need to explicitely preallocate the counts, as if
108-
* we use the auto allocation it will allocate just for 1 cpu,
109-
* as we start by cpu 0.
110-
*/
111-
if (perf_evsel__alloc_counts(evsel, cpus->nr) < 0) {
112-
pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus->nr);
113-
goto out_close_fd;
114-
}
115-
116-
err = 0;
117-
118-
for (cpu = 0; cpu < cpus->nr; ++cpu) {
119-
unsigned int expected;
120-
121-
if (cpus->map[cpu] >= CPU_SETSIZE)
122-
continue;
123-
124-
if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) {
125-
pr_debug("perf_evsel__read_on_cpu\n");
126-
err = -1;
127-
break;
128-
}
129-
130-
expected = nr_open_calls + cpu;
131-
if (evsel->counts->cpu[cpu].val != expected) {
132-
pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
133-
expected, cpus->map[cpu], evsel->counts->cpu[cpu].val);
134-
err = -1;
135-
}
136-
}
137-
138-
out_close_fd:
139-
perf_evsel__close_fd(evsel, 1, threads->nr);
140-
out_evsel_delete:
141-
perf_evsel__delete(evsel);
142-
out_thread_map_delete:
143-
thread_map__delete(threads);
144-
return err;
145-
}
14632

14733
/*
14834
* This test will generate random numbers of calls to some getpid syscalls,
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include "evsel.h"
2+
#include "tests.h"
3+
#include "thread_map.h"
4+
#include "cpumap.h"
5+
#include "debug.h"
6+
7+
int test__open_syscall_event_on_all_cpus(void)
8+
{
9+
int err = -1, fd, cpu;
10+
struct thread_map *threads;
11+
struct cpu_map *cpus;
12+
struct perf_evsel *evsel;
13+
struct perf_event_attr attr;
14+
unsigned int nr_open_calls = 111, i;
15+
cpu_set_t cpu_set;
16+
int id = trace_event__id("sys_enter_open");
17+
18+
if (id < 0) {
19+
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
20+
return -1;
21+
}
22+
23+
threads = thread_map__new(-1, getpid(), UINT_MAX);
24+
if (threads == NULL) {
25+
pr_debug("thread_map__new\n");
26+
return -1;
27+
}
28+
29+
cpus = cpu_map__new(NULL);
30+
if (cpus == NULL) {
31+
pr_debug("cpu_map__new\n");
32+
goto out_thread_map_delete;
33+
}
34+
35+
36+
CPU_ZERO(&cpu_set);
37+
38+
memset(&attr, 0, sizeof(attr));
39+
attr.type = PERF_TYPE_TRACEPOINT;
40+
attr.config = id;
41+
evsel = perf_evsel__new(&attr, 0);
42+
if (evsel == NULL) {
43+
pr_debug("perf_evsel__new\n");
44+
goto out_thread_map_delete;
45+
}
46+
47+
if (perf_evsel__open(evsel, cpus, threads) < 0) {
48+
pr_debug("failed to open counter: %s, "
49+
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
50+
strerror(errno));
51+
goto out_evsel_delete;
52+
}
53+
54+
for (cpu = 0; cpu < cpus->nr; ++cpu) {
55+
unsigned int ncalls = nr_open_calls + cpu;
56+
/*
57+
* XXX eventually lift this restriction in a way that
58+
* keeps perf building on older glibc installations
59+
* without CPU_ALLOC. 1024 cpus in 2010 still seems
60+
* a reasonable upper limit tho :-)
61+
*/
62+
if (cpus->map[cpu] >= CPU_SETSIZE) {
63+
pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
64+
continue;
65+
}
66+
67+
CPU_SET(cpus->map[cpu], &cpu_set);
68+
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
69+
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
70+
cpus->map[cpu],
71+
strerror(errno));
72+
goto out_close_fd;
73+
}
74+
for (i = 0; i < ncalls; ++i) {
75+
fd = open("/etc/passwd", O_RDONLY);
76+
close(fd);
77+
}
78+
CPU_CLR(cpus->map[cpu], &cpu_set);
79+
}
80+
81+
/*
82+
* Here we need to explicitely preallocate the counts, as if
83+
* we use the auto allocation it will allocate just for 1 cpu,
84+
* as we start by cpu 0.
85+
*/
86+
if (perf_evsel__alloc_counts(evsel, cpus->nr) < 0) {
87+
pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus->nr);
88+
goto out_close_fd;
89+
}
90+
91+
err = 0;
92+
93+
for (cpu = 0; cpu < cpus->nr; ++cpu) {
94+
unsigned int expected;
95+
96+
if (cpus->map[cpu] >= CPU_SETSIZE)
97+
continue;
98+
99+
if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) {
100+
pr_debug("perf_evsel__read_on_cpu\n");
101+
err = -1;
102+
break;
103+
}
104+
105+
expected = nr_open_calls + cpu;
106+
if (evsel->counts->cpu[cpu].val != expected) {
107+
pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
108+
expected, cpus->map[cpu], evsel->counts->cpu[cpu].val);
109+
err = -1;
110+
}
111+
}
112+
113+
out_close_fd:
114+
perf_evsel__close_fd(evsel, 1, threads->nr);
115+
out_evsel_delete:
116+
perf_evsel__delete(evsel);
117+
out_thread_map_delete:
118+
thread_map__delete(threads);
119+
return err;
120+
}

tools/perf/tests/tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/* Tests */
55
int test__vmlinux_matches_kallsyms(void);
66
int test__open_syscall_event(void);
7+
int test__open_syscall_event_on_all_cpus(void);
78

89
/* Util */
910
int trace_event__id(const char *evname);

0 commit comments

Comments
 (0)