Commit 26009592 authored by Naveen N. Rao's avatar Naveen N. Rao Committed by Michael Ellerman

selftests/powerpc: Account for offline cpus in perf-hwbreak test

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: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/15fd447dcefd19945a7d31f0a475349f548a3603.1669096083.git.naveen.n.rao@linux.vnet.ibm.com
parent 616ad3f4
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
* Copyright (C) 2018 Michael Neuling, IBM Corporation. * Copyright (C) 2018 Michael Neuling, IBM Corporation.
*/ */
#define _GNU_SOURCE
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <sched.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
...@@ -141,8 +144,10 @@ static void disable_fds(int *fd, int n) ...@@ -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) static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 len)
{ {
int i, ncpus, cpu, ret = 0;
struct rlimit rlim; struct rlimit rlim;
int i = 0; cpu_set_t *mask;
size_t size;
if (getrlimit(RLIMIT_NOFILE, &rlim)) { if (getrlimit(RLIMIT_NOFILE, &rlim)) {
perror("getrlimit"); perror("getrlimit");
...@@ -154,16 +159,44 @@ static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 len ...@@ -154,16 +159,44 @@ static int perf_systemwide_event_open(int *fd, __u32 type, __u64 addr, __u64 len
return -1; return -1;
} }
/* Assume online processors are 0 to nprocs for simplisity */ ncpus = get_nprocs_conf();
for (i = 0; i < nprocs; i++) { size = CPU_ALLOC_SIZE(ncpus);
fd[i] = perf_cpu_event_open(i, type, addr, len); 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) { if (fd[i] < 0) {
perror("perf_systemwide_event_open"); perror("perf_systemwide_event_open");
close_fds(fd, i); 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) static inline bool breakpoint_test(int len)
......
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