aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/builtin-test.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-11-09 19:46:46 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-11-14 14:49:50 -0500
commitbacf7e5d4055b65506292cf6412ec71e7948a9cf (patch)
treeb911c762c553e59f185aead53cfe279f0d8269cc /tools/perf/tests/builtin-test.c
parent16d00fee703866c61c9006eff097952289335479 (diff)
perf tests: Move test__rdpmc into separate object
Separating test__rdpmc test from the builtin-test into rdpmc 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-7-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/builtin-test.c')
-rw-r--r--tools/perf/tests/builtin-test.c168
1 files changed, 0 insertions, 168 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 7cb3928d896a..1e9a0ea68fb2 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -30,174 +30,6 @@
30#include <sched.h> 30#include <sched.h>
31 31
32 32
33
34#if defined(__x86_64__) || defined(__i386__)
35
36#define barrier() asm volatile("" ::: "memory")
37
38static u64 rdpmc(unsigned int counter)
39{
40 unsigned int low, high;
41
42 asm volatile("rdpmc" : "=a" (low), "=d" (high) : "c" (counter));
43
44 return low | ((u64)high) << 32;
45}
46
47static u64 rdtsc(void)
48{
49 unsigned int low, high;
50
51 asm volatile("rdtsc" : "=a" (low), "=d" (high));
52
53 return low | ((u64)high) << 32;
54}
55
56static u64 mmap_read_self(void *addr)
57{
58 struct perf_event_mmap_page *pc = addr;
59 u32 seq, idx, time_mult = 0, time_shift = 0;
60 u64 count, cyc = 0, time_offset = 0, enabled, running, delta;
61
62 do {
63 seq = pc->lock;
64 barrier();
65
66 enabled = pc->time_enabled;
67 running = pc->time_running;
68
69 if (enabled != running) {
70 cyc = rdtsc();
71 time_mult = pc->time_mult;
72 time_shift = pc->time_shift;
73 time_offset = pc->time_offset;
74 }
75
76 idx = pc->index;
77 count = pc->offset;
78 if (idx)
79 count += rdpmc(idx - 1);
80
81 barrier();
82 } while (pc->lock != seq);
83
84 if (enabled != running) {
85 u64 quot, rem;
86
87 quot = (cyc >> time_shift);
88 rem = cyc & ((1 << time_shift) - 1);
89 delta = time_offset + quot * time_mult +
90 ((rem * time_mult) >> time_shift);
91
92 enabled += delta;
93 if (idx)
94 running += delta;
95
96 quot = count / running;
97 rem = count % running;
98 count = quot * enabled + (rem * enabled) / running;
99 }
100
101 return count;
102}
103
104/*
105 * If the RDPMC instruction faults then signal this back to the test parent task:
106 */
107static void segfault_handler(int sig __maybe_unused,
108 siginfo_t *info __maybe_unused,
109 void *uc __maybe_unused)
110{
111 exit(-1);
112}
113
114static int __test__rdpmc(void)
115{
116 volatile int tmp = 0;
117 u64 i, loops = 1000;
118 int n;
119 int fd;
120 void *addr;
121 struct perf_event_attr attr = {
122 .type = PERF_TYPE_HARDWARE,
123 .config = PERF_COUNT_HW_INSTRUCTIONS,
124 .exclude_kernel = 1,
125 };
126 u64 delta_sum = 0;
127 struct sigaction sa;
128
129 sigfillset(&sa.sa_mask);
130 sa.sa_sigaction = segfault_handler;
131 sigaction(SIGSEGV, &sa, NULL);
132
133 fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
134 if (fd < 0) {
135 pr_err("Error: sys_perf_event_open() syscall returned "
136 "with %d (%s)\n", fd, strerror(errno));
137 return -1;
138 }
139
140 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
141 if (addr == (void *)(-1)) {
142 pr_err("Error: mmap() syscall returned with (%s)\n",
143 strerror(errno));
144 goto out_close;
145 }
146
147 for (n = 0; n < 6; n++) {
148 u64 stamp, now, delta;
149
150 stamp = mmap_read_self(addr);
151
152 for (i = 0; i < loops; i++)
153 tmp++;
154
155 now = mmap_read_self(addr);
156 loops *= 10;
157
158 delta = now - stamp;
159 pr_debug("%14d: %14Lu\n", n, (long long)delta);
160
161 delta_sum += delta;
162 }
163
164 munmap(addr, page_size);
165 pr_debug(" ");
166out_close:
167 close(fd);
168
169 if (!delta_sum)
170 return -1;
171
172 return 0;
173}
174
175static int test__rdpmc(void)
176{
177 int status = 0;
178 int wret = 0;
179 int ret;
180 int pid;
181
182 pid = fork();
183 if (pid < 0)
184 return -1;
185
186 if (!pid) {
187 ret = __test__rdpmc();
188
189 exit(ret);
190 }
191
192 wret = waitpid(pid, &status, 0);
193 if (wret < 0 || status)
194 return -1;
195
196 return 0;
197}
198
199#endif
200
201static int test__perf_pmu(void) 33static int test__perf_pmu(void)
202{ 34{
203 return perf_pmu__test(); 35 return perf_pmu__test();