diff options
author | Benjamin Gray <bgray@linux.ibm.com> | 2023-04-06 14:33:16 +1000 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2023-04-20 13:21:45 +1000 |
commit | 6ff4dc25483f3f49d1db48af28d4c485fc77bd21 (patch) | |
tree | 5ec89621d6a955f58ca9d88b33ef0cf001ddaaed /tools/testing/selftests/powerpc/utils.c | |
parent | c97b2fc6627e1c26a3a84633e135322918a1e592 (diff) |
selftests/powerpc: Allow bind_to_cpu() to automatically pick CPU
All current users of bind_to_cpu() don't care _which_ CPU they get, just
that they are bound to a single free one. So alter the interface to
1. Accept a BIND_CPU_ANY value that tells it to automatically
pick a CPU
2. Return the picked CPU
And convert all these users to bind_to_cpu(BIND_CPU_ANY).
Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230406043320.125138-4-bgray@linux.ibm.com
Diffstat (limited to 'tools/testing/selftests/powerpc/utils.c')
-rw-r--r-- | tools/testing/selftests/powerpc/utils.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/utils.c b/tools/testing/selftests/powerpc/utils.c index cdb996dba703..252fb4a95e90 100644 --- a/tools/testing/selftests/powerpc/utils.c +++ b/tools/testing/selftests/powerpc/utils.c @@ -455,13 +455,24 @@ done: int bind_to_cpu(int cpu) { cpu_set_t mask; + int err; + + if (cpu == BIND_CPU_ANY) { + cpu = pick_online_cpu(); + if (cpu < 0) + return cpu; + } printf("Binding to cpu %d\n", cpu); CPU_ZERO(&mask); CPU_SET(cpu, &mask); - return sched_setaffinity(0, sizeof(mask), &mask); + err = sched_setaffinity(0, sizeof(mask), &mask); + if (err) + return err; + + return cpu; } bool is_ppc64le(void) |