Take a commit left to the scheduler in before its next check, and bound a commit's passes
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.
This commit is contained in:
1 parent
07abdd4bd9
commit
e5d1616030
12 files changed
+734
-197
No files matched your search
@@ -51,9 +51,12 @@ use std::sync::Arc;
|
||||
/// whose memory was taken away, as Metal fails it).
|
||||
///
|
||||
/// It runs with no lock of the runtime's held, and holds back the scheduler thread's submissions
|
||||
/// while it runs (a commit meanwhile still submits its own ready batches): it must not wait for
|
||||
/// GPU work, a command buffer or a handler, and should be quick. It may call the runtime
|
||||
/// otherwise.
|
||||
/// while it runs. A commit made meanwhile has its ready batches submitted, by itself or by the
|
||||
/// pass of another commit's thread it finds under way; where that pass is the last that thread
|
||||
/// makes for others, which leaves what it is left to the scheduler's thread
|
||||
/// (`scheduler/inbox.rs`), they wait for this check to end, unless a later commit takes them in
|
||||
/// first. It must not wait for GPU work, a command buffer or a handler, and should be quick. It
|
||||
/// may call the runtime otherwise.
|
||||
pub type SubmissionCheck = Arc<dyn Fn(&Submission<'_>) -> Option<NonZeroU64> + Send + Sync>;
|
||||
|
||||
/// The `MTLCommandBufferError` code a submission whose check panicked fails with: `Internal`.
|
||||
|
||||
@@ -1318,11 +1318,14 @@ impl CommandBuffer {
|
||||
/// submission or host step that fails, a lost device); they are dropped with it. A command
|
||||
/// buffer committed as failed ([`commit_failed`](Self::commit_failed)) submits its batches
|
||||
/// and runs them.
|
||||
/// - **Keep it short.** It holds back its command buffer's scheduling, `commit` where the
|
||||
/// commit submits, and on the scheduler thread the device's other submissions (a commit
|
||||
/// meanwhile still submits its own ready batches). A wait in it for a command buffer, or
|
||||
/// for a slot of a full queue, that has not happened yet is refused (`WaitWouldDeadlock` of
|
||||
/// [`DeadlockCause::SubmissionHandler`]); it must not wait for GPU work otherwise.
|
||||
/// - **Keep it short.** It holds back its command buffer's scheduling, `commit` where a
|
||||
/// commit's thread runs it, and on the scheduler thread the device's other submissions,
|
||||
/// among them those of a commit left to the pass that submitted this command buffer, which
|
||||
/// the thread may take in only after its handlers (`scheduler/inbox.rs`). A commit made
|
||||
/// while it runs that finds no pass under way submits its own ready batches. A wait in it
|
||||
/// for a command buffer, or for a slot of a full queue, that has not happened yet is refused
|
||||
/// (`WaitWouldDeadlock` of [`DeadlockCause::SubmissionHandler`]); it must not wait for GPU
|
||||
/// work otherwise.
|
||||
///
|
||||
/// Refused once the command buffer is committed (`Invalid`, `Problem::HandlerAfterCommit`),
|
||||
/// as [`add_scheduled_handler`](Self::add_scheduled_handler) is.
|
||||
|
||||
Reference in new issue
Block a user