[all-commits] [llvm/llvm-project] d110c3: [ADT] Support BitVector as a key in DenseSet/Map

Alexandre Ganea via All-commits all-commits at lists.llvm.org
Fri Feb 14 07:25:56 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: d110c3a9f5253c4d94c10299c61fbbb33edab7db
      https://github.com/llvm/llvm-project/commit/d110c3a9f5253c4d94c10299c61fbbb33edab7db
  Author: Alexandre Ganea <alexandre.ganea at ubisoft.com>
  Date:   2020-02-14 (Fri, 14 Feb 2020)

  Changed paths:
    M llvm/include/llvm/ADT/BitVector.h
    M llvm/include/llvm/ADT/SmallBitVector.h
    M llvm/unittests/ADT/BitVectorTest.cpp

  Log Message:
  -----------
  [ADT] Support BitVector as a key in DenseSet/Map

This patch adds DenseMapInfo<> support for BitVector and SmallBitVector.

This is part of https://reviews.llvm.org/D71775, where a BitVector is used as a thread affinity mask.


  Commit: d9049e871f309199a3d8fd7d3c0f76c86af9db91
      https://github.com/llvm/llvm-project/commit/d9049e871f309199a3d8fd7d3c0f76c86af9db91
  Author: Alexandre Ganea <alexandre.ganea at ubisoft.com>
  Date:   2020-02-14 (Fri, 14 Feb 2020)

  Changed paths:
    M clang/tools/clang-scan-deps/ClangScanDeps.cpp

  Log Message:
  -----------
  [clang-scan-deps] Switch to using a ThreadPool

Use a ThreadPool instead of plain std::threads in clang-scan-deps.
This is needed to further support https://reviews.llvm.org/D71775.

Differential Revision: https://reviews.llvm.org/D74569


  Commit: 8404aeb56a73ab24f9b295111de3b37a37f0b841
      https://github.com/llvm/llvm-project/commit/8404aeb56a73ab24f9b295111de3b37a37f0b841
  Author: Alexandre Ganea <alexandre.ganea at ubisoft.com>
  Date:   2020-02-14 (Fri, 14 Feb 2020)

  Changed paths:
    M clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
    M clang-tools-extra/clangd/TUScheduler.cpp
    M clang-tools-extra/clangd/index/Background.cpp
    M clang-tools-extra/clangd/index/Background.h
    M clang-tools-extra/clangd/index/BackgroundRebuild.h
    M clang/lib/Tooling/AllTUsExecution.cpp
    M clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
    M clang/tools/clang-scan-deps/ClangScanDeps.cpp
    M lld/ELF/SyntheticSections.cpp
    M llvm/include/llvm/LTO/LTO.h
    M llvm/include/llvm/Support/ThreadPool.h
    M llvm/include/llvm/Support/Threading.h
    M llvm/lib/CodeGen/ParallelCG.cpp
    M llvm/lib/DWARFLinker/DWARFLinker.cpp
    M llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
    M llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
    M llvm/lib/LTO/LTO.cpp
    M llvm/lib/LTO/LTOBackend.cpp
    M llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    M llvm/lib/Support/Host.cpp
    M llvm/lib/Support/Parallel.cpp
    M llvm/lib/Support/ThreadPool.cpp
    M llvm/lib/Support/Threading.cpp
    M llvm/lib/Support/Unix/Threading.inc
    M llvm/lib/Support/Windows/Threading.inc
    M llvm/tools/dsymutil/dsymutil.cpp
    M llvm/tools/gold/gold-plugin.cpp
    M llvm/tools/llvm-cov/CodeCoverage.cpp
    M llvm/tools/llvm-cov/CoverageExporterJson.cpp
    M llvm/tools/llvm-cov/CoverageReport.cpp
    M llvm/tools/llvm-lto2/llvm-lto2.cpp
    M llvm/tools/llvm-profdata/llvm-profdata.cpp
    M llvm/unittests/Support/Host.cpp
    M llvm/unittests/Support/TaskQueueTest.cpp
    M llvm/unittests/Support/ThreadPool.cpp
    M llvm/unittests/Support/Threading.cpp
    M mlir/lib/Pass/Pass.cpp

  Log Message:
  -----------
  [Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups

The goal of this patch is to maximize CPU utilization on multi-socket or high core count systems, so that parallel computations such as LLD/ThinLTO can use all hardware threads in the system. Before this patch, on Windows, a maximum of 64 hardware threads could be used at most, in some cases dispatched only on one CPU socket.

== Background ==
Windows doesn't have a flat cpu_set_t like Linux. Instead, it projects hardware CPUs (or NUMA nodes) to applications through a concept of "processor groups". A "processor" is the smallest unit of execution on a CPU, that is, an hyper-thread if SMT is active; a core otherwise. There's a limit of 32-bit processors on older 32-bit versions of Windows, which later was raised to 64-processors with 64-bit versions of Windows. This limit comes from the affinity mask, which historically is represented by the sizeof(void*). Consequently, the concept of "processor groups" was introduced for dealing with systems with more than 64 hyper-threads.

By default, the Windows OS assigns only one "processor group" to each starting application, in a round-robin manner. If the application wants to use more processors, it needs to programmatically enable it, by assigning threads to other "processor groups". This also means that affinity cannot cross "processor group" boundaries; one can only specify a "preferred" group on start-up, but the application is free to allocate more groups if it wants to.

This creates a peculiar situation, where newer CPUs like the AMD EPYC 7702P (64-cores, 128-hyperthreads) are projected by the OS as two (2) "processor groups". This means that by default, an application can only use half of the cores. This situation could only get worse in the years to come, as dies with more cores will appear on the market.

== The problem ==
The heavyweight_hardware_concurrency() API was introduced so that only *one hardware thread per core* was used. Once that API returns, that original intention is lost, only the number of threads is retained. Consider a situation, on Windows, where the system has 2 CPU sockets, 18 cores each, each core having 2 hyper-threads, for a total of 72 hyper-threads. Both heavyweight_hardware_concurrency() and hardware_concurrency() currently return 36, because on Windows they are simply wrappers over std::thread::hardware_concurrency() -- which can only return processors from the current "processor group".

== The changes in this patch ==
To solve this situation, we capture (and retain) the initial intention until the point of usage, through a new ThreadPoolStrategy class. The number of threads to use is deferred as late as possible, until the moment where the std::threads are created (ThreadPool in the case of ThinLTO).

When using hardware_concurrency(), setting ThreadCount to 0 now means to use all the possible hardware CPU (SMT) threads. Providing a ThreadCount above to the maximum number of threads will have no effect, the maximum will be used instead.
The heavyweight_hardware_concurrency() is similar to hardware_concurrency(), except that only one thread per hardware *core* will be used.

When LLVM_ENABLE_THREADS is OFF, the threading APIs will always return 1, to ensure any caller loops will be exercised at least once.

Differential Revision: https://reviews.llvm.org/D71775


Compare: https://github.com/llvm/llvm-project/compare/c29310707e9a...8404aeb56a73


More information about the All-commits mailing list