commit ea99c09963488130ec0a61ef39df3fd0fcecad3c Author: David Carlier Date: Mon Jan 20 18:52:10 2020 +0000 [OpenMP] affinity little fix for FreeBSD - pthread affinity np has different semantic than sched affinity counterpart. On success returns strictly 0. Reviewers: chandlerc, AndreyChurbanov, jdoerfert Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D72132 diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h index f270bb6dbb8..664a4239319 100644 --- projects/openmp/runtime/src/kmp_affinity.h +++ projects/openmp/runtime/src/kmp_affinity.h @@ -303,8 +303,9 @@ class KMPNativeAffinity : public KMPAffinity { int retval = syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask); #elif KMP_OS_FREEBSD - int retval = + int r = pthread_getaffinity_np(pthread_self(), __kmp_affin_mask_size, reinterpret_cast(mask)); + int retval = (r == 0 ? 0 : -1); #endif if (retval >= 0) { return 0; @@ -322,8 +323,9 @@ class KMPNativeAffinity : public KMPAffinity { int retval = syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask); #elif KMP_OS_FREEBSD - int retval = + int r = pthread_setaffinity_np(pthread_self(), __kmp_affin_mask_size, reinterpret_cast(mask)); + int retval = (r == 0 ? 0 : -1); #endif if (retval >= 0) { return 0; diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp index 1daa3d31047..5e2d1bd4a2f 100644 --- projects/openmp/runtime/src/z_Linux_util.cpp +++ projects/openmp/runtime/src/z_Linux_util.cpp @@ -164,7 +164,7 @@ void __kmp_affinity_determine_capable(const char *env_var) { if (gCode > 0) { // Linux* OS only // The optimal situation: the OS returns the size of the buffer it expects. // - // A verification of correct behavior is that Isetaffinity on a NULL + // A verification of correct behavior is that setaffinity on a NULL // buffer with the same size fails with errno set to EFAULT. sCode = syscall(__NR_sched_setaffinity, 0, gCode, NULL); KA_TRACE(30, ("__kmp_affinity_determine_capable: " @@ -286,7 +286,7 @@ void __kmp_affinity_determine_capable(const char *env_var) { if (gCode == 0) { KMP_AFFINITY_ENABLE(KMP_CPU_SET_SIZE_LIMIT); KA_TRACE(10, ("__kmp_affinity_determine_capable: " - "affinity supported (mask size %d)\n"< + "affinity supported (mask size %d)\n", (int)__kmp_affin_mask_size)); KMP_INTERNAL_FREE(buf); return;