[PATCH] D84764: Fix computeHostNumPhysicalCores() for Linux on POWER and Linux on Z

Ettore Tiotto via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 08:56:08 PDT 2020


etiotto created this revision.
etiotto added reviewers: Kai, Whitney, kbarton, bmahjour, RKSimon.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya, krytarowski.
Herald added a project: LLVM.
etiotto requested review of this revision.

ThinLTO is run using a single thread on Linux on Power. The  `compute_thread_count()` routine calls `getHostNumPhysicalCores` which returns -1 by default, and so  `MaxThreadCount is set to 1.

  unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
   
      int MaxThreadCount = UseHyperThreads ? computeHostNumHardwareThreads()
                                          : sys::getHostNumPhysicalCores();
       if (MaxThreadCount <= 0)
          MaxThreadCount = 1;
     …
  }

Fix: provide custom implementation of `getHostNumPhysicalCores` for Linux on Power and Linux on Z.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84764

Files:
  llvm/lib/Support/Host.cpp


Index: llvm/lib/Support/Host.cpp
===================================================================
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -1271,6 +1271,14 @@
   }
   return CPU_COUNT(&Enabled);
 }
+#elif (defined(__linux__) &&                                                   \
+       (defined(__ppc__) || defined(__powerpc__) || defined(__s390x__)))
+#include <unistd.h>
+
+// Gets the number of *physical cores* on the machine.
+int computeHostNumPhysicalCores() {
+  return sysconf(_SC_NPROCESSORS_ONLN);
+}
 #elif defined(__APPLE__) && defined(__x86_64__)
 #include <sys/param.h>
 #include <sys/sysctl.h>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84764.281250.patch
Type: text/x-patch
Size: 637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/208b37cf/attachment.bin>


More information about the llvm-commits mailing list