diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2015-12-16 02:59:31 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-12-16 18:46:41 -0500 |
commit | d1301afd71bd38b1610b391e50debf766faa84be (patch) | |
tree | ec86ca9e28aa61b7bd145538fe6e1230a0cd63d3 | |
parent | 00b912b0c88e690b1662067497182454357b18b0 (diff) |
selftests/powerpc: Move pick_online_cpu() up into utils.c
We want to use this in another test, so make it available at the top of
the powerpc selftests tree.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | tools/testing/selftests/powerpc/pmu/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/pmu/lib.c | 26 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/pmu/lib.h | 1 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/utils.c | 29 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/utils.h | 1 |
5 files changed, 31 insertions, 28 deletions
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile index 50326cbb372d..ac41a7177f2e 100644 --- a/tools/testing/selftests/powerpc/pmu/Makefile +++ b/tools/testing/selftests/powerpc/pmu/Makefile | |||
@@ -2,7 +2,7 @@ noarg: | |||
2 | $(MAKE) -C ../ | 2 | $(MAKE) -C ../ |
3 | 3 | ||
4 | TEST_PROGS := count_instructions l3_bank_test per_event_excludes | 4 | TEST_PROGS := count_instructions l3_bank_test per_event_excludes |
5 | EXTRA_SOURCES := ../harness.c event.c lib.c | 5 | EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c |
6 | 6 | ||
7 | all: $(TEST_PROGS) ebb | 7 | all: $(TEST_PROGS) ebb |
8 | 8 | ||
diff --git a/tools/testing/selftests/powerpc/pmu/lib.c b/tools/testing/selftests/powerpc/pmu/lib.c index a07104c2afe6..a361ad3334ce 100644 --- a/tools/testing/selftests/powerpc/pmu/lib.c +++ b/tools/testing/selftests/powerpc/pmu/lib.c | |||
@@ -15,32 +15,6 @@ | |||
15 | #include "lib.h" | 15 | #include "lib.h" |
16 | 16 | ||
17 | 17 | ||
18 | int pick_online_cpu(void) | ||
19 | { | ||
20 | cpu_set_t mask; | ||
21 | int cpu; | ||
22 | |||
23 | CPU_ZERO(&mask); | ||
24 | |||
25 | if (sched_getaffinity(0, sizeof(mask), &mask)) { | ||
26 | perror("sched_getaffinity"); | ||
27 | return -1; | ||
28 | } | ||
29 | |||
30 | /* We prefer a primary thread, but skip 0 */ | ||
31 | for (cpu = 8; cpu < CPU_SETSIZE; cpu += 8) | ||
32 | if (CPU_ISSET(cpu, &mask)) | ||
33 | return cpu; | ||
34 | |||
35 | /* Search for anything, but in reverse */ | ||
36 | for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--) | ||
37 | if (CPU_ISSET(cpu, &mask)) | ||
38 | return cpu; | ||
39 | |||
40 | printf("No cpus in affinity mask?!\n"); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | int bind_to_cpu(int cpu) | 18 | int bind_to_cpu(int cpu) |
45 | { | 19 | { |
46 | cpu_set_t mask; | 20 | cpu_set_t mask; |
diff --git a/tools/testing/selftests/powerpc/pmu/lib.h b/tools/testing/selftests/powerpc/pmu/lib.h index ca5d72ae3be6..0213af4ff332 100644 --- a/tools/testing/selftests/powerpc/pmu/lib.h +++ b/tools/testing/selftests/powerpc/pmu/lib.h | |||
@@ -19,7 +19,6 @@ union pipe { | |||
19 | int fds[2]; | 19 | int fds[2]; |
20 | }; | 20 | }; |
21 | 21 | ||
22 | extern int pick_online_cpu(void); | ||
23 | extern int bind_to_cpu(int cpu); | 22 | extern int bind_to_cpu(int cpu); |
24 | extern int kill_child_and_wait(pid_t child_pid); | 23 | extern int kill_child_and_wait(pid_t child_pid); |
25 | extern int wait_for_child(pid_t child_pid); | 24 | extern int wait_for_child(pid_t child_pid); |
diff --git a/tools/testing/selftests/powerpc/utils.c b/tools/testing/selftests/powerpc/utils.c index 536113add380..dcf74184bfd0 100644 --- a/tools/testing/selftests/powerpc/utils.c +++ b/tools/testing/selftests/powerpc/utils.c | |||
@@ -3,10 +3,13 @@ | |||
3 | * Licensed under GPLv2. | 3 | * Licensed under GPLv2. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #define _GNU_SOURCE /* For CPU_ZERO etc. */ | ||
7 | |||
6 | #include <elf.h> | 8 | #include <elf.h> |
7 | #include <errno.h> | 9 | #include <errno.h> |
8 | #include <fcntl.h> | 10 | #include <fcntl.h> |
9 | #include <link.h> | 11 | #include <link.h> |
12 | #include <sched.h> | ||
10 | #include <stdio.h> | 13 | #include <stdio.h> |
11 | #include <sys/stat.h> | 14 | #include <sys/stat.h> |
12 | #include <sys/types.h> | 15 | #include <sys/types.h> |
@@ -56,3 +59,29 @@ out: | |||
56 | close(fd); | 59 | close(fd); |
57 | return result; | 60 | return result; |
58 | } | 61 | } |
62 | |||
63 | int pick_online_cpu(void) | ||
64 | { | ||
65 | cpu_set_t mask; | ||
66 | int cpu; | ||
67 | |||
68 | CPU_ZERO(&mask); | ||
69 | |||
70 | if (sched_getaffinity(0, sizeof(mask), &mask)) { | ||
71 | perror("sched_getaffinity"); | ||
72 | return -1; | ||
73 | } | ||
74 | |||
75 | /* We prefer a primary thread, but skip 0 */ | ||
76 | for (cpu = 8; cpu < CPU_SETSIZE; cpu += 8) | ||
77 | if (CPU_ISSET(cpu, &mask)) | ||
78 | return cpu; | ||
79 | |||
80 | /* Search for anything, but in reverse */ | ||
81 | for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--) | ||
82 | if (CPU_ISSET(cpu, &mask)) | ||
83 | return cpu; | ||
84 | |||
85 | printf("No cpus in affinity mask?!\n"); | ||
86 | return -1; | ||
87 | } | ||
diff --git a/tools/testing/selftests/powerpc/utils.h b/tools/testing/selftests/powerpc/utils.h index fbf2bf530e50..175ac6ad10dd 100644 --- a/tools/testing/selftests/powerpc/utils.h +++ b/tools/testing/selftests/powerpc/utils.h | |||
@@ -22,6 +22,7 @@ typedef uint8_t u8; | |||
22 | 22 | ||
23 | int test_harness(int (test_function)(void), char *name); | 23 | int test_harness(int (test_function)(void), char *name); |
24 | extern void *get_auxv_entry(int type); | 24 | extern void *get_auxv_entry(int type); |
25 | int pick_online_cpu(void); | ||
25 | 26 | ||
26 | static inline bool have_hwcap2(unsigned long ftr2) | 27 | static inline bool have_hwcap2(unsigned long ftr2) |
27 | { | 28 | { |