[llvm] [AIX][PowerPC] Teach the Threading Library About the Number of Physical Cores on AIX (PR #67683)
Qiongsi Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 06:47:39 PDT 2023
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/67683
>From a384b08716cc9a37b3fe646ee4ff9ac3f6ad9b63 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu <qwu at ibm.com>
Date: Thu, 28 Sep 2023 09:39:57 -0400
Subject: [PATCH 1/2] Teach the threading library about number of physical
cores on AIX
---
llvm/lib/Support/Unix/Threading.inc | 6 ++++++
llvm/unittests/Support/Threading.cpp | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 819748db4ec21e8..1d5f01264784d4e 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -55,6 +55,10 @@
#include <unistd.h> // For syscall()
#endif
+#if defined(_AIX)
+#include <sys/systemcfg.h>
+#endif
+
namespace llvm {
pthread_t
llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
@@ -432,6 +436,8 @@ static int computeHostNumPhysicalCores() {
static_cast<uintptr_t>(reinterpret_cast<unsigned int &>(CVT[CVTCSD])));
return reinterpret_cast<int &>(CSD[CSD_NUMBER_ONLINE_STANDARD_CPS]);
}
+#elif defined(_AIX)
+static int computeHostNumPhysicalCores() { return _system_configuration.ncpus; }
#else
// On other systems, return -1 to indicate unknown.
static int computeHostNumPhysicalCores() { return -1; }
diff --git a/llvm/unittests/Support/Threading.cpp b/llvm/unittests/Support/Threading.cpp
index b5eff6f6f14fba6..7fd8b1cfe3a5b9c 100644
--- a/llvm/unittests/Support/Threading.cpp
+++ b/llvm/unittests/Support/Threading.cpp
@@ -29,7 +29,7 @@ static bool isThreadingSupportedArchAndOS() {
return (Host.isOSWindows() && llvm_is_multithreaded()) || Host.isOSDarwin() ||
(Host.isX86() && Host.isOSLinux()) ||
(Host.isOSLinux() && !Host.isAndroid()) ||
- (Host.isSystemZ() && Host.isOSzOS());
+ (Host.isSystemZ() && Host.isOSzOS()) || Host.isOSAIX();
#else
return false;
#endif
>From a1cc33bb51efc7feba74682555f8c7754eb8ef4c Mon Sep 17 00:00:00 2001
From: Qiongsi Wu <qwu at ibm.com>
Date: Fri, 29 Sep 2023 09:14:05 -0400
Subject: [PATCH 2/2] Address code review
---
llvm/lib/Support/CMakeLists.txt | 9 +++++++++
llvm/lib/Support/Unix/Threading.inc | 8 +-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 54baf159a86877c..b96d62c7a6224d6 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -118,6 +118,15 @@ if(LLVM_INTEGRATED_CRT_ALLOC)
endif()
endif()
+# FIXME: We are currently guarding AIX headers with _XOPEN_SOURCE=700.
+# See llvm/CMakeLists.txt. However, we need _SC_NPROCESSORS_ONLN in
+# unistd.h and it is guarded by _ALL_SOURCE, so we remove the _XOPEN_SOURCE
+# guard here. We should remove the guards all together once AIX cleans up
+# the system headers.
+if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+ remove_definitions("-D_XOPEN_SOURCE=700")
+endif()
+
add_subdirectory(BLAKE3)
add_llvm_component_library(LLVMSupport
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 1d5f01264784d4e..55e7dcfa4678cf1 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -55,10 +55,6 @@
#include <unistd.h> // For syscall()
#endif
-#if defined(_AIX)
-#include <sys/systemcfg.h>
-#endif
-
namespace llvm {
pthread_t
llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
@@ -375,7 +371,7 @@ static int computeHostNumPhysicalCores() {
}
return CPU_COUNT(&Enabled);
}
-#elif defined(__linux__) && defined(__s390x__)
+#elif (defined(__linux__) && defined(__s390x__)) || defined(_AIX)
static int computeHostNumPhysicalCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
@@ -436,8 +432,6 @@ static int computeHostNumPhysicalCores() {
static_cast<uintptr_t>(reinterpret_cast<unsigned int &>(CVT[CVTCSD])));
return reinterpret_cast<int &>(CSD[CSD_NUMBER_ONLINE_STANDARD_CPS]);
}
-#elif defined(_AIX)
-static int computeHostNumPhysicalCores() { return _system_configuration.ncpus; }
#else
// On other systems, return -1 to indicate unknown.
static int computeHostNumPhysicalCores() { return -1; }
More information about the llvm-commits
mailing list