[llvm] e9b2131 - [Support] computeHostNumPhysicalCores: use sched_getaffinity for all non-Android Linux with no custom implementation
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 13 01:36:17 PDT 2022
Author: Fangrui Song
Date: 2022-08-13T01:36:13-07:00
New Revision: e9b213131ae9c57f4f151d3206916676135b31b0
URL: https://github.com/llvm/llvm-project/commit/e9b213131ae9c57f4f151d3206916676135b31b0
DIFF: https://github.com/llvm/llvm-project/commit/e9b213131ae9c57f4f151d3206916676135b31b0.diff
LOG: [Support] computeHostNumPhysicalCores: use sched_getaffinity for all non-Android Linux with no custom implementation
Make the sched_getaffinity based implementation available to all architectures
(except s390x/x86 which have a custom implementation). The `CPU_ALLOC(2048)`
code supports all `CONFIG_NR_CPUS` values in Linux kernel `arch/*/configs/`.
The function is mainly used by in-process ThinLTO to decide the default number
of threads. Returning -1 will use just one thread.
Android is excluded because of the higher API level requirement:
`sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-x86=12 introduced-x86_64=21`
Added:
Modified:
llvm/lib/Support/Host.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index f67acd7416315..f163c8256adbd 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1586,7 +1586,9 @@ int computeHostNumPhysicalCores() {
}
return CPU_COUNT(&Enabled);
}
-#elif defined(__linux__) && defined(__powerpc__)
+#elif defined(__linux__) && defined(__s390x__)
+int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
+#elif defined(__linux__) && !defined(__ANDROID__)
int computeHostNumPhysicalCores() {
cpu_set_t Affinity;
if (sched_getaffinity(0, sizeof(Affinity), &Affinity) == 0)
@@ -1605,8 +1607,6 @@ int computeHostNumPhysicalCores() {
}
return -1;
}
-#elif defined(__linux__) && defined(__s390x__)
-int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
#elif defined(__APPLE__)
// Gets the number of *physical cores* on the machine.
int computeHostNumPhysicalCores() {
More information about the llvm-commits
mailing list