The scheduler review's work packet: the inbox's and the work loop's fixes, and race tests that catch
a lost wake.
Take a commit left to the scheduler thread in before its next check, and bound a commit's passes:
Four defects in the commit inbox (scheduler/inbox.rs) and the scheduler thread's loop, which
broke the inbox's bound on a commit's wait and Metal's prompt commit:
- A commit left to the scheduler thread during the round that took an earlier one in waited for
the thread's next check (the program's code) or host step: the thread looked at the inbox once
before each piece of work, not again after that round. The thread's way through its work is now
`scheduler/left.rs`'s `work_through`, which makes rounds for as long as the inbox holds commits
before each piece, generic so that it is tested without a device.
- A committing thread passed again for as long as other threads' commits or wakes kept arriving
during its passes, so one commit() was unbounded. Its look again now makes at most one pass
(`inbox::AGAIN`); what is left to that pass with no other passer counted is answered as
unattended, and `Scheduler::commit` wakes the scheduler thread for it (the wake's code moves into
`Inbox::wake`, which `Scheduler::wake` and the tests' model share).
- Checks always ran before host steps, and rounds between pieces add checks, so a step (and its
queue) could wait behind checks found after it. Work now runs in the order rounds found it, a
round's checks before its steps.
- A pass cleared the nudge with a plain store, so the memory model gave no happens-before from a
waker's change to the pass that took its nudge in. It is now a swap, which synchronizes with the
waker's store it reads.
Docs made true again: the inbox's and the scheduler's wait bounds, SubmissionCheck's and
add_submission_handler's "a commit meanwhile still submits", the stall in texture/storage_form.rs
(also after a commit left to another thread's pass), and WorkCounts::queue_submissions (the first
work rides in the batch's call). RUNTIME_VERSION 1188; the runtime-sources pin follows in its own
commit.
Verified on msi-laptop (Linux, Rust 1.98.1), before the rebase onto fleet/round: clippy -p metal2vulkan-runtime --all-targets
--all-features clean; rustdoc of the crate clean; nextest tests::inbox, tests::left and
tests::scheduler 24 of 24. Each new deterministic test fails without its fix: with `if` for
`while` the left commit runs after the first check ([TakenIn(1), Ran(Check, 1), TakenIn(2)...]);
with checks always first a later round's check runs before an earlier round's steps; with the
committer unbounded it makes 5 passes for 4 commits left to it, against 2. A paced stress (4
threads, 6 commits a ms in all, 80 us passes, release) made up to 4 passes in one commit() on the
base (0.1-12% of commits over 2), and at most 2 with this change.
Make the inbox's race tests catch a lost wake, and print the paths they took:
The racing-commits test stopped its model scheduler thread right after the committers ended, and
the stop's own notify would make the thread pass for a commit whose wake was lost, so the test
could not see one. It now waits (up to its 30 s bound) for the thread to have passed every commit
before it stops it, as the wakers' test does for every raise, through a shared `soon`. Both tests
print how often the races took the paths they cover (commits left to another thread and left
unattended; wakes left to a pass under way), as evidence that those paths ran.
Test-only: the runtime sources the pin covers are unchanged.
Verified on msi-laptop: tests::inbox and tests::left pass (see the landing note for counts).
Versions: RUNTIME_VERSION 1196 -> 1197. RUNTIME_VERSION moves: when a commit's work is taken in and
how many passes it makes change. crates/metal2vulkan-validation/runtime-sources.sha256 holds
581e5e5522ddfb5c61d4b949e7b7b01e210925bff898241bcd517ef6fdee40f2, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.