llvm.org GIT mirror llvm / 9f2abf5
Revert D38481 due to missing cmake check for CPU_COUNT 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 Daniel Neilson 1 year, 11 months ago
8 changed file(s) with 8 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
268268 add_definitions( -D_GNU_SOURCE )
269269 endif()
270270 # This check requires _GNU_SOURCE
271 check_library_exists(c sched_getaffinity "" HAVE_SCHED_GETAFFINITY)
272271 if(HAVE_LIBPTHREAD)
273272 check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
274273 check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
184184 /* Define to 1 if you have the `setenv' function. */
185185 #cmakedefine HAVE_SETENV ${HAVE_SETENV}
186186
187 /* Define to 1 if you have the `sched_getaffinity' function. */
188 #cmakedefine HAVE_SCHED_GETAFFINITY ${HAVE_SCHED_GETAFFINITY}
189
190187 /* Define to 1 if you have the `setrlimit' function. */
191188 #cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT}
192189
3737 using TaskTy = std::function;
3838 using PackagedTaskTy = std::packaged_task;
3939
40 /// Construct a pool with the number of threads found by
41 /// hardware_concurrency().
40 /// Construct a pool with the number of core available on the system (or
41 /// whatever the value returned by std::thread::hardware_concurrency() is).
4242 ThreadPool();
4343
4444 /// Construct a pool of \p ThreadCount threads
130130 /// Returns 1 when LLVM is configured with LLVM_ENABLE_THREADS=OFF
131131 unsigned heavyweight_hardware_concurrency();
132132
133 /// Get the number of threads that the current program can execute
134 /// concurrently. On some systems std::thread::hardware_concurrency() returns
135 /// the total number of cores, without taking affinity into consideration.
136 /// Returns 1 when LLVM is configured with LLVM_ENABLE_THREADS=OFF.
137 /// Fallback to std::thread::hardware_concurrency() if sched_getaffinity is
138 /// not available.
139 unsigned hardware_concurrency();
140
141133 /// \brief Return the current thread id, as used in various OS system calls.
142134 /// Note that not all platforms guarantee that the value returned will be
143135 /// unique across the entire system, so portable code should not assume
88
99 #include "llvm/Support/Parallel.h"
1010 #include "llvm/Config/llvm-config.h"
11 #include "llvm/Support/Threading.h"
1211
1312 #include
1413 #include
7069 /// in filo order.
7170 class ThreadPoolExecutor : public Executor {
7271 public:
73 explicit ThreadPoolExecutor(unsigned ThreadCount = hardware_concurrency())
72 explicit ThreadPoolExecutor(
73 unsigned ThreadCount = std::thread::hardware_concurrency())
7474 : Done(ThreadCount) {
7575 // Spawn all but one of the threads in another thread as spawning threads
7676 // can take a while.
1313 #include "llvm/Support/ThreadPool.h"
1414
1515 #include "llvm/Config/llvm-config.h"
16 #include "llvm/Support/Threading.h"
1716 #include "llvm/Support/raw_ostream.h"
1817
1918 using namespace llvm;
2019
2120 #if LLVM_ENABLE_THREADS
2221
23 // Default to hardware_concurrency
24 ThreadPool::ThreadPool() : ThreadPool(hardware_concurrency()) {}
22 // Default to std::thread::hardware_concurrency
23 ThreadPool::ThreadPool() : ThreadPool(std::thread::hardware_concurrency()) {}
2524
2625 ThreadPool::ThreadPool(unsigned ThreadCount)
2726 : ActiveThreads(0), EnableFlag(true) {
4646
4747 unsigned llvm::heavyweight_hardware_concurrency() { return 1; }
4848
49 unsigned llvm::hardware_concurrency() { return 1; }
50
5149 uint64_t llvm::get_threadid() { return 0; }
5250
5351 uint32_t llvm::get_max_thread_name_length() { return 0; }
7270 return NumPhysical;
7371 }
7472
75 unsigned llvm::hardware_concurrency() {
76 #ifdef HAVE_SCHED_GETAFFINITY
77 cpu_set_t Set;
78 if (sched_getaffinity(0, sizeof(Set), &Set))
79 return CPU_COUNT(&Set);
80 #endif
81 // Guard against std::thread::hardware_concurrency() returning 0.
82 if (unsigned Val = std::thread::hardware_concurrency())
83 return Val;
84 return 1;
85 }
86
8773 // Include the platform-specific parts of this class.
8874 #ifdef LLVM_ON_UNIX
8975 #include "Unix/Threading.inc"
210210
211211 // If NumThreads is not specified, auto-detect a good default.
212212 if (NumThreads == 0)
213 NumThreads =
214 std::min(hardware_concurrency(), unsigned((Inputs.size() + 1) / 2));
213 NumThreads = std::max(1U, std::min(std::thread::hardware_concurrency(),
214 unsigned(Inputs.size() / 2)));
215215
216216 // Initialize the writer contexts.
217217 SmallVector, 4> Contexts;