5 #define __SANE_USERSPACE_TYPES__ 11 #include <sys/ioctl.h> 16 #include <linux/compiler.h> 17 #include <linux/hw_breakpoint.h> 18 #include <sys/ioctl.h> 32 static int __event(
bool is_x,
void *addr,
struct perf_event_attr *
attr)
36 memset(attr, 0,
sizeof(
struct perf_event_attr));
37 attr->type = PERF_TYPE_BREAKPOINT;
38 attr->size =
sizeof(
struct perf_event_attr);
41 attr->bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
42 attr->bp_addr = (
unsigned long) addr;
43 attr->bp_len =
sizeof(long);
45 attr->sample_period = 1;
46 attr->sample_type = PERF_SAMPLE_IP;
48 attr->exclude_kernel = 1;
54 pr_debug(
"failed opening event %llx\n", attr->config);
63 return __event(
false, addr, attr);
68 return __event(
true, addr, attr);
73 struct perf_event_attr attr, attr_mod, attr_new;
74 int i, fd[wp_cnt], fd_wp, ret;
76 for (i = 0; i < wp_cnt; i++) {
83 attr_mod.bp_type = HW_BREAKPOINT_X;
86 ret = ioctl(fd[0], PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &attr_mod);
97 for (i = 0; i < wp_cnt; i++)
105 struct perf_event_attr attr;
107 int fd[100], cnt = 0, i;
111 pr_debug(
"way too many debug registers, fix the test\n");
114 fd[cnt] =
__event(is_x, addr, &attr);
121 for (i = 0; i < cnt; i++)
129 struct perf_event_attr attr;
134 ret = ioctl(fd, PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &attr);
143 struct perf_event_attr attr;
144 int i, fd[wp_cnt + bp_cnt], ret;
146 for (i = 0; i < wp_cnt; i++) {
151 for (; i < (bp_cnt + wp_cnt); i++) {
157 ret = i != (bp_cnt + wp_cnt);
186 pr_debug(
"watchpoints count %d, breakpoints count %d, has_ioctl %d, share %d\n",
187 wp_cnt, bp_cnt, has_ioctl, share);
189 if (!wp_cnt || !bp_cnt || !has_ioctl)
#define TEST_ASSERT_VAL(text, cond)
static int sys_perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags)
static int detect_cnt(bool is_x)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
static int detect_ioctl(void)
#define pr_debug(fmt,...)
static noinline int test_function(void)
int test__bp_accounting(struct test *test __maybe_unused, int subtest __maybe_unused)
static int __event(bool is_x, void *addr, struct perf_event_attr *attr)
static int bp_accounting(int wp_cnt, int share)
static int bp_event(void *addr, struct perf_event_attr *attr)
static int wp_event(void *addr, struct perf_event_attr *attr)
unsigned long perf_event_open_cloexec_flag(void)
static int detect_share(int wp_cnt, int bp_cnt)