Files
metal2vulkan/docs
Anees Iqbal 2feb4e70f1 RUNTIME 2437: Scheduler: hand a pass's submission handlers to the device's handler threads as it goes on
What: the scheduler thread's passes no longer run the submission handlers of the command
buffers they submit (or hold in a group, or make Scheduled behind a host step) at the end of
the pass. Each time the pass is about to look for its next batch, it hands the handlers taken
so far, as one segment with its Turns ticket, to the device's handler pool (one context of the
"metal2vulkan-handlers" threads, made at the first hand-off), and goes on submitting. The
segment runs there in its turn, so submission order holds across passes and with
commit_and_submit's own pass, which still runs its handlers inside the call on the committing
thread. A pass that settled a switch of storage forms keeps the handlers it took from then on
and runs them itself after the switch ended, as before, since the switch must end before those
command buffers are Scheduled.

The blocking wait in run_scheduled (a Finished that found Scheduled owed waited on a pool
thread for the submission handlers) is gone: such a Finished is posted behind a context gate
(finish_after_handlers), its place kept, holding no thread, and the thread that ran the
handlers opens the gate; the Finished then runs the owed Scheduled first. So no handler thread
waits for a submission handler, and the pool's cap cannot be exhausted by such waits.

A held group is cut short for another queue's submission handlers (Alone::Handlers) only where
the pass keeps them (a settled switch): handed-off handlers hold back no pass.

Why: in the guest-shaped submit-cost leg on PHOENIX, a command buffer's submission handlers
started 1683/5299/5776 us (p50/p99/max) after its own vkQueueSubmit returned, behind the rest
of the pass; 4561 of 5280 command buffers were seen complete before their own submission
handler ran, and seen -> seen handler was 1.4 ms p50 / 5 ms p99 against Metal's 0.28 ms p99.

Tests: submission_turns gains a_pass_s_submission_handlers_run_while_it_goes_on_{exact,grouped}
(a handler of an earlier submission starts before the pass's later submission returns plus the
pause) and completions_before_their_submission_handlers_hold_no_handler_thread_{exact,grouped}
(6 queues with owed Scheduled on a pool of 2 threads, all complete within a bound; test hook
contexts::TEST_LIMIT). waiter_submits::Held now holds the scheduler thread with a test hook
after the pass that handed off its command buffer's handler (trace::hold_after_hand_off,
Point::HandedOff), since a submission handler no longer runs there. Tests and lanes that held
the scheduler thread in a submission handler hold it in a submission check instead
(unsubmitted, host_memory's deallocator lane); queue_order's take-up probe notes from the
check, which still runs on the scheduler thread; commit_and_submit's held-check test asserts
the orders that hold (A's handler before B's, B's check before B's handler) instead of one
interleaving; the submission_handlers lane expects the handler threads; grouped_submissions'
cross-queue handler lane counts X and Y's one submission once all completed.

Docs: add_submission_handler names the threads (inside commit_and_submit: the committing
thread; otherwise the device's handler threads), README, RUNTIME-PORTING, FAST-PATHS (the
grouped-completion row's handler rule, the commit cost entry), scheduler, inbox, group,
submit, contexts.

Also: the completion_latency guest-shaped leg times each submission handler from its own
submission's return; the unsubmitted check and the deallocator lane hold the scheduler thread
where an empty opener runs no submission check.

Verified (complat): msi m3-max-35809 at 0e0c55e4e8: build, clippy -D warnings (runtime, plain and
--cfg m2v_gpu), unit 44/44, signatures, lavapipe suites 122/122, all 0; gem10 35797 at 4aa9c2ac29:
workspace clippy x3 and rustdoc 0. Negative controls (msi 35811, lavapipe): with the blocking wait
back, completions_before_their_submission_handlers_hold_no_handler_thread fails under Exact and
Grouped (5 of 6 never completed with 2 handler threads); with no hand-off,
a_pass_s_submission_handlers_run_while_it_goes_on fails under both. PHOENIX suites and the
submit-cost leg before/after follow.
2026-11-16 02:01:45 -08:00
..