Skip to content

Commit

Permalink
[OpenMP] affinity little fix for FreeBSD
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
devnexen committed Jan 20, 2020
1 parent a17ad35 commit ea99c09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions openmp/runtime/src/kmp_affinity.h
Expand Up @@ -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<cpuset_t *>(mask));
int retval = (r == 0 ? 0 : -1);
#endif
if (retval >= 0) {
return 0;
Expand All @@ -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<cpuset_t *>(mask));
int retval = (r == 0 ? 0 : -1);
#endif
if (retval >= 0) {
return 0;
Expand Down
4 changes: 2 additions & 2 deletions openmp/runtime/src/z_Linux_util.cpp
Expand Up @@ -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: "
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ea99c09

Please sign in to comment.