]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/tests/bp_signal.c
2 * Inspired by breakpoint overflow test done by
3 * Vince Weaver <vincent.weaver@maine.edu> for perf_event_tests
4 * (git://github.com/deater/perf_event_tests)
11 #include <sys/ioctl.h>
16 #include <linux/compiler.h>
17 #include <linux/hw_breakpoint.h>
27 __attribute__ ((noinline
))
28 static int test_function(void)
33 static void sig_handler(int signum __maybe_unused
,
34 siginfo_t
*oh __maybe_unused
,
35 void *uc __maybe_unused
)
41 * This should be executed only once during
42 * this test, if we are here for the 10th
43 * time, consider this the recursive issue.
45 * We can get out of here by disable events,
46 * so no new SIGIO is delivered.
48 ioctl(fd1
, PERF_EVENT_IOC_DISABLE
, 0);
49 ioctl(fd2
, PERF_EVENT_IOC_DISABLE
, 0);
53 static int bp_event(void *fn
, int setup_signal
)
55 struct perf_event_attr pe
;
58 memset(&pe
, 0, sizeof(struct perf_event_attr
));
59 pe
.type
= PERF_TYPE_BREAKPOINT
;
60 pe
.size
= sizeof(struct perf_event_attr
);
63 pe
.bp_type
= HW_BREAKPOINT_X
;
64 pe
.bp_addr
= (unsigned long) fn
;
65 pe
.bp_len
= sizeof(long);
68 pe
.sample_type
= PERF_SAMPLE_IP
;
72 pe
.exclude_kernel
= 1;
75 fd
= sys_perf_event_open(&pe
, 0, -1, -1, 0);
77 pr_debug("failed opening event %llx\n", pe
.config
);
82 fcntl(fd
, F_SETFL
, O_RDWR
|O_NONBLOCK
|O_ASYNC
);
83 fcntl(fd
, F_SETSIG
, SIGIO
);
84 fcntl(fd
, F_SETOWN
, getpid());
87 ioctl(fd
, PERF_EVENT_IOC_RESET
, 0);
92 static long long bp_count(int fd
)
97 ret
= read(fd
, &count
, sizeof(long long));
98 if (ret
!= sizeof(long long)) {
99 pr_debug("failed to read: %d\n", ret
);
106 int test__bp_signal(void)
109 long long count1
, count2
;
111 /* setup SIGIO signal handler */
112 memset(&sa
, 0, sizeof(struct sigaction
));
113 sa
.sa_sigaction
= (void *) sig_handler
;
114 sa
.sa_flags
= SA_SIGINFO
;
116 if (sigaction(SIGIO
, &sa
, NULL
) < 0) {
117 pr_debug("failed setting up signal handler\n");
122 * We create following events:
124 * fd1 - breakpoint event on test_function with SIGIO
125 * signal configured. We should get signal
126 * notification each time the breakpoint is hit
128 * fd2 - breakpoint event on sig_handler without SIGIO
131 * Following processing should happen:
132 * - execute test_function
133 * - fd1 event breakpoint hit -> count1 == 1
134 * - SIGIO is delivered -> overflows == 1
135 * - fd2 event breakpoint hit -> count2 == 1
137 * The test case check following error conditions:
138 * - we get stuck in signal handler because of debug
139 * exception being triggered receursively due to
140 * the wrong RF EFLAG management
142 * - we never trigger the sig_handler breakpoint due
143 * to the rong RF EFLAG management
147 fd1
= bp_event(test_function
, 1);
148 fd2
= bp_event(sig_handler
, 0);
150 ioctl(fd1
, PERF_EVENT_IOC_ENABLE
, 0);
151 ioctl(fd2
, PERF_EVENT_IOC_ENABLE
, 0);
154 * Kick off the test by trigering 'fd1'
159 ioctl(fd1
, PERF_EVENT_IOC_DISABLE
, 0);
160 ioctl(fd2
, PERF_EVENT_IOC_DISABLE
, 0);
162 count1
= bp_count(fd1
);
163 count2
= bp_count(fd2
);
168 pr_debug("count1 %lld, count2 %lld, overflow %d\n",
169 count1
, count2
, overflows
);
173 pr_debug("failed: RF EFLAG recursion issue detected\n");
175 pr_debug("failed: wrong count for bp1%lld\n", count1
);
179 pr_debug("failed: wrong overflow hit\n");
182 pr_debug("failed: wrong count for bp2\n");
184 return count1
== 1 && overflows
== 1 && count2
== 1 ?