* [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes
@ 2022-11-22 6:40 Naveen N. Rao
2022-11-22 6:40 ` [PATCH 1/3] selftests/powerpc: Move perror closer to its use Naveen N. Rao
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Naveen N. Rao @ 2022-11-22 6:40 UTC (permalink / raw)
To: Michael Ellerman; +Cc: Rohan Deshpande, linuxppc-dev
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
--
2.38.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] selftests/powerpc: Move perror closer to its use
2022-11-22 6:40 [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Naveen N. Rao
@ 2022-11-22 6:40 ` Naveen N. Rao
2022-11-22 6:40 ` [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test Naveen N. Rao
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Naveen N. Rao @ 2022-11-22 6:40 UTC (permalink / raw)
To: Michael Ellerman; +Cc: Rohan Deshpande, linuxppc-dev
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.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
.../selftests/powerpc/ptrace/perf-hwbreak.c | 21 +++++--------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
index ecde2c199f3b18..ea5e14ecbf309f 100644
--- a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
+++ b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
@@ -146,6 +146,7 @@ static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 len
for (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);
}
--
2.38.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test
2022-11-22 6:40 [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Naveen N. Rao
2022-11-22 6:40 ` [PATCH 1/3] selftests/powerpc: Move perror closer to its use Naveen N. Rao
@ 2022-11-22 6:40 ` Naveen N. Rao
2022-12-01 14:24 ` Rohan Deshpande
2022-11-22 6:40 ` [PATCH 3/3] selftests/powerpc: Account for offline cpus in " Naveen N. Rao
2022-12-08 12:39 ` [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Michael Ellerman
3 siblings, 1 reply; 6+ messages in thread
From: Naveen N. Rao @ 2022-11-22 6:40 UTC (permalink / raw)
To: Michael Ellerman; +Cc: Rohan Deshpande, linuxppc-dev
The 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.
Reported-by: Rohan Deshpande <rohan_d@linux.vnet.ibm.com>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
.../testing/selftests/powerpc/ptrace/perf-hwbreak.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
index ea5e14ecbf309f..866e5be48ee33a 100644
--- a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
+++ b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] selftests/powerpc: Account for offline cpus in perf-hwbreak test
2022-11-22 6:40 [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Naveen N. Rao
2022-11-22 6:40 ` [PATCH 1/3] selftests/powerpc: Move perror closer to its use Naveen N. Rao
2022-11-22 6:40 ` [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test Naveen N. Rao
@ 2022-11-22 6:40 ` Naveen N. Rao
2022-12-08 12:39 ` [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Michael Ellerman
3 siblings, 0 replies; 6+ messages in thread
From: Naveen N. Rao @ 2022-11-22 6:40 UTC (permalink / raw)
To: Michael Ellerman; +Cc: Rohan Deshpande, linuxppc-dev
For 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.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
.../selftests/powerpc/ptrace/perf-hwbreak.c | 45 ++++++++++++++++---
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
index 866e5be48ee33a..f75739bbad28cd 100644
--- a/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
+++ b/tools/testing/selftests/powerpc/ptrace/perf-hwbreak.c
@@ -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 len
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);
+ 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)
--
2.38.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test
2022-11-22 6:40 ` [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test Naveen N. Rao
@ 2022-12-01 14:24 ` Rohan Deshpande
0 siblings, 0 replies; 6+ messages in thread
From: Rohan Deshpande @ 2022-12-01 14:24 UTC (permalink / raw)
To: Naveen N. Rao, Michael Ellerman; +Cc: Rohan Deshpande, linuxppc-dev
Hi,
I have verified and tested this patch. No issues found. Changes look good.
Tested-by: Rohan Deshpande <rohan_d@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes
2022-11-22 6:40 [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Naveen N. Rao
` (2 preceding siblings ...)
2022-11-22 6:40 ` [PATCH 3/3] selftests/powerpc: Account for offline cpus in " Naveen N. Rao
@ 2022-12-08 12:39 ` Michael Ellerman
3 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2022-12-08 12:39 UTC (permalink / raw)
To: Michael Ellerman, Naveen N. Rao; +Cc: Rohan Deshpande, linuxppc-dev
On Tue, 22 Nov 2022 12:10:51 +0530, Naveen N. Rao wrote:
> 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.
>
> [...]
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-08 12:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 6:40 [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Naveen N. Rao
2022-11-22 6:40 ` [PATCH 1/3] selftests/powerpc: Move perror closer to its use Naveen N. Rao
2022-11-22 6:40 ` [PATCH 2/3] selftests/powerpc: Bump up rlimit for perf-hwbreak test Naveen N. Rao
2022-12-01 14:24 ` Rohan Deshpande
2022-11-22 6:40 ` [PATCH 3/3] selftests/powerpc: Account for offline cpus in " Naveen N. Rao
2022-12-08 12:39 ` [PATCH 0/3] selftests/powerpc: ptrace/perf_hwbreak test fixes Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).