diff options
author | Cyril Bur <cyrilbur@gmail.com> | 2017-07-04 11:21:15 +1000 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2017-10-13 19:41:56 +1100 |
commit | 89aca4753eb451a48f65a12b02640365dba3d4ea (patch) | |
tree | 3804871858d88e3c99d3209a2cf59440549c9bde /tools/testing/selftests/powerpc/benchmarks/context_switch.c | |
parent | 8f6a90421c7637984fb352da079fb13172176bfd (diff) | |
download | linux-89aca4753eb451a48f65a12b02640365dba3d4ea.tar.bz2 |
selftests/powerpc: context_switch: Fix pthread errors
Turns out pthreads returns an errno and doesn't set errno. This doesn't
play well with perror().
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing/selftests/powerpc/benchmarks/context_switch.c')
-rw-r--r-- | tools/testing/selftests/powerpc/benchmarks/context_switch.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/testing/selftests/powerpc/benchmarks/context_switch.c b/tools/testing/selftests/powerpc/benchmarks/context_switch.c index f4241339edd2..87f1f0252299 100644 --- a/tools/testing/selftests/powerpc/benchmarks/context_switch.c +++ b/tools/testing/selftests/powerpc/benchmarks/context_switch.c @@ -10,6 +10,7 @@ */ #define _GNU_SOURCE +#include <errno.h> #include <sched.h> #include <string.h> #include <stdio.h> @@ -75,6 +76,7 @@ static void touch(void) static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu) { + int rc; pthread_t tid; cpu_set_t cpuset; pthread_attr_t attr; @@ -82,14 +84,23 @@ static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu) CPU_ZERO(&cpuset); CPU_SET(cpu, &cpuset); - pthread_attr_init(&attr); + rc = pthread_attr_init(&attr); + if (rc) { + errno = rc; + perror("pthread_attr_init"); + exit(1); + } - if (pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) { + rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset); + if (rc) { + errno = rc; perror("pthread_attr_setaffinity_np"); exit(1); } - if (pthread_create(&tid, &attr, fn, arg)) { + rc = pthread_create(&tid, &attr, fn, arg); + if (rc) { + errno = rc; perror("pthread_create"); exit(1); } |