Skip to content

Commit

Permalink
Fix computeHostNumPhysicalCores() for Linux on POWER and Linux on Z
Browse files Browse the repository at this point in the history
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.

Reviewed By: Kai, uweigand

Differential Revision: https://reviews.llvm.org/D84764
  • Loading branch information
etiotto committed Jul 30, 2020
1 parent ce1eb7a commit 36a4f10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions llvm/lib/Support/Host.cpp
Expand Up @@ -1271,6 +1271,12 @@ int computeHostNumPhysicalCores() {
}
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>
Expand Down
4 changes: 3 additions & 1 deletion llvm/unittests/Support/Host.cpp
Expand Up @@ -40,7 +40,9 @@ class HostTest : public testing::Test {
// x86_64 Linux and Darwin.
return (Host.isOSWindows() && llvm_is_multithreaded()) ||
(Host.isX86() &&
(Host.isOSDarwin() || Host.getOS() == Triple::Linux));
(Host.isOSDarwin() || Host.getOS() == Triple::Linux)) ||
(Host.getOS() == Triple::Linux &&
(Host.isPPC64() || Host.isSystemZ()));
}

HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
Expand Down

0 comments on commit 36a4f10

Please sign in to comment.