-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[llvm][Support] Add support for thread naming under DragonFly BSD and Solaris/illumos #106944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-support Author: Brad Smith (brad0) ChangesFull diff: https://github.com/llvm/llvm-project/pull/106944.diff 3 Files Affected:
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index f76eacb9d51366..3707ca824f6e9c 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -356,6 +356,8 @@ if (NOT PURE_WINDOWS)
endif()
check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP)
check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
+ check_symbol_exists(pthread_get_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_GET_NAME_NP)
+ check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
if (LLVM_PTHREAD_LIB)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
endif()
diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake
index f39d2d56d61e89..d71ff40144c097 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -125,6 +125,12 @@
/* Define to 1 if you have the `pthread_setname_np' function. */
#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP}
+/* Define to 1 if you have the `pthread_get_name_np' function. */
+#cmakedefine HAVE_PTHREAD_GET_NAME_NP ${HAVE_PTHREAD_GET_NAME_NP}
+
+/* Define to 1 if you have the `pthread_set_name_np' function. */
+#cmakedefine HAVE_PTHREAD_SET_NAME_NP ${HAVE_PTHREAD_SET_NAME_NP}
+
/* Define to 1 if you have the <mach/mach.h> header file. */
#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 1812d990f21ac1..23d2c070afbbf6 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -137,13 +137,15 @@ uint64_t llvm::get_threadid() {
}
static constexpr uint32_t get_max_thread_name_length_impl() {
-#if defined(__NetBSD__)
+#if defined(PTHREAD_MAX_NAMELEN_NP)
return PTHREAD_MAX_NAMELEN_NP;
#elif defined(__APPLE__)
return 64;
+#elif defined(__sun__) && defined(__svr4__)
+ return 31;
#elif defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
return 16;
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
return 16;
#elif defined(__OpenBSD__)
return 32;
@@ -170,15 +172,17 @@ void llvm::set_thread_name(const Twine &Name) {
if (get_max_thread_name_length() > 0)
NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
(void)NameStr;
-#if defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
- ::pthread_setname_np(::pthread_self(), NameStr.data());
-#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(HAVE_PTHREAD_SET_NAME_NP)
::pthread_set_name_np(::pthread_self(), NameStr.data());
-#elif defined(__NetBSD__)
+#elif defined(HAVE_PTHREAD_SETNAME_NP)
+#if defined(__NetBSD__)
::pthread_setname_np(::pthread_self(), "%s",
const_cast<char *>(NameStr.data()));
#elif defined(__APPLE__)
::pthread_setname_np(NameStr.data());
+#else
+ ::pthread_setname_np(::pthread_self(), NameStr.data());
+#endif
#endif
}
@@ -221,23 +225,24 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
}
free(kp);
return;
-#elif defined(__NetBSD__)
+#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
+ constexpr uint32_t len = get_max_thread_name_length_impl();
+ char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
+ if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
+ Name.append(Buffer, Buffer + strlen(Buffer));
+#elif defined(HAVE_PTHREAD_GET_NAME_NP)
constexpr uint32_t len = get_max_thread_name_length_impl();
char buf[len];
- ::pthread_getname_np(::pthread_self(), buf, len);
+ ::pthread_get_name_np(::pthread_self(), buf, len);
Name.append(buf, buf + strlen(buf));
-#elif defined(__OpenBSD__)
+
+#elif defined(HAVE_PTHREAD_GETNAME_NP)
constexpr uint32_t len = get_max_thread_name_length_impl();
char buf[len];
- ::pthread_get_name_np(::pthread_self(), buf, len);
+ ::pthread_getname_np(::pthread_self(), buf, len);
Name.append(buf, buf + strlen(buf));
-#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
- constexpr uint32_t len = get_max_thread_name_length_impl();
- char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
- if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
- Name.append(Buffer, Buffer + strlen(Buffer));
#endif
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
bb31a84
to
df24d78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
df24d78
to
f5217c5
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3372 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/151/builds/2077 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/92/builds/5637 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/141/builds/2054 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/13/builds/1950 Here is the relevant piece of the build log for the reference
|
No description provided.