RFR: 8321242: Enable WorkerThreads to run tasks in caller thread [v6]
Guoxiong Li
gli at openjdk.org
Thu Dec 28 17:24:50 UTC 2023
On Wed, 6 Dec 2023 15:17:51 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> `WorkerThreads` is a generic abstraction that allows running the task in multiple threads. There are cases, however, when we only ask for a single thread to carry the computation, and we can accept the caller running the computation instead of ping-ponging with the worker thread. As rendezvous with worker thread is a potential latency hiccup, we would like to avoid delegating work to worker threads unnecessarily. This improves latency on critical paths: the usual round-trip takes about 10..50us on systems I tried.
>>
>> Nominally, we would like to handle the case for 1 worker requested. But I would argue we would also like to do this even if we are requesting N (N > 1) threads to carry the compute. We can submit (N-1) tasks to workers, and execute the other task in the caller. For lower N-s, this removes additional rendezvous point with workers, and allows caller to complete the bulk of the work while workers are waking up. This would also simplify testing: if caller path is always taken, this would verify the task can indeed be executed by caller.
>>
>> We cannot, however, do this optimization unconditionally, because the caller thread might not be set up in the same way as workers are, and executing the code in caller might cause bugs. Therefore, it would be nice to have the opt-in option that allows running in caller thread. Since this looks to be the property of the task, I added it to task definition.
>>
>> This PR is only the infrastructure code additions, without product code behavior changes. New option is sanity-tested by new gtest. Other PRs can then opt-in tasks into this, for example #16882.
>>
>> Additional testing:
>> - [x] New gtest
>> - [x] Linux x86_64 server fastdebug, `tier{1,2,3}`
>> - [x] Linux AArch64 server fastdebug, `tier{1,2,3}`
>
> Aleksey Shipilev has updated the pull request incrementally with two additional commits since the last revision:
>
> - Missing const
> - More comprehensive gtest
Currently, when setting the active worker number in the method `WorkerThreads::set_active_workers`, we can't set it larger than the max worker number. The related code is shown below.
// method WorkerThreads::set_active_workers
assert(num_workers > 0 && num_workers <= _max_workers,
"Invalid number of active workers %u (should be 1-%u)",
num_workers, _max_workers);
If we use the caller thread to run the task, there is at least one worker thread is idle. In extreme scenarios, when the max worker number is only `1`, the worker thread never runs (actually we don't need the worker thread pool now). Maybe we should revise `WorkerThreads::set_active_workers` or provide other ways to use all the worker threads simultaneously.
src/hotspot/share/gc/shared/workerThread.cpp line 95:
> 93: _task->work(worker_id);
> 94: } else {
> 95: _task->work(worker_id);
If we don't set the GCId, the logs may be obscure. But I don't know whether such non named thread exists.
-------------
PR Review: https://git.openjdk.org/jdk/pull/16945#pullrequestreview-1798283888
PR Review Comment: https://git.openjdk.org/jdk/pull/16945#discussion_r1437793576
More information about the hotspot-gc-dev
mailing list