Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf bench breakpoint: Skip run if no breakpoints available

Based on commit 7d54a4acd8c1de3e ("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: Disha Goel <disgoel@linux.vnet.ibm.com>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Naveen 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kajol Jain and committed by
Arnaldo Carvalho de Melo
9823ae6f 7a46404b

+21 -3
+21 -3
tools/perf/bench/breakpoint.c
··· 47 47 static int breakpoint_setup(void *addr) 48 48 { 49 49 struct perf_event_attr attr = { .size = 0, }; 50 + int fd; 50 51 51 52 attr.type = PERF_TYPE_BREAKPOINT; 52 53 attr.size = sizeof(attr); ··· 57 56 attr.bp_addr = (unsigned long)addr; 58 57 attr.bp_type = HW_BREAKPOINT_RW; 59 58 attr.bp_len = HW_BREAKPOINT_LEN_1; 60 - return syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0); 59 + fd = syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0); 60 + 61 + if (fd < 0) 62 + fd = -errno; 63 + 64 + return fd; 61 65 } 62 66 63 67 static void *passive_thread(void *arg) ··· 128 122 129 123 for (i = 0; i < thread_params.nbreakpoints; i++) { 130 124 breakpoints[i].fd = breakpoint_setup(&breakpoints[i].watched); 131 - if (breakpoints[i].fd == -1) 125 + 126 + if (breakpoints[i].fd < 0) { 127 + if (breakpoints[i].fd == -ENODEV) { 128 + printf("Skipping perf bench breakpoint thread: No hardware support\n"); 129 + return 0; 130 + } 132 131 exit((perror("perf_event_open"), EXIT_FAILURE)); 132 + } 133 133 } 134 134 gettimeofday(&start, NULL); 135 135 for (i = 0; i < thread_params.nparallel; i++) { ··· 208 196 exit(EXIT_FAILURE); 209 197 } 210 198 fd = breakpoint_setup(&watched); 211 - if (fd == -1) 199 + 200 + if (fd < 0) { 201 + if (fd == -ENODEV) { 202 + printf("Skipping perf bench breakpoint enable: No hardware support\n"); 203 + return 0; 204 + } 212 205 exit((perror("perf_event_open"), EXIT_FAILURE)); 206 + } 213 207 nthreads = enable_params.npassive + enable_params.nactive; 214 208 threads = calloc(nthreads, sizeof(threads[0])); 215 209 if (!threads)