From 336ab2d51dfdd5ca09c2a9c506453db4fe653584 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Wed, 13 Jan 2021 20:59:31 -0500 Subject: [Support] On Windows, take the affinity mask into account The number of hardware threads available to a ThreadPool can be limited if setting an affinity mask. For example: > start /B /AFFINITY 0xF lld-link.exe ... Would let LLD only use 4 hyper-threads. Previously, there was an outstanding issue on Windows Server 2019 on dual-CPU machines, which was preventing from using both CPU sockets. In normal conditions, when no affinity mask was set, ProcessorGroup::AllThreads was different from ProcessorGroup::UsableThreads. The previous code in llvm/lib/Support/Windows/Threading.inc L201 was improperly assuming those two values to be equal, and consequently was limiting the execution to only one CPU socket. Differential Revision: https://reviews.llvm.org/D92419 --- llvm/lib/Support/Program.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Support/Program.cpp') diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp index 5294f65..c7a5964 100644 --- a/llvm/lib/Support/Program.cpp +++ b/llvm/lib/Support/Program.cpp @@ -26,17 +26,20 @@ using namespace sys; static bool Execute(ProcessInfo &PI, StringRef Program, ArrayRef Args, Optional> Env, ArrayRef> Redirects, - unsigned MemoryLimit, std::string *ErrMsg); + unsigned MemoryLimit, std::string *ErrMsg, + BitVector *AffinityMask); int sys::ExecuteAndWait(StringRef Program, ArrayRef Args, Optional> Env, ArrayRef> Redirects, unsigned SecondsToWait, unsigned MemoryLimit, std::string *ErrMsg, bool *ExecutionFailed, - Optional *ProcStat) { + Optional *ProcStat, + BitVector *AffinityMask) { assert(Redirects.empty() || Redirects.size() == 3); ProcessInfo PI; - if (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) { + if (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg, + AffinityMask)) { if (ExecutionFailed) *ExecutionFailed = false; ProcessInfo Result = @@ -55,12 +58,13 @@ ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef Args, Optional> Env, ArrayRef> Redirects, unsigned MemoryLimit, std::string *ErrMsg, - bool *ExecutionFailed) { + bool *ExecutionFailed, BitVector *AffinityMask) { assert(Redirects.empty() || Redirects.size() == 3); ProcessInfo PI; if (ExecutionFailed) *ExecutionFailed = false; - if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) + if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg, + AffinityMask)) if (ExecutionFailed) *ExecutionFailed = true; -- cgit v1.1