Skip to content

Commit 37e109c

Browse files
authored
[OpenMP] Support setting POSIX thread name on *BSD's and Solaris (#106489)
1 parent ec58817 commit 37e109c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

openmp/runtime/cmake/LibompDefinitions.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function(libomp_get_definitions_flags cppflags)
2323
else()
2424
libomp_append(cppflags_local "-D _GNU_SOURCE")
2525
libomp_append(cppflags_local "-D _REENTRANT")
26-
# or use HAVE_PTHREAD_SETNAME_NP from top-level cmake/config-ix.cmake
27-
libomp_append(cppflags_local "-D LIBOMP_HAVE_LINUX_PTHREAD_SETNAME" LIBOMP_HAVE_LINUX_PTHREAD_SETNAME)
26+
libomp_append(cppflags_local "-D LIBOMP_HAVE_PTHREAD_SETNAME_NP" LIBOMP_HAVE_PTHREAD_SETNAME_NP)
27+
libomp_append(cppflags_local "-D LIBOMP_HAVE_PTHREAD_SET_NAME_NP" LIBOMP_HAVE_PTHREAD_SET_NAME_NP)
2828
endif()
2929

3030
# CMake doesn't include CPPFLAGS from environment, but we will.

openmp/runtime/cmake/config-ix.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ if(${LIBOMP_FORTRAN_MODULES})
102102
endif()
103103

104104
# Check non-posix pthread API here before CMAKE_REQUIRED_DEFINITIONS gets messed up
105-
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
106-
check_symbol_exists(pthread_setname_np "pthread.h" LIBOMP_HAVE_LINUX_PTHREAD_SETNAME)
107-
endif()
105+
check_symbol_exists(pthread_setname_np "pthread.h" LIBOMP_HAVE_PTHREAD_SETNAME_NP)
106+
check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" LIBOMP_HAVE_PTHREAD_SET_NAME_NP)
108107

109108
# Check for Unix shared memory
110109
check_symbol_exists(shm_open "sys/mman.h" LIBOMP_HAVE_SHM_OPEN_NO_LRT)

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
#if KMP_OS_NETBSD
7272
#include <sched.h>
7373
#endif
74+
#if KMP_OS_OPENBSD
75+
#include <pthread_np.h>
76+
#endif
7477
#elif KMP_OS_SOLARIS
7578
#include <libproc.h>
7679
#include <procfs.h>
@@ -878,12 +881,18 @@ void __kmp_create_worker(int gtid, kmp_info_t *th, size_t stack_size) {
878881
KMP_SYSFAIL("pthread_create", status);
879882
}
880883

881-
#ifdef LIBOMP_HAVE_LINUX_PTHREAD_SETNAME
882884
// Rename worker threads for improved debuggability
883885
if (!KMP_UBER_GTID(gtid)) {
886+
#if defined(LIBOMP_HAVE_PTHREAD_SET_NAME_NP)
887+
pthread_set_name_np(handle, "openmp_worker");
888+
#elif defined(LIBOMP_HAVE_PTHREAD_SETNAME_NP) && !KMP_OS_DARWIN
889+
#if KMP_OS_NETBSD
890+
pthread_setname_np(handle, "%s", const_cast<char *>("openmp_worker"));
891+
#else
884892
pthread_setname_np(handle, "openmp_worker");
885-
}
886893
#endif
894+
#endif
895+
}
887896

888897
th->th.th_info.ds.ds_thread = handle;
889898

0 commit comments

Comments
 (0)