selftests/bpf: Output the correct error code for pthread APIs
authorHou Tao <houtao1@huawei.com>
Tue, 13 Jun 2023 08:09:18 +0000 (16:09 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 19 Jun 2023 20:26:43 +0000 (13:26 -0700)
The return value of pthread API is the error code when the called
API fails, so output the return value instead of errno.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20230613080921.1623219-3-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/bench.c

index d9c080a..0b5d2b5 100644 (file)
@@ -441,12 +441,14 @@ static void setup_timer()
 static void set_thread_affinity(pthread_t thread, int cpu)
 {
        cpu_set_t cpuset;
+       int err;
 
        CPU_ZERO(&cpuset);
        CPU_SET(cpu, &cpuset);
-       if (pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset)) {
+       err = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
+       if (err) {
                fprintf(stderr, "setting affinity to CPU #%d failed: %d\n",
-                       cpu, errno);
+                       cpu, -err);
                exit(1);
        }
 }
@@ -605,7 +607,7 @@ static void setup_benchmark(void)
                                     bench->consumer_thread, (void *)(long)i);
                if (err) {
                        fprintf(stderr, "failed to create consumer thread #%d: %d\n",
-                               i, -errno);
+                               i, -err);
                        exit(1);
                }
                if (env.affinity)
@@ -624,7 +626,7 @@ static void setup_benchmark(void)
                                     bench->producer_thread, (void *)(long)i);
                if (err) {
                        fprintf(stderr, "failed to create producer thread #%d: %d\n",
-                               i, -errno);
+                               i, -err);
                        exit(1);
                }
                if (env.affinity)