Commit 9823ae6f authored by Kajol Jain's avatar Kajol Jain Committed by Arnaldo Carvalho de Melo

perf bench breakpoint: Skip run if no breakpoints available

Based on commit 7d54a4ac ("perf test: Skip watchpoint tests if
no watchpoints available"), hardware breakpoints are not available for
power9 platform and because of that 'perf bench breakpoint' run fails on
power9 platform.

Add code to check for the return value of perf_event_open() in the
breakpoint run and skip the 'perf bench breakpoint' run, if hardware
breakpoints are not available.

Result on power9 system before patch changes:

  [command]# perf bench breakpoint thread
  perf_event_open: No such device

Result on power9 system after patch changes:

  [command]# ./perf bench breakpoint thread
  Skipping perf bench breakpoint thread: No hardware support
Reported-by: default avatarDisha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
Acked-by: default avatarNaveen N Rao <naveen@kernel.org>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230823075103.190565-1-kjain@linux.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7a46404b
...@@ -47,6 +47,7 @@ struct breakpoint { ...@@ -47,6 +47,7 @@ struct breakpoint {
static int breakpoint_setup(void *addr) static int breakpoint_setup(void *addr)
{ {
struct perf_event_attr attr = { .size = 0, }; struct perf_event_attr attr = { .size = 0, };
int fd;
attr.type = PERF_TYPE_BREAKPOINT; attr.type = PERF_TYPE_BREAKPOINT;
attr.size = sizeof(attr); attr.size = sizeof(attr);
...@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr) ...@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
attr.bp_addr = (unsigned long)addr; attr.bp_addr = (unsigned long)addr;
attr.bp_type = HW_BREAKPOINT_RW; attr.bp_type = HW_BREAKPOINT_RW;
attr.bp_len = HW_BREAKPOINT_LEN_1; attr.bp_len = HW_BREAKPOINT_LEN_1;
return syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0); fd = syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0);
if (fd < 0)
fd = -errno;
return fd;
} }
static void *passive_thread(void *arg) static void *passive_thread(void *arg)
...@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv) ...@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
for (i = 0; i < thread_params.nbreakpoints; i++) { for (i = 0; i < thread_params.nbreakpoints; i++) {
breakpoints[i].fd = breakpoint_setup(&breakpoints[i].watched); breakpoints[i].fd = breakpoint_setup(&breakpoints[i].watched);
if (breakpoints[i].fd == -1)
if (breakpoints[i].fd < 0) {
if (breakpoints[i].fd == -ENODEV) {
printf("Skipping perf bench breakpoint thread: No hardware support\n");
return 0;
}
exit((perror("perf_event_open"), EXIT_FAILURE)); exit((perror("perf_event_open"), EXIT_FAILURE));
}
} }
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (i = 0; i < thread_params.nparallel; i++) { for (i = 0; i < thread_params.nparallel; i++) {
...@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv) ...@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fd = breakpoint_setup(&watched); fd = breakpoint_setup(&watched);
if (fd == -1)
if (fd < 0) {
if (fd == -ENODEV) {
printf("Skipping perf bench breakpoint enable: No hardware support\n");
return 0;
}
exit((perror("perf_event_open"), EXIT_FAILURE)); exit((perror("perf_event_open"), EXIT_FAILURE));
}
nthreads = enable_params.npassive + enable_params.nactive; nthreads = enable_params.npassive + enable_params.nactive;
threads = calloc(nthreads, sizeof(threads[0])); threads = calloc(nthreads, sizeof(threads[0]));
if (!threads) if (!threads)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment