[llvm] 62a933b - [Support][PPC] Fix bot failures due to cd53ded557c3

Nemanja Ivanovic via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 07:01:08 PDT 2020


Author: Nemanja Ivanovic
Date: 2020-08-04T09:00:49-05:00
New Revision: 62a933b72c5b060bcb2c7332d05082f002d6c65a

URL: https://github.com/llvm/llvm-project/commit/62a933b72c5b060bcb2c7332d05082f002d6c65a
DIFF: https://github.com/llvm/llvm-project/commit/62a933b72c5b060bcb2c7332d05082f002d6c65a.diff

LOG: [Support][PPC] Fix bot failures due to cd53ded557c3

Commit https://reviews.llvm.org/rGcd53ded557c3 attempts to fix the
computation in computeHostNumPhysicalCores() to respect Affinity.
However, the GLIBC wrapper of the affinity system call fails with
a default size of cpu_set_t on systems that have more than 1024 CPUs.
This just fixes the computation on such large machines.

Added: 
    

Modified: 
    llvm/lib/Support/Host.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index d3b255ae0f2e..890b1178cbd0 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1274,9 +1274,21 @@ int computeHostNumPhysicalCores() {
 #elif defined(__linux__) && defined(__powerpc__)
 int computeHostNumPhysicalCores() {
   cpu_set_t Affinity;
-  if (sched_getaffinity(0, sizeof(Affinity), &Affinity) != 0)
-    return -1;
-  return CPU_COUNT(&Affinity);
+  if (sched_getaffinity(0, sizeof(Affinity), &Affinity) == 0)
+    return CPU_COUNT(&Affinity);
+
+  // The call to sched_getaffinity() may have failed because the Affinity
+  // mask is too small for the number of CPU's on the system (i.e. the
+  // system has more than 1024 CPUs). Allocate a mask large enough for
+  // twice as many CPUs.
+  cpu_set_t *DynAffinity;
+  DynAffinity = CPU_ALLOC(2048);
+  if (sched_getaffinity(0, CPU_ALLOC_SIZE(2048), DynAffinity) == 0) {
+    int NumCPUs = CPU_COUNT(DynAffinity);
+    CPU_FREE(DynAffinity);
+    return NumCPUs;
+  }
+  return -1;
 }
 #elif defined(__linux__) && defined(__s390x__)
 int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }


        


More information about the llvm-commits mailing list