aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2013-03-10 14:41:11 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-15 12:06:10 -0400
commit06933e3a732bb305b0721f1051a45264588e0519 (patch)
treec3f03e4014cefde840ba550a016a6b4f0710b8f2 /tools/perf
parent5a6bef47b418676546ab86d25631c3cfb9ffaf2a (diff)
perf tests: Test breakpoint overflow signal handler counts
Adding automated test to check the exact number of breakpoint event overflows and counts. This test was originally done by Vince Weaver for perf_event_tests. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Link: http://lkml.kernel.org/r/1362940871-24486-7-git-send-email-jolsa@redhat.com [ committer note: s/pr_err/pr_debug/g i.e. print just OK or FAILED in non verbose mode ] 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/bp_signal_overflow.c126
-rw-r--r--tools/perf/tests/builtin-test.c4
-rw-r--r--tools/perf/tests/tests.h1
4 files changed, 132 insertions, 0 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 21e0b4b04465..990e9a113190 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -512,6 +512,7 @@ LIB_OBJS += $(OUTPUT)tests/pmu.o
512LIB_OBJS += $(OUTPUT)tests/hists_link.o 512LIB_OBJS += $(OUTPUT)tests/hists_link.o
513LIB_OBJS += $(OUTPUT)tests/python-use.o 513LIB_OBJS += $(OUTPUT)tests/python-use.o
514LIB_OBJS += $(OUTPUT)tests/bp_signal.o 514LIB_OBJS += $(OUTPUT)tests/bp_signal.o
515LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
515 516
516BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 517BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
517BUILTIN_OBJS += $(OUTPUT)builtin-bench.o 518BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
new file mode 100644
index 000000000000..fe7ed28815f8
--- /dev/null
+++ b/tools/perf/tests/bp_signal_overflow.c
@@ -0,0 +1,126 @@
1/*
2 * Originally done by Vince Weaver <vincent.weaver@maine.edu> for
3 * perf_event_tests (git://github.com/deater/perf_event_tests)
4 */
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <unistd.h>
9#include <string.h>
10#include <sys/ioctl.h>
11#include <time.h>
12#include <fcntl.h>
13#include <signal.h>
14#include <sys/mman.h>
15#include <linux/compiler.h>
16#include <linux/hw_breakpoint.h>
17
18#include "tests.h"
19#include "debug.h"
20#include "perf.h"
21
22static int overflows;
23
24__attribute__ ((noinline))
25static int test_function(void)
26{
27 return time(NULL);
28}
29
30static void sig_handler(int signum __maybe_unused,
31 siginfo_t *oh __maybe_unused,
32 void *uc __maybe_unused)
33{
34 overflows++;
35}
36
37static long long bp_count(int fd)
38{
39 long long count;
40 int ret;
41
42 ret = read(fd, &count, sizeof(long long));
43 if (ret != sizeof(long long)) {
44 pr_debug("failed to read: %d\n", ret);
45 return TEST_FAIL;
46 }
47
48 return count;
49}
50
51#define EXECUTIONS 10000
52#define THRESHOLD 100
53
54int test__bp_signal_overflow(void)
55{
56 struct perf_event_attr pe;
57 struct sigaction sa;
58 long long count;
59 int fd, i, fails = 0;
60
61 /* setup SIGIO signal handler */
62 memset(&sa, 0, sizeof(struct sigaction));
63 sa.sa_sigaction = (void *) sig_handler;
64 sa.sa_flags = SA_SIGINFO;
65
66 if (sigaction(SIGIO, &sa, NULL) < 0) {
67 pr_debug("failed setting up signal handler\n");
68 return TEST_FAIL;
69 }
70
71 memset(&pe, 0, sizeof(struct perf_event_attr));
72 pe.type = PERF_TYPE_BREAKPOINT;
73 pe.size = sizeof(struct perf_event_attr);
74
75 pe.config = 0;
76 pe.bp_type = HW_BREAKPOINT_X;
77 pe.bp_addr = (unsigned long) test_function;
78 pe.bp_len = sizeof(long);
79
80 pe.sample_period = THRESHOLD;
81 pe.sample_type = PERF_SAMPLE_IP;
82 pe.wakeup_events = 1;
83
84 pe.disabled = 1;
85 pe.exclude_kernel = 1;
86 pe.exclude_hv = 1;
87
88 fd = sys_perf_event_open(&pe, 0, -1, -1, 0);
89 if (fd < 0) {
90 pr_debug("failed opening event %llx\n", pe.config);
91 return TEST_FAIL;
92 }
93
94 fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
95 fcntl(fd, F_SETSIG, SIGIO);
96 fcntl(fd, F_SETOWN, getpid());
97
98 ioctl(fd, PERF_EVENT_IOC_RESET, 0);
99 ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
100
101 for (i = 0; i < EXECUTIONS; i++)
102 test_function();
103
104 ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
105
106 count = bp_count(fd);
107
108 close(fd);
109
110 pr_debug("count %lld, overflow %d\n",
111 count, overflows);
112
113 if (count != EXECUTIONS) {
114 pr_debug("\tWrong number of executions %lld != %d\n",
115 count, EXECUTIONS);
116 fails++;
117 }
118
119 if (overflows != EXECUTIONS / THRESHOLD) {
120 pr_debug("\tWrong number of overflows %d != %d\n",
121 overflows, EXECUTIONS / THRESHOLD);
122 fails++;
123 }
124
125 return fails ? TEST_FAIL : TEST_OK;
126}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 37b108bf973c..45d9ad442d56 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -82,6 +82,10 @@ static struct test {
82 .func = test__bp_signal, 82 .func = test__bp_signal,
83 }, 83 },
84 { 84 {
85 .desc = "Test breakpoint overflow sampling",
86 .func = test__bp_signal_overflow,
87 },
88 {
85 .func = NULL, 89 .func = NULL,
86 }, 90 },
87}; 91};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 05d0e58064a3..6cf1ec4866d3 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -24,5 +24,6 @@ int test__parse_events(void);
24int test__hists_link(void); 24int test__hists_link(void);
25int test__python_use(void); 25int test__python_use(void);
26int test__bp_signal(void); 26int test__bp_signal(void);
27int test__bp_signal_overflow(void);
27 28
28#endif /* TESTS_H */ 29#endif /* TESTS_H */