Skip to contentSkip to conversation

perf test: Skip perf bench breakpoint run if no breakpoints available

PATCH Applied Kajol Jain 5 participants 5 messages Aug 23, 2023 – Aug 29, 2023 perf events

lore
Share & tools
lore

Kajol Jain

author
#0 lore raw

PATCH 1/1 perf test: Skip perf bench breakpoint run if no breakpoints available

Based on commit 7d54a4acd8c1 ("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 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

---
 tools/perf/bench/breakpoint.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
tools/perf/bench/breakpoint.c +21 -3
index 41385f89ffc7..dfd18f5db97d 100644
@@ -47,6 +47,7 @@ struct breakpoint {
 static int breakpoint_setup(void *addr)
 {
 	struct perf_event_attr attr = { .size = 0, };
+	int fd;
 
 	attr.type = PERF_TYPE_BREAKPOINT;
 	attr.size = sizeof(attr);
@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
 	attr.bp_addr = (unsigned long)addr;
 	attr.bp_type = HW_BREAKPOINT_RW;
 	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)
@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
 
 	for (i = 0; i < thread_params.nbreakpoints; i++) {
 		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));
+		}
 	}
 	gettimeofday(&start, NULL);
 	for (i = 0; i < thread_params.nparallel; i++) {
@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
 		exit(EXIT_FAILURE);
 	}
 	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));
+	}
 	nthreads = enable_params.npassive + enable_params.nactive;
 	threads = calloc(nthreads, sizeof(threads[0]));
 	if (!threads)
Signature · 1 line
2.39.3
Acked-by on v1 1/1
#1 lore raw

Hi Kajol,

Quoted 16 lines · Kajol Jain

Based on commit 7d54a4acd8c1 ("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 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

Quoted 5 lines
---
 tools/perf/bench/breakpoint.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Thanks for fixing this to not report an error. A minor nit below, but otherwise:

Quoted 28 lines
tools/perf/bench/breakpoint.c +7 -1
index 41385f89ffc7..dfd18f5db97d 100644
@@ -47,6 +47,7 @@ struct breakpoint {
 static int breakpoint_setup(void *addr)
 {
 	struct perf_event_attr attr = { .size = 0, };
+	int fd;
 
 	attr.type = PERF_TYPE_BREAKPOINT;
 	attr.size = sizeof(attr);
@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
 	attr.bp_addr = (unsigned long)addr;
 	attr.bp_type = HW_BREAKPOINT_RW;
 	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)

tools/perf/bench/breakpoint.c int bench_breakpoint_thread(int argc, const char **argv) · line 135

Quoted 9 lines
tools/perf/bench/breakpoint.c +5 -1
@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
 
 	for (i = 0; i < thread_params.nbreakpoints; i++) {
 		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;

Should we instead do 'exit(0)' here to stop further benchmarks? Perhaps:
err(EXIT_SUCCESS, "Skipping perf bench breakpoint thread: No hardware support");

EXIT_SUCCESS looks weird, but should help document that this is not an error.

Quoted 7 lines
tools/perf/bench/breakpoint.c +2 -0
+			}
 			exit((perror("perf_event_open"), EXIT_FAILURE));
+		}
 	}
 	gettimeofday(&start, NULL);
 	for (i = 0; i < thread_params.nparallel; i++) {

tools/perf/bench/breakpoint.c int bench_breakpoint_enable(int argc, const char **argv) · line 215

Quoted 9 lines
tools/perf/bench/breakpoint.c +5 -1
@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
 		exit(EXIT_FAILURE);
 	}
 	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;

Here too.

- Naveen

Quoted 6 lines
tools/perf/bench/breakpoint.c +2 -0
+		}
 		exit((perror("perf_event_open"), EXIT_FAILURE));
+	}
 	nthreads = enable_params.npassive + enable_params.nactive;
 	threads = calloc(nthreads, sizeof(threads[0]));
 	if (!threads)
reviewer
#2 lore raw
Quoted 71 lines · Naveen N Rao

Hi Kajol,

Quoted 16 lines · Kajol Jain

Based on commit 7d54a4acd8c1 ("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 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

Quoted 5 lines
---
 tools/perf/bench/breakpoint.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Thanks for fixing this to not report an error. A minor nit below, but otherwise:

Quoted 28 lines
tools/perf/bench/breakpoint.c +7 -1
index 41385f89ffc7..dfd18f5db97d 100644
@@ -47,6 +47,7 @@ struct breakpoint {
 static int breakpoint_setup(void *addr)
 {
      struct perf_event_attr attr = { .size = 0, };
+     int fd;
 
      attr.type = PERF_TYPE_BREAKPOINT;
      attr.size = sizeof(attr);
@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
      attr.bp_addr = (unsigned long)addr;
      attr.bp_type = HW_BREAKPOINT_RW;
      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)

tools/perf/bench/breakpoint.c int bench_breakpoint_thread(int argc, const char **argv) · line 135

Quoted 9 lines
tools/perf/bench/breakpoint.c +5 -1
@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
 
      for (i = 0; i < thread_params.nbreakpoints; i++) {
              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;

Should we instead do 'exit(0)' here to stop further benchmarks? Perhaps:
err(EXIT_SUCCESS, "Skipping perf bench breakpoint thread: No hardware support");

Quoted 2 lines

EXIT_SUCCESS looks weird, but should help document that this is not an error.

In tools/perf/tests/tests.h is:

enum {
       TEST_OK   =  0,
       TEST_FAIL = -1,
       TEST_SKIP = -2,
};

So I think the EXIT_SUCCESS/0 should really be TEST_OK, but I think it would clearer if these cases were TEST_SKIP.

Thanks,
Ian

Quoted 28 lines
Quoted 7 lines
tools/perf/bench/breakpoint.c +2 -0
+                     }
                      exit((perror("perf_event_open"), EXIT_FAILURE));
+             }
      }
      gettimeofday(&start, NULL);
      for (i = 0; i < thread_params.nparallel; i++) {

tools/perf/bench/breakpoint.c int bench_breakpoint_enable(int argc, const char **argv) · line 215

Quoted 9 lines
tools/perf/bench/breakpoint.c +5 -1
@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
              exit(EXIT_FAILURE);
      }
      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;

