perf test: Fix build on older glibcs

Where we don't have CPU_ALLOC & friends. As the tools are being used in older
distros where the only allowed change are to replace the kernel, like RHEL4 and
5.
Reported-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 01bb2dc4
...@@ -332,8 +332,7 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -332,8 +332,7 @@ static int test__open_syscall_event_on_all_cpus(void)
struct perf_evsel *evsel; struct perf_evsel *evsel;
struct perf_event_attr attr; struct perf_event_attr attr;
unsigned int nr_open_calls = 111, i; unsigned int nr_open_calls = 111, i;
cpu_set_t *cpu_set; cpu_set_t cpu_set;
size_t cpu_set_size;
int id = trace_event__id("sys_enter_open"); int id = trace_event__id("sys_enter_open");
if (id < 0) { if (id < 0) {
...@@ -353,13 +352,8 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -353,13 +352,8 @@ static int test__open_syscall_event_on_all_cpus(void)
return -1; return -1;
} }
cpu_set = CPU_ALLOC(cpus->nr);
if (cpu_set == NULL) CPU_ZERO(&cpu_set);
goto out_thread_map_delete;
cpu_set_size = CPU_ALLOC_SIZE(cpus->nr);
CPU_ZERO_S(cpu_set_size, cpu_set);
memset(&attr, 0, sizeof(attr)); memset(&attr, 0, sizeof(attr));
attr.type = PERF_TYPE_TRACEPOINT; attr.type = PERF_TYPE_TRACEPOINT;
...@@ -367,7 +361,7 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -367,7 +361,7 @@ static int test__open_syscall_event_on_all_cpus(void)
evsel = perf_evsel__new(&attr, 0); evsel = perf_evsel__new(&attr, 0);
if (evsel == NULL) { if (evsel == NULL) {
pr_debug("perf_evsel__new\n"); pr_debug("perf_evsel__new\n");
goto out_cpu_free; goto out_thread_map_delete;
} }
if (perf_evsel__open(evsel, cpus, threads) < 0) { if (perf_evsel__open(evsel, cpus, threads) < 0) {
...@@ -379,9 +373,19 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -379,9 +373,19 @@ static int test__open_syscall_event_on_all_cpus(void)
for (cpu = 0; cpu < cpus->nr; ++cpu) { for (cpu = 0; cpu < cpus->nr; ++cpu) {
unsigned int ncalls = nr_open_calls + cpu; unsigned int ncalls = nr_open_calls + cpu;
/*
* XXX eventually lift this restriction in a way that
* keeps perf building on older glibc installations
* without CPU_ALLOC. 1024 cpus in 2010 still seems
* a reasonable upper limit tho :-)
*/
if (cpus->map[cpu] >= CPU_SETSIZE) {
pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
continue;
}
CPU_SET_S(cpus->map[cpu], cpu_set_size, cpu_set); CPU_SET(cpus->map[cpu], &cpu_set);
if (sched_setaffinity(0, cpu_set_size, cpu_set) < 0) { if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
pr_debug("sched_setaffinity() failed on CPU %d: %s ", pr_debug("sched_setaffinity() failed on CPU %d: %s ",
cpus->map[cpu], cpus->map[cpu],
strerror(errno)); strerror(errno));
...@@ -391,7 +395,7 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -391,7 +395,7 @@ static int test__open_syscall_event_on_all_cpus(void)
fd = open("/etc/passwd", O_RDONLY); fd = open("/etc/passwd", O_RDONLY);
close(fd); close(fd);
} }
CPU_CLR_S(cpus->map[cpu], cpu_set_size, cpu_set); CPU_CLR(cpus->map[cpu], &cpu_set);
} }
/* /*
...@@ -407,6 +411,9 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -407,6 +411,9 @@ static int test__open_syscall_event_on_all_cpus(void)
for (cpu = 0; cpu < cpus->nr; ++cpu) { for (cpu = 0; cpu < cpus->nr; ++cpu) {
unsigned int expected; unsigned int expected;
if (cpus->map[cpu] >= CPU_SETSIZE)
continue;
if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) { if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) {
pr_debug("perf_evsel__open_read_on_cpu\n"); pr_debug("perf_evsel__open_read_on_cpu\n");
goto out_close_fd; goto out_close_fd;
...@@ -425,8 +432,6 @@ static int test__open_syscall_event_on_all_cpus(void) ...@@ -425,8 +432,6 @@ static int test__open_syscall_event_on_all_cpus(void)
perf_evsel__close_fd(evsel, 1, threads->nr); perf_evsel__close_fd(evsel, 1, threads->nr);
out_evsel_delete: out_evsel_delete:
perf_evsel__delete(evsel); perf_evsel__delete(evsel);
out_cpu_free:
CPU_FREE(cpu_set);
out_thread_map_delete: out_thread_map_delete:
thread_map__delete(threads); thread_map__delete(threads);
return err; return err;
......
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