diff options
author | David Carlier <devnexen@gmail.com> | 2019-10-08 21:25:30 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2019-10-08 21:25:30 +0000 |
commit | cb6f3c46a841e47718564ca40f49af8bcfc57c3a (patch) | |
tree | 5b7d1c38316e0ff0b44ab49d4d5c9c22c0f1474d /runtime/src/kmp_affinity.h | |
parent | ace8505db1e11227e9007a2ac55ffaeccf88a65c (diff) |
[OpenMP] Enable thread affinity on FreeBSD
Reviewers: chandlerc, jlpeyton, jdoerfert, dim
Reviewed-By: dim
Differential Revision: https://reviews.llvm.org/D68580
git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@374118 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime/src/kmp_affinity.h')
-rw-r--r-- | runtime/src/kmp_affinity.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/runtime/src/kmp_affinity.h b/runtime/src/kmp_affinity.h index c00ad36..f270bb6 100644 --- a/runtime/src/kmp_affinity.h +++ b/runtime/src/kmp_affinity.h @@ -160,6 +160,7 @@ public: }; #endif /* KMP_USE_HWLOC */ +#if KMP_OS_LINUX || KMP_OS_FREEBSD #if KMP_OS_LINUX /* On some of the older OS's that we build on, these constants aren't present in <asm/unistd.h> #included from <sys.syscall.h>. They must be the same on @@ -234,6 +235,10 @@ public: #endif /* __NR_sched_getaffinity */ #error Unknown or unsupported architecture #endif /* KMP_ARCH_* */ +#elif KMP_OS_FREEBSD +#include <pthread.h> +#include <pthread_np.h> +#endif class KMPNativeAffinity : public KMPAffinity { class Mask : public KMPAffinity::Mask { typedef unsigned char mask_t; @@ -294,8 +299,13 @@ class KMPNativeAffinity : public KMPAffinity { int get_system_affinity(bool abort_on_error) override { KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal get affinity operation when not capable"); +#if KMP_OS_LINUX int retval = syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask); +#elif KMP_OS_FREEBSD + int retval = + pthread_getaffinity_np(pthread_self(), __kmp_affin_mask_size, reinterpret_cast<cpuset_t *>(mask)); +#endif if (retval >= 0) { return 0; } @@ -308,8 +318,13 @@ class KMPNativeAffinity : public KMPAffinity { int set_system_affinity(bool abort_on_error) const override { KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal get affinity operation when not capable"); +#if KMP_OS_LINUX int retval = syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask); +#elif KMP_OS_FREEBSD + int retval = + pthread_setaffinity_np(pthread_self(), __kmp_affin_mask_size, reinterpret_cast<cpuset_t *>(mask)); +#endif if (retval >= 0) { return 0; } @@ -347,7 +362,7 @@ class KMPNativeAffinity : public KMPAffinity { } api_type get_api_type() const override { return NATIVE_OS; } }; -#endif /* KMP_OS_LINUX */ +#endif /* KMP_OS_LINUX || KMP_OS_FREEBSD */ #if KMP_OS_WINDOWS class KMPNativeAffinity : public KMPAffinity { |