aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-11-09 19:46:43 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-11-14 14:49:25 -0500
commitbd90517b374b1d6381a5509f55df1a9b7c33a6b1 (patch)
treeb3b9011250f5d889b45dd997de55bb5c525c661f /tools/perf
parentd3b59a38bcdab4248134023c2c5dfabee5a4878e (diff)
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 <jolsa@redhat.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1352508412-16914-4-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/tests/builtin-test.c114
-rw-r--r--tools/perf/tests/open-syscall-all-cpus.c120
-rw-r--r--tools/perf/tests/tests.h1
4 files changed, 122 insertions, 114 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 69f582c53cbb..d413e89c38e1 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -433,6 +433,7 @@ LIB_OBJS += $(OUTPUT)tests/dso-data.o
433LIB_OBJS += $(OUTPUT)tests/attr.o 433LIB_OBJS += $(OUTPUT)tests/attr.o
434LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o 434LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o
435LIB_OBJS += $(OUTPUT)tests/open-syscall.o 435LIB_OBJS += $(OUTPUT)tests/open-syscall.o
436LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o
436LIB_OBJS += $(OUTPUT)tests/util.o 437LIB_OBJS += $(OUTPUT)tests/util.o
437 438
438BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 439BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index b6b1e46a51c6..98e883bc330b 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -29,120 +29,6 @@
29 29
30#include <sched.h> 30#include <sched.h>
31 31
32static 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
138out_close_fd:
139 perf_evsel__close_fd(evsel, 1, threads->nr);
140out_evsel_delete:
141 perf_evsel__delete(evsel);
142out_thread_map_delete:
143 thread_map__delete(threads);
144 return err;
145}
146 32
147/* 33/*
148 * This test will generate random numbers of calls to some getpid syscalls, 34 * This test will generate random numbers of calls to some getpid syscalls,
diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
new file mode 100644
index 000000000000..31072aba0d54
--- /dev/null
+++ b/tools/perf/tests/open-syscall-all-cpus.c
@@ -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
7int 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
113out_close_fd:
114 perf_evsel__close_fd(evsel, 1, threads->nr);
115out_evsel_delete:
116 perf_evsel__delete(evsel);
117out_thread_map_delete:
118 thread_map__delete(threads);
119 return err;
120}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index bac133e15bbd..c2887f226db3 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -4,6 +4,7 @@
4/* Tests */ 4/* Tests */
5int test__vmlinux_matches_kallsyms(void); 5int test__vmlinux_matches_kallsyms(void);
6int test__open_syscall_event(void); 6int test__open_syscall_event(void);
7int test__open_syscall_event_on_all_cpus(void);
7 8
8/* Util */ 9/* Util */
9int trace_event__id(const char *evname); 10int trace_event__id(const char *evname);