diff options
author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2025-10-03 09:25:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-03 09:25:49 -0400 |
commit | ffc503edd0a2d07121232fe204e480fc29631a90 (patch) | |
tree | f7c4565e759352bd71b2e29ec8461ea7e0eecafe /libcxx/include/__algorithm/comp.h | |
parent | 173063cf054645a7f72e0ca1d0f2dfe87346d65c (diff) | |
download | llvm-ffc503edd0a2d07121232fe204e480fc29631a90.zip llvm-ffc503edd0a2d07121232fe204e480fc29631a90.tar.gz llvm-ffc503edd0a2d07121232fe204e480fc29631a90.tar.bz2 |
[LLVM] Add GNU make jobserver support (#145131)
This patch introduces support for the jobserver protocol to control
parallelism for device offloading tasks.
When running a parallel build with a modern build system like `make -jN`
or `ninja -jN`, each Clang process might also be configured to use
multiple threads for its own tasks (e.g., via `--offload-jobs=4`). This
can lead to an explosion of threads (N * 4), causing heavy system load,
CPU contention, and ultimately slowing down the entire build.
This patch allows Clang to act as a cooperative client of the build
system's jobserver. It extends the `--offload-jobs` option to accept the
value 'jobserver'. With the recent addition of jobserver support to the
Ninja build system, this functionality now benefits users of both Make
and Ninja.
When `--offload-jobs=jobserver` is specified, Clang's thread pool will:
1. Parse the MAKEFLAGS environment variable to find the jobserver
details.
2. Before dispatching a task, acquire a job slot from the jobserver. If
none are available, the worker thread will block.
3. Release the job slot once the task is complete.
This ensures that the total number of active offload tasks across all
Clang processes does not exceed the limit defined by the parent build
system, leading to more efficient and controlled parallel builds.
Implementation:
- A new library, `llvm/Support/Jobserver`, is added to provide a
platform-agnostic client for the jobserver protocol, with backends for
Unix (FIFO) and Windows (semaphores).
- `llvm/Support/ThreadPool` and `llvm/Support/Parallel` are updated with
a `jobserver_concurrency` strategy to integrate this logic.
- The Clang driver and linker-wrapper are modified to recognize the
'jobserver' argument and enable the new thread pool strategy.
- New unit and integration tests are added to validate the feature.
Diffstat (limited to 'libcxx/include/__algorithm/comp.h')
0 files changed, 0 insertions, 0 deletions