[lld] r314810 - Use sched_getaffinity instead of std::thread::hardware_concurrency.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 09:25:49 PDT 2017


Author: rafael
Date: Tue Oct  3 09:25:48 2017
New Revision: 314810

URL: http://llvm.org/viewvc/llvm-project?rev=314810&view=rev
Log:
Use sched_getaffinity instead of std::thread::hardware_concurrency.

The issue with std::thread::hardware_concurrency is that it forwards
to libc and some implementations (like glibc) don't take thread
affinity into consideration.

With this change a llvm program that can execute in only 2 cores will
use 2 threads, even if the machine has 32 cores.

This makes benchmarking a lot easier, but should also help if someone
doesn't want to use all cores for compilation for example.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=314810&r1=314809&r2=314810&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Oct  3 09:25:48 2017
@@ -2240,8 +2240,8 @@ void MergeNoTailSection::finalizeContent
   // operations in the following tight loop.
   size_t Concurrency = 1;
   if (Config->Threads)
-    if (int N = std::thread::hardware_concurrency())
-      Concurrency = std::min<size_t>(PowerOf2Floor(N), NumShards);
+    Concurrency =
+        std::min<size_t>(PowerOf2Floor(hardware_concurrency()), NumShards);
 
   // Add section pieces to the builders.
   parallelForEachN(0, Concurrency, [&](size_t ThreadId) {




More information about the llvm-commits mailing list