Repository navigation
Conversation
In fast idle mode an idle worker backs off: it spins for short periods and sleeps for longer ones until it is woken up or its period ends. A new thread that finds all idle workers asleep waits for a wake up, which takes a few microseconds on Linux and up to the resolution of the timer, a millisecond or more, on Windows. With strictly periodic work the backoff can also lock into one phase against it, which makes a whole process fast or slow. A worker that would go to sleep now becomes the sentinel if there is none, and spins through the period instead. It looks at its own queues every round, and at the queues it steals from right after a thread was queued anywhere: wake_one, wake_if_sleeping and do_some_work count the new threads while there is a sentinel. Both the sentinel and the count are on one cache line. The sentinel isn't counted as a spinning worker, so a worker that queues small threads for itself still wakes up a sleeper. One idle core stays busy while the pool is idle. Normal mode is not changed. Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
Describe the idle worker that spins instead of sleeping in the idle backoff section of the scheduler configuration guide. Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Up to standards ✅🟢 Issues
|
In fast idle mode an idle worker spins for short backoff periods and sleeps for longer ones. A new thread that finds all idle workers asleep waits for a wake up, which takes a few microseconds on Linux and a millisecond or more on Windows. With strictly periodic work the backoff can also lock into one phase against it, which makes a whole process fast or slow.
With this, a worker that would go to sleep becomes the sentinel if there is none, and spins through its period instead. It looks at its own queues every round, and at the queues it steals from right after a thread was queued anywhere (
wake_one,wake_if_sleepinganddo_some_workcount the new threads while there is a sentinel; the sentinel and the count share one cache line). The sentinel isn't counted as a spinning worker, so a worker that queues small threads for itself still wakes up a sleeper. Its spin is out of line inspin_as_sentinel. One idle core stays busy while the pool is idle; normal mode is not changed.Based on #8035.
Measured on top of #8018, against it (two sessions per mode with interleaved builds, a row counts only if it moves by more than 3% with p < 0.05 in the same direction in both sessions):
On top of #8035 (the same code in
idle_callback_with_rules) the sentinel keeps the tuned scheduler's branch level with the sentinel branch on the DGX Spark, and on the Xeon with #8034 applied to both.