]> granicus.if.org Git - llvm/commitdiff
Revert D38481 due to missing cmake check for CPU_COUNT
authorDaniel Neilson <dneilson@azul.com>
Wed, 4 Oct 2017 18:19:03 +0000 (18:19 +0000)
committerDaniel Neilson <dneilson@azul.com>
Wed, 4 Oct 2017 18:19:03 +0000 (18:19 +0000)
Summary:
This reverts D38481. The change breaks systems with older versions of glibc. It
injects a use of CPU_COUNT() from sched.h without checking to ensure that the
function exists first.

Reviewers:

Subscribers:

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314922 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/config-ix.cmake
include/llvm/Config/config.h.cmake
include/llvm/Support/ThreadPool.h
include/llvm/Support/Threading.h
lib/Support/Parallel.cpp
lib/Support/ThreadPool.cpp
lib/Support/Threading.cpp
tools/llvm-profdata/llvm-profdata.cpp

index c89e46227c51b7626814a6a312c8ebe8e3c2e655..a1a16b99eb1a400b545ecda638fe624405dba56d 100644 (file)
@@ -269,7 +269,6 @@ if( LLVM_USING_GLIBC )
   add_definitions( -D_GNU_SOURCE )
 endif()
 # This check requires _GNU_SOURCE
-check_library_exists(c sched_getaffinity "" HAVE_SCHED_GETAFFINITY)
 if(HAVE_LIBPTHREAD)
   check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
   check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
index f3506de015b9394d484cbb70059ad9a81b6d47ee..d0d1e0985ccae7ea42019bd5dedc703b80bc4e07 100644 (file)
 /* Define to 1 if you have the `setenv' function. */
 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
 
-/* Define to 1 if you have the `sched_getaffinity' function. */
-#cmakedefine HAVE_SCHED_GETAFFINITY ${HAVE_SCHED_GETAFFINITY}
-
 /* Define to 1 if you have the `setrlimit' function. */
 #cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT}
 
index fb82559005100ae49f4ca46ca52b9522b0fbedae..9ada946c6dae3c49e9a330e0cc62c7cf0dace537 100644 (file)
@@ -38,8 +38,8 @@ public:
   using TaskTy = std::function<void()>;
   using PackagedTaskTy = std::packaged_task<void()>;
 
-  /// Construct a pool with the number of threads found by
-  /// hardware_concurrency().
+  /// Construct a pool with the number of core available on the system (or
+  /// whatever the value returned by std::thread::hardware_concurrency() is).
   ThreadPool();
 
   /// Construct a pool of \p ThreadCount threads
index 6d813bccb93fce657688ff8f01623d1ac6565a4b..03963a24c107eeed24dd39611c6b3d57ea63cb78 100644 (file)
@@ -131,14 +131,6 @@ void llvm_execute_on_thread(void (*UserFn)(void *), void *UserData,
   /// Returns 1 when LLVM is configured with LLVM_ENABLE_THREADS=OFF
   unsigned heavyweight_hardware_concurrency();
 
-  /// Get the number of threads that the current program can execute
-  /// concurrently. On some systems std::thread::hardware_concurrency() returns
-  /// the total number of cores, without taking affinity into consideration.
-  /// Returns 1 when LLVM is configured with LLVM_ENABLE_THREADS=OFF.
-  /// Fallback to std::thread::hardware_concurrency() if sched_getaffinity is
-  /// not available.
-  unsigned hardware_concurrency();
-
   /// \brief Return the current thread id, as used in various OS system calls.
   /// Note that not all platforms guarantee that the value returned will be
   /// unique across the entire system, so portable code should not assume
index 010e42916f957633f57b8531d870bf37930b9b43..ab2cfdebf07d4507d4464f0eba0b0670a7506a26 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "llvm/Support/Parallel.h"
 #include "llvm/Config/llvm-config.h"
-#include "llvm/Support/Threading.h"
 
 #include <atomic>
 #include <stack>
@@ -71,7 +70,8 @@ Executor *Executor::getDefaultExecutor() {
 ///   in filo order.
 class ThreadPoolExecutor : public Executor {
 public:
-  explicit ThreadPoolExecutor(unsigned ThreadCount = hardware_concurrency())
+  explicit ThreadPoolExecutor(
+      unsigned ThreadCount = std::thread::hardware_concurrency())
       : Done(ThreadCount) {
     // Spawn all but one of the threads in another thread as spawning threads
     // can take a while.
index f1b5bdf40c32b4eea6a8a9bd80d0a4e30fe82e34..22b7550d497149bbb0292855c36ac7d88799d6d0 100644 (file)
 #include "llvm/Support/ThreadPool.h"
 
 #include "llvm/Config/llvm-config.h"
-#include "llvm/Support/Threading.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
 #if LLVM_ENABLE_THREADS
 
-// Default to hardware_concurrency
-ThreadPool::ThreadPool() : ThreadPool(hardware_concurrency()) {}
+// Default to std::thread::hardware_concurrency
+ThreadPool::ThreadPool() : ThreadPool(std::thread::hardware_concurrency()) {}
 
 ThreadPool::ThreadPool(unsigned ThreadCount)
     : ActiveThreads(0), EnableFlag(true) {
index b3579b575488f260b5d6aa18d17b88c794ab2694..6a10b988d4648a9e95e42c2761b34f0717c52122 100644 (file)
@@ -47,8 +47,6 @@ void llvm::llvm_execute_on_thread(void (*Fn)(void *), void *UserData,
 
 unsigned llvm::heavyweight_hardware_concurrency() { return 1; }
 
-unsigned llvm::hardware_concurrency() { return 1; }
-
 uint64_t llvm::get_threadid() { return 0; }
 
 uint32_t llvm::get_max_thread_name_length() { return 0; }
@@ -73,18 +71,6 @@ unsigned llvm::heavyweight_hardware_concurrency() {
   return NumPhysical;
 }
 
-unsigned llvm::hardware_concurrency() {
-#ifdef HAVE_SCHED_GETAFFINITY
-  cpu_set_t Set;
-  if (sched_getaffinity(0, sizeof(Set), &Set))
-    return CPU_COUNT(&Set);
-#endif
-  // Guard against std::thread::hardware_concurrency() returning 0.
-  if (unsigned Val = std::thread::hardware_concurrency())
-    return Val;
-  return 1;
-}
-
 // Include the platform-specific parts of this class.
 #ifdef LLVM_ON_UNIX
 #include "Unix/Threading.inc"
index 8e21a7a9b4fc93116c3f1ef563a7776570ea71a1..eee242107dabe85b44dc55836766dc71e57e2d78 100644 (file)
@@ -211,8 +211,8 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
 
   // If NumThreads is not specified, auto-detect a good default.
   if (NumThreads == 0)
-    NumThreads =
-        std::min(hardware_concurrency(), unsigned((Inputs.size() + 1) / 2));
+    NumThreads = std::max(1U, std::min(std::thread::hardware_concurrency(),
+                                       unsigned(Inputs.size() / 2)));
 
   // Initialize the writer contexts.
   SmallVector<std::unique_ptr<WriterContext>, 4> Contexts;