diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-10-04 20:27:01 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-10-04 20:27:01 +0000 |
commit | a72e2a9037b131cd2d75215c228cc67359632ba7 (patch) | |
tree | 29f2762cbc2c27a6441d5c8b3cbc21702a832b03 /tools/llvm-profdata/llvm-profdata.cpp | |
parent | dfc9ea2a051b54e6445a41d434f383514067b727 (diff) |
Bring r314809 back.
But now include a check for CPU_COUNT so we still build on 10 year old
versions of glibc.
Original message:
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r-- | tools/llvm-profdata/llvm-profdata.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp index eee242107da..8e21a7a9b4f 100644 --- a/tools/llvm-profdata/llvm-profdata.cpp +++ b/tools/llvm-profdata/llvm-profdata.cpp @@ -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::max(1U, std::min(std::thread::hardware_concurrency(), - unsigned(Inputs.size() / 2))); + NumThreads = + std::min(hardware_concurrency(), unsigned((Inputs.size() + 1) / 2)); // Initialize the writer contexts. SmallVector<std::unique_ptr<WriterContext>, 4> Contexts; |