selftests/powerpc: ptrace/perf_hwbreak test fixes
cover selftests/powerpc: ptrace/perf_hwbreak test fixes
This series fixes two issues with the perf_hwbreak test:
- Test fails on systems with large number of cpus due to hitting the resource limit for maximum number of open file descriptors.
- Test fails on systems running with lower SMT levels since it assumes all cpus are online.
Fix those issues. The first patch is a small cleanup to aid subsequent fixes.
- Naveen
Naveen N. Rao (3):
selftests/powerpc: Move perror closer to its use selftests/powerpc: Bump up rlimit for perf-hwbreak test selftests/powerpc: Account for offline cpus in perf-hwbreak test
.../selftests/powerpc/ptrace/perf-hwbreak.c | 78 +++++++++++++------ 1 file changed, 56 insertions(+), 22 deletions(-)
base-commit: eb05539de71d4784705d3e502d951ac17fea05e3
Signature · 1 line
2.38.1
PATCH 1/3 selftests/powerpc: Move perror closer to its use
Right now, if perf_event_open() fails for the systemwide tests, error report is printed too late, sometimes after subsequent system calls. Move use of perror() to the main function, just after the syscall.
--- .../selftests/powerpc/ptrace/perf-hwbreak.c | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-)
tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c +5 -16
@@ -146,6 +146,7 @@ static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 lenfor (i =0 ; i < nprocs; i++) { fd[i] =perf_cpu_event_open (i, type, addr, len);if (fd[i] <0 ) { +perror ("perf_systemwide_event_open" );close_fds (fd, i);return fd[i]; }
@@ -543,15 +544,12 @@ static int test_syswide_multi_diff_addr(void)int ret; ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a)); -if (ret) { -perror ("perf_systemwide_event_open" ); +if (ret)exit (EXIT_FAILURE ); - } ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_RW , (__u64)&b, (__u64 )sizeof (b));if (ret) {close_fds (fd1, nprocs); -perror ("perf_systemwide_event_open" );exit (EXIT_FAILURE ); }
@@ -590,15 +588,12 @@ static int test_syswide_multi_same_addr(void)int ret; ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a)); -if (ret) { -perror ("perf_systemwide_event_open" ); +if (ret)exit (EXIT_FAILURE ); - } ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_RW , (__u64)&a, (__u64 )sizeof (a));if (ret) {close_fds (fd1, nprocs); -perror ("perf_systemwide_event_open" );exit (EXIT_FAILURE ); }
@@ -637,15 +632,12 @@ static int test_syswide_multi_diff_addr_ro_wo(void)int ret; ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_W , (__u64)&a, (__u64 )sizeof (a)); -if (ret) { -perror ("perf_systemwide_event_open" ); +if (ret)exit (EXIT_FAILURE ); - } ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_R , (__u64)&b, (__u64 )sizeof (b));if (ret) {close_fds (fd1, nprocs); -perror ("perf_systemwide_event_open" );exit (EXIT_FAILURE ); }
@@ -684,15 +676,12 @@ static int test_syswide_multi_same_addr_ro_wo(void)int ret; ret =perf_systemwide_event_open (fd1,HW_BREAKPOINT_W , (__u64)&a, (__u64 )sizeof (a)); -if (ret) { -perror ("perf_systemwide_event_open" ); +if (ret)exit (EXIT_FAILURE ); - } ret =perf_systemwide_event_open (fd2,HW_BREAKPOINT_R , (__u64)&a, (__u64 )sizeof (a));if (ret) {close_fds (fd1, nprocs); -perror ("perf_systemwide_event_open" );exit (EXIT_FAILURE ); }
Signature · 1 line
2.38.1
PATCH 3/3 selftests/powerpc: Account for offline cpus in perf-hwbreak test
In reply to Naveen N. RaoFor systemwide tests, use online cpu mask to only open events on online cpus. This enables this test to work on systems in lower SMT modes.
--- .../selftests/powerpc/ptrace/perf-hwbreak.c | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-)
tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c +39 -6
@@ -17,8 +17,11 @@* Copyright (C) 2018 Michael Neuling, IBM Corporation. */ +#define _GNU_SOURCE +#include <unistd.h> #include <assert.h> +#include <sched.h> #include <stdio.h> #include <stdlib.h> #include <signal.h>
@@ -141,8 +144,10 @@ static void disable_fds(int *fd, int n)static int perf_systemwide_event_open (int *fd,__u32 type,__u64 addr,__u64 len) { +int i, ncpus, cpu, ret =0 ;struct rlimit rlim; -int i =0 ; +cpu_set_t *mask; +size_t size;if (getrlimit (RLIMIT_NOFILE , &rlim)) {perror ("getrlimit" );
@@ -154,16 +159,44 @@ static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 lenreturn -1 ; } -/* Assume online processors are 0 to nprocs for simplisity */ -for (i =0 ; i < nprocs; i++) { - fd[i] =perf_cpu_event_open (i, type, addr, len); + ncpus =get_nprocs_conf (); + size =CPU_ALLOC_SIZE (ncpus); + mask =CPU_ALLOC (ncpus); +if (!mask) { +perror ("malloc" ); +return -1 ; + } + +CPU_ZERO_S (size, mask); + +if (sched_getaffinity (0 , size, mask)) { +perror ("sched_getaffinity" ); + ret =-1 ; + goto done; + } + +for (i =0 , cpu =0 ; i < nprocs && cpu < ncpus; cpu++) { +if (!CPU_ISSET_S (cpu, size, mask)) +continue ; + fd[i] =perf_cpu_event_open (cpu, type, addr, len);if (fd[i] <0 ) {perror ("perf_systemwide_event_open" );close_fds (fd, i); -return fd[i]; + ret = fd[i]; + goto done; } + i++; } -return 0 ; + +if (i < nprocs) { +printf ("Error: Number of online cpus reduced since start of test: %d < %d\n" , i, nprocs); +close_fds (fd, i); + ret =-1 ; + } + +done: +CPU_FREE (mask); +return ret; }static inline bool breakpoint_test (int len)
Signature · 1 line
2.38.1
PATCH 2/3 selftests/powerpc: Bump up rlimit for perf-hwbreak test
In reply to Naveen N. RaoThe systemwide perf hardware breakpoint test tries to open a perf event on each cpu. On large systems, we run out of file descriptors and fail the test. Instead, have the test set the file descriptor limit to an arbitraty high value.
--- .../testing/selftests/powerpc/ptrace/perf-hwbreak.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c +12 -0
@@ -26,6 +26,7 @@#include <sys/ioctl.h> #include <sys/wait.h> #include <sys/ptrace.h> +#include <sys/resource.h> #include <sys/sysinfo.h> #include <asm/ptrace.h> #include <elf.h>
@@ -140,8 +141,19 @@ static void disable_fds(int *fd, int n)static int perf_systemwide_event_open (int *fd,__u32 type,__u64 addr,__u64 len) { +struct rlimit rlim;int i =0 ; +if (getrlimit (RLIMIT_NOFILE , &rlim)) { +perror ("getrlimit" ); +return -1 ; + } + rlim.rlim_cur =65536 ; +if (setrlimit (RLIMIT_NOFILE , &rlim)) { +perror ("setrlimit" ); +return -1 ; + } +/* Assume online processors are 0 to nprocs for simplisity */ for (i =0 ; i < nprocs; i++) { fd[i] =perf_cpu_event_open (i, type, addr, len);
Signature · 1 line
2.38.1
Re: [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test
Hi,
I have verified and tested this patch. No issues found. Changes look good.
Michael Ellerman
AppliedQuoted 10 lines · Naveen N. Rao
This series fixes two issues with the
perf_hwbreaktest:
- Test fails on systems with large number of cpus due to hitting the resource limit for maximum number of open file descriptors.
- Test fails on systems running with lower SMT levels since it assumes all cpus are online.Fix those issues. The first patch is a small cleanup to aid subsequent fixes.
[...]
Applied to powerpc/next.
[1/3] selftests/powerpc: Move perror closer to its use
https://git.kernel.org/powerpc/c/71ae6305ad41cfd1ac5aa91d356e71c7a537df2e [2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test https://git.kernel.org/powerpc/c/616ad3f4aac287c48b66c92cb777395b4465ed4f [3/3] selftests/powerpc: Account for offline cpus in perf-hwbreak test https://git.kernel.org/powerpc/c/260095926d3956071c6699a28824c3f0fa7cd97a
cheers