Here too.

- Naveen

Quoted 6 lines
tools/perf/bench/breakpoint.c +2 -0
+             }
              exit((perror("perf_event_open"), EXIT_FAILURE));
+     }
      nthreads = enable_params.npassive + enable_params.nactive;
      threads = calloc(nthreads, sizeof(threads[0]));
      if (!threads)
maintainer Applied
#3 lore raw
In reply to Kajol Jain

Em Wed, Aug 23, 2023 at 01:21:03PM +0530, Kajol Jain escreveu:

Quoted 12 lines

Based on commit 7d54a4acd8c1 ("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 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

Quoted 6 lines

Result on power9 system after patch changes:
[command]# ./perf bench breakpoint thread Skipping perf bench breakpoint thread: No hardware support

Thanks, applied.

- Arnaldo

Quoted 65 lines
---
 tools/perf/bench/breakpoint.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
tools/perf/bench/breakpoint.c +21 -3
index 41385f89ffc7..dfd18f5db97d 100644
@@ -47,6 +47,7 @@ struct breakpoint {
 static int breakpoint_setup(void *addr)
 {
 	struct perf_event_attr attr = { .size = 0, };
+	int fd;
 
 	attr.type = PERF_TYPE_BREAKPOINT;
 	attr.size = sizeof(attr);
@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
 	attr.bp_addr = (unsigned long)addr;
 	attr.bp_type = HW_BREAKPOINT_RW;
 	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)
@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
 
 	for (i = 0; i < thread_params.nbreakpoints; i++) {
 		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));
+		}
 	}
 	gettimeofday(&start, NULL);
 	for (i = 0; i < thread_params.nparallel; i++) {
@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
 		exit(EXIT_FAILURE);
 	}
 	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));
+	}
 	nthreads = enable_params.npassive + enable_params.nactive;
 	threads = calloc(nthreads, sizeof(threads[0]));
 	if (!threads)
Signature · 1 line
2.39.3
Signature · 1 line
- Arnaldo
Tested-by on v1 1/1
#4 lore raw
In reply to Kajol Jain
Quoted 12 lines · Kajol Jain

Based on commit 7d54a4acd8c1 ("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 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

Quoted 6 lines

Result on power9 system after patch changes:
[command]# ./perf bench breakpoint thread Skipping perf bench breakpoint thread: No hardware support

With this patch applied perf bench breakpoint test works correctly on Power9 and Power10.

Result on Power9 system with patch changes:

[root@]# ./perf bench breakpoint all
# Running breakpoint/thread benchmark...
Skipping perf bench breakpoint thread: No hardware support

# Running breakpoint/enable benchmark...
Skipping perf bench breakpoint enable: No hardware support

Result on Power10 system with patch changes:

[root@]# ./perf bench breakpoint all
# Running breakpoint/thread benchmark...
# Created/joined 10 threads with 1 breakpoints and 1 parallelism
     Total time: 0.001 [sec]
     115.100000 usecs/op
     115.100000 usecs/op/cpu

# Running breakpoint/enable benchmark...
# Enabled/disabled breakpoint 10 time with 0 passive and 0 active threads

     Total time: 0.000 [sec]

       2.800000 usecs/op
Quoted 62 lines
---
  tools/perf/bench/breakpoint.c | 24 +++++++++++++++++++++---
  1 file changed, 21 insertions(+), 3 deletions(-)
tools/perf/bench/breakpoint.c +21 -3
index 41385f89ffc7..dfd18f5db97d 100644
@@ -47,6 +47,7 @@ struct breakpoint {
  static int breakpoint_setup(void *addr)
  {
  	struct perf_event_attr attr = { .size = 0, };
+	int fd;
 
  	attr.type = PERF_TYPE_BREAKPOINT;
  	attr.size = sizeof(attr);
@@ -56,7 +57,12 @@ static int breakpoint_setup(void *addr)
  	attr.bp_addr = (unsigned long)addr;
  	attr.bp_type = HW_BREAKPOINT_RW;
  	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)
@@ -122,8 +128,14 @@ int bench_breakpoint_thread(int argc, const char **argv)
 
  	for (i = 0; i < thread_params.nbreakpoints; i++) {
  		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));
+		}
  	}
  	gettimeofday(&start, NULL);
  	for (i = 0; i < thread_params.nparallel; i++) {
@@ -196,8 +208,14 @@ int bench_breakpoint_enable(int argc, const char **argv)
  		exit(EXIT_FAILURE);
  	}
  	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));
+	}
  	nthreads = enable_params.npassive + enable_params.nactive;
  	threads = calloc(nthreads, sizeof(threads[0]));
  	if (!threads)