bb21c14865fd994b46bb26c74619cc5e01ac4bbc
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
54b8b75d45 |
queue_share: a pairs mode, a game's two command buffers a frame beside a compositor's queue
A consumer's game on the RX 7900 XTX (RADV, one graphics VkQueue) ran a frame of two command buffers (about 9.5 ms and 0.3 ms of GPU time, two frames in flight) at 22 ms a frame against 9.9 ms of GPU time, its batches held 5.5 ms a frame for the compositor's unshared queue (WorkCounts::batch_hold_nanos, heads_held_for_unshared_isolation). This mode runs that shape on the runtime alone: the frame period, GPU time and GPU idle share, each command buffer's commit to kernel start, the GPU gap before each frame, the completion's lateness, and the device's hold and scheduler counts a frame, under either UnsharedIsolationPolicy, with the compositor's queue committing nothing or a draw every --period-ms. Verified: cargo fmt; built and run on the XTX in the following jobs. |
||
|
|
fa57e96133 |
Example queue_share: a churn mode, command queues made and dropped as a guest's processes make them
A compositor (unshared with --unshared) committing a draw every 16 ms beside three kept queues and a churn of queues each made with one long command buffer and dropped 1 to 8 ticks later; --untimed answers GPU times from the host, as a consumer that does so does not share VkQueues. Prints the compositor's latencies and the device's waits behind other queues, the measure of the placement change that follows. Not yet run. |
||
|
|
688cf76271 |
Example queue_share: frames makes the compositor's queue before the application starts
Other queues' batches are held back only while an unshared queue exists, so with the compositor's queue made 50 ms after the application began, the application's first command buffers went untracked and the compositor's first frames waited behind all three: one 85-87 ms wait in every run on both the Iris Xe and the Radeon 780M (m3-max-16884, -16885), which set the worst wait the run reported. A compositor's queue exists before the applications it shows. |
||
|
|
07700b3a86 |
Runtime: an unshared queue's batches never wait in a group, and no group is kept, on a VkQueue held back for it
Measured on the Radeon 780M (job m3-max-16523, queue_share frames, three 30 ms command buffers in flight beside an unshared compositor's draw every 16 ms): with the hold alone the compositor's p50 fell from 72-77 ms to 34-35 ms but its max stayed 84-85 ms, 3.1-3.2 batches ahead of its long waits, and the GPU idled 0.9-1.0% where it idled 0.04%. Two parts of grouped submissions (CompletionPolicy::Grouped, Mesa's merging drivers) undid the hold: - a compositor's batch held in a group goes with the next batch the hold lets go, and is seen complete at that batch's end, 30 ms late; - Group::keeps holds a group while two submissions of its VkQueue run (the compositor's queued behind the application's is the second), so the application's next batch, which the hold let go about 2 ms before the one ahead ends, waited for that one's completion: the GPU idle between. So, on a VkQueue other queues' work is held back from (Device::holds_back_for_unshared): an unshared queue's batch never waits in a group (CommandBufferShared::groups, which submit_batch now asks too), and a group is never kept. The hold bounds the work ahead there by expected GPU time instead of the count of submissions. Elsewhere grouping is as before. The queue_share example's frames mode also reports the application's mean GPU time a command buffer and the kernel submissions a second. |
||
|
|
f9d4c06388 |
Runtime: hold other queues' work back from a VkQueue an unshared queue shares
On a device whose graphics family has one queue (RADV, ANV, lavapipe), every command queue submits to it, an unshared one (a compositor's) included, and a VkQueue runs its submissions in order: the compositor's light command buffer waits for every batch submitted before it. On a Radeon 780M, a compositor committing a draw every 16 ms beside an application keeping three 30 ms command buffers in flight waited 76 ms at the median, 112 ms at worst (queue_share example, frames mode, job m3-max-16449). New DevicePolicy switch unshared_isolation: UnsharedIsolationPolicy::Bounded (the default) or Off. Under Bounded, on a VkQueue an unshared queue holds (SlotShare::unshared), another command queue's batch, otherwise ready, is submitted only while less than 2 ms (unshared_hold::BUDGET) of other queues' expected GPU work is in flight there; else the scheduler holds it, keeping its place in the order (HeldFor::UnsharedIsolation, WorkCounts::heads_held_for_unshared_isolation), and waits for the VkQueue's next completion (a gate in Awaits) or, where the oldest batch's expected run covers it, for the time the work left falls under the budget (wake_by): so the next batch goes in before the one ahead ends. How (unshared_hold.rs): each VkQueue an unshared queue holds keeps a Flight of its batches taken and not seen complete, under queue_wait.rs's leaf lock, at the batch's value take and the host's completion; each other queue's batch carries its command queue's expected run, the host's view of how long its recent batches ran as the VkQueue's oldest (queue_wait.rs's runs), raised at once by a longer run and halved toward a shorter one. The work left is the expected runs in flight less what the oldest has run, up to its own expected run. A committing or waiting thread's own pass leaves a held batch to the scheduler's thread, which it wakes. Tests: unit tests of the expected run and the flight (tests/unshared_hold.rs), among them a queue whose batches drop from 30 ms to 1 ms let have two in flight again within five; device test queue_share_device::an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work, both values. The wait-counting test runs under Off. The queue_share example takes --isolation and reports the application's GPU-busy share and the GPU's idle share. API signatures re-blessed. |
||
|
|
614d97a5b0 |
Runtime: count what an unshared queue's long waits waited behind
The compositor-isolation decision needs to know, for an unshared queue's command buffers that wait over 16 ms behind another command queue's work on a one-queue GPU, whether they wait behind many batches queued ahead or behind one long batch. Four counters, always on, for those waits: - WorkCounts::unshared_waits_over_16ms_batches_ahead: the batches in flight ahead of each on its VkQueue as its first batch took its value (timeline values past the one the host saw complete), summed; ..._most_batches_ahead the most; - ..._longest_runs_nanos: the longest run each waited for, summed, where a run is the host's view of how long the VkQueue's oldest batch in flight was so (completion seen to completion seen, or from its submission onto a VkQueue the host saw idle); - ..._behind_one_long_run: those whose longest run alone was over 16 ms. How (queue_wait.rs): each VkQueue keeps the host time its oldest batch became so, and, while a wait is timed, a sliding maximum of the runs seen since the oldest timed wait began (a deque falling from the front; a wait's longest run is its front once runs from before it are dropped). O(1) a completion amortized, plus one clock read per completion; no more runs kept than the batches the oldest wait was behind. The queue_share example gains a `frames` mode: a compositor committing one draw every --period-ms (16) beside an application keeping --in-flight long command buffers of --long-ms (30) in flight, with the compositor's latencies, the application's rate and these counts. The API signatures table is re-blessed (scripts/api-signatures/signatures.py --bless). |
||
|
|
0d66b9de2b |
with_vk_queue: the closure gets the VkDevice its VkQueue belongs to
`CommandQueue::with_vk_queue` now calls `f(&ash::Device, vk::Queue, u32)`. The device is the serving generation's, read under the queue's lock with the VkQueue. After a recovery the queue lends the new VkDevice's VkQueue. Until now a caller could get the device only from `Device::raw` handles it had cached, and after a recovery those name the lost VkDevice. The consumer's copier did exactly that: it submitted command buffers from a pool made on the lost device to the new device's queue, and the process died inside RADV (a segfault at null+0x50 in libvulkan_radeon.so, right after our "VkDevice was lost and made again" log). No call let it see the change atomically. Every call site in the runtime, its examples and the validation lanes takes the new argument. The runtime README's interop and "A lost device" sections, `Device::raw`'s docs and docs/API.md's device-recovered entry say what the closure gets. api_signatures.tsv is re-blessed (one signature changed). Test: device_recovery::a_lent_queue_names_the_vk_device_it_belongs_to_across_a_recovery. It reads the lent queue's device before and after recover_for_test. The two differ, and the second equals what Device::raw answers after the recovery. The test also asserts the old route is wrong: the raw handle cached before the recovery differs from the lent queue's device after it. That cached handle was the only source of the device under the old signature. (cherry picked from commit b4bf228df9db98a451c997f350c6014b027f7e31) |
||
|
|
7996b9a164 |
Mark a queue long by its command buffer's own GPU time, not the host's view of its head's age
What: a command queue is now marked long where one of its command buffers' own timestamps (its first batch's start to its last's end) span over LONG_HEAD (2 ms), in the completion turn that read them (CommandBufferShared::place_gpu_times), before the turn finishes it. The waiter's host-age check in command_buffer/completion.rs (HeadWatch, Device::head_watch) is removed, and went_long returns at once unless the device shares. A device whose command buffers write no timestamps the host reads (gpu_times_from_host, a driver whose timestamps wait for every queue's, or no calibrated timestamps) no longer shares: queue_switch_check::timed() gates the check, and recall settles Unchecked and counts the new WorkCounts::queue_sharing_untimed where the device has two VkQueues of one family to share. Two runtime extensions, doc-hidden, for the lanes and the probe: CommandQueue::vk_queue_sharing() (its VkQueue and long mark) and Device::shares_vk_queues(). Why: the host's view of a batch's age as its VkQueue's oldest also holds its wait for the GPU to start it and the waiter's lateness to see it complete, so short command buffers marked their queues long for good. On the RTX 5080 Laptop GPU, 2x3 runs in a slow stretch had each thread's queue marked long mid-run (at 20 ms to 1,238 ms) and settled apart, the PerQueue placement, at PerQueue's rates. Measured cause, with a diagnostic build printing each host-age mark beside the command buffer's own GPU span: beside another process's 30 ms command buffers, draws of 11 and 16 us of GPU time were seen 2.0 and 2.3 ms after they became their VkQueue's oldest, 1.8 and 2.1 ms of that before they started; that run's thread queue settled apart and ran at PerQueue's 4.1k. In the runs without contention, every true mark had a GPU span within 1.2 ms of its host age (the 30 ms command buffers and the probe's 2.7 ms sizing one); under contention the sizing command buffer's host age exceeded its span by 4.2 ms. Neither suggested alternative fits: the false marks came mid-run, not only in a queue's first command buffers, and decaying the mark after short heads would let the trap and alternating shapes' long queues rejoin and stall the compositor again. Tests: tests::queue_share_device gains a_device_that_answers_gpu_times_from_the_host_does_not_ share_and_counts_it (expected, not run, to fail without the gate on the 5080: there it printed "Unchecked ... could share: true", so the recorded Idles verdict would make it share), and asserts queue_sharing_untimed == 0 elsewhere; its isolation runs print each queue's VkQueue and mark over the run. The queues lane's a_queue_joining_another_s_busy_vk_queue_is_announced_once now makes its device under QueueSharingPolicy::Adaptive (over the lane's exact_answers()), lets the busy queue's fills be submitted first, and asserts queue_joins > 0 exactly where the device shares, saying why where it does not. cross_queue_shadows gains the signal-in-between and the waiting-writer cases on one VkQueue: no spin, Adaptive, the check settled, queue 2 joining queue 1's busy VkQueue; they assert the join, neither queue long, the hold still withheld while the waiting writer has not completed, and the bytes. Docs: QueueSharingPolicy::Adaptive, the FAST-PATHS row (the rule, the untimed exclusion, the new ranges), docs/API.md (the policy section and the notice), the queue-sharing notice's cost text, queue.rs and queue_share.rs; api_signatures blessed (additions only). Verified on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, msi, under gpu-locks, no VM), release probe: - 2 threads x 3 in flight, 10 runs each in turn: Adaptive 48.3, 28.0, 50.7, 52.9, 28.1, 53.7, 48.6, 29.9, 31.5, 53.0k against PerQueue 21.4, 24.9, 27.8, 28.0, 27.6, 27.4, 27.1, 23.3, 26.9, 27.3k, Adaptive above PerQueue in each pair; no thread's queue marked long in any run (gone long 1 each: the probe's sizing queue). The 28-31k runs keep the shared placement, with waiter parks 0.23 against 0.02-0.05 per command buffer in the fast ones: a host-side mode, not a move. - Beside another process's 30 ms command buffers, 3 runs each: the old rule 4.1k (a thread's queue marked long by its host age), 5.2k, 6.6k; this rule 6.7k, 5.4k, 5.1k (no mark); PerQueue 4.1k, 4.1k, 4.0k. There, draws' own spans reached 1.16 to 1.52 ms (timesliced), under the bound. - Isolation, 3 runs each: trap and slow-alternating 64 completions over 10 ms under Adaptive (the one first-long stall, at most 26.4 to 30.1 ms) against none under PerQueue (at most 5.6 to 9.7 ms); alternating none under Adaptive (at most 5.7 to 9.8 ms) against 7, 0, 0 under PerQueue. Unchanged from the host-age rule's runs. - 8 threads: 3 in flight 53.4k, 54.4k against 27.8k, 27.4k; 1 in flight 50.1k, 49.3k against 14.0k, 13.9k. - Device tests (debug, --cfg m2v_gpu): tests::queue_share_device 8/8, the joining lane test and cross_queue_shadows 7/7 (the one-VkQueue cases: X's and Y's queues both on VkQueue 1, neither long, holds withheld 2, gated copies in 2). The compositor isolation test, old rule and new in turn, 3 each: p99 2.66-2.94 ms against 2.16-2.83 ms, 0 stalls, the same placement (the compositor alone on VkQueue 1, the application long on VkQueue 0, gone long 1). Its one earlier failure under this rule (p99 7.93 ms, 20 stalls, 5,579 of ~9,600 commits made) ran right after a 74 s compile inside the hold, with the same placement and gone long 1: host load, not the rule. On the M3 Max (MoltenVK, no sharing), tests::queue_share*, command_queues, cross_queue_shadows, gpu_time and host_memory: 90/90. clippy -D warnings plain and --cfg m2v_gpu; RUSTDOCFLAGS=-D warnings cargo doc; fast_paths, degradation*, api_signatures, api_surface, work_counts pass. No RUNTIME_VERSION bump or pin here. (cherry picked from commit 4fd88b7564cd9cd3651543bb3f8cd529b021709e, two claims corrected to what was run) (cherry picked from commit eb0153e9d0fe6d272f2411c65f0a1ecda2c78bc2) |
||
|
|
be47523f80 |
State queue sharing's residual stall and the unshared form for queues that must never wait
What: docs/FAST-PATHS.md's queue sharing row, docs/API.md's policy bullet and the runtime README's new_command_queue_unshared entry now state the residual stall exactly: once per logical queue that goes long, for a queue that joined its VkQueue during its short phase, about one long command buffer's length. They also say a queue that must never wait (a compositor's) is made with Device::new_command_queue_unshared. The row's cost column carries the measured rates. The queue_share example's rates mode takes --threads, --in-flight and --one-vk-queue for one shape. It prints each command buffer's GPU end and commit to its completed handler, the submission, scheduler and wake counts per command buffer, and the busiest threads' CPU from /proc (Linux). Why: on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, release, 3 runs a side), the trap and slow-alternating shapes cost a shared compositor 64 completions over 10 ms, at most 29.4 to 30.6 ms, in every run, with one join each. That is the first long command buffer of the application it joined during the application's short phase. PerQueue had none in 5 of those 6 runs and 4 in the sixth (at most 3.7 to 10.7 ms). An unshared compositor had none over 10 ms in any run. No join rule built on what a queue has shown can avoid the first one: the long command buffer gives no sign before it runs. A re-pick at submission would not either: the compositor holds about 4 uncompleted command buffers at each commit (p50 commit to handler 0.78 to 0.87 ms at a 208 us period), and the stall is all or nothing in a queue's own order. So the docs name the unshared form as the answer for such a queue. The probe settled the 2 threads x 3 in flight drop (15.4k against 26.0k a second in one run): it was the lock hold's warm-up. In the hold's first runs both policies ran slow (11.1k and 10.4k), and later runs gave Adaptive 46.5k and 39.7k against PerQueue's 25.2k and 26.5k. Two queues on one forced VkQueue ran 38.1k to 46.6k under PerQueue and 41.4k to 49.9k pinned under Adaptive, so one VkQueue is not slow in the runtime's path. No runtime thread was busy in the slow runs (scheduler 10%, handler threads 5%, waiters 3%), and every shape made one vkQueueSubmit per command buffer. Verified: tests::fast_paths, degradation_catalogue and degradation_sites (25 passed); clippy of the example with all features. (cherry picked from commit b1dbea95dad3a5a156191df01084db0f86cb67a0) (cherry picked from commit 24af60dbf8175da8e60ea24f38f9103c20c23e8b) |
||
|
|
510e0c0cca |
Share VkQueues between command queues where the GPU idles at each switch, with an unshared opt-out
What: a new DevicePolicy switch, queue_sharing: QueueSharingPolicy { Adaptive (default),
PerQueue }; exact_answers() selects PerQueue. Under Adaptive, on a device whose own self-check
finds its GPU idle when consecutive work comes from another VkQueue, a command queue chooses its
VkQueue again each time it makes a command buffer while it holds no other uncompleted one (the
slot take with held.all == 1, under its slots lock): it joins the busy VkQueue of its family
whose oldest batch has run under 0.5 ms, the most batches in flight first, then the latest
submission (Device::pick_vk_queue: one pass of atomics over the round robin's VkQueues, no lock).
A queue whose batch ran over 2 ms as its VkQueue's oldest is marked long by the waiter that saw
it complete, under the completion's pending lock, before the turn that finishes it
(command_buffer/completion.rs); no queue joins a long queue's VkQueue, and the long queue moves
once more at its next idle point, to the least recently used idle VkQueue no long or unshared
queue holds. Its mark moves with it and a dropped queue subtracts its marks. Presenting queues and
a queue that lent its VkQueue (with_vk_queue, pinned from then on) never move. A queue's vk_queue
is now an atomic; everything that reads it does so between a command buffer's make and its
completion, when no move can happen.
The self-check (queue_switch_check.rs) is the runtime's own, kept like the in-place check's, not
a DriverFact row: on a thread of its own, once per driver, release and runtime, 24 rounds of two
timestamp-only batches held behind one host-signalled gate on two same-family VkQueues against
24 on one; the switch cost is the difference of the median gaps; Idles above 20 us, DoesNotIdle
below, Unchecked where the device has no calibrated timestamps, no two VkQueues of one family, or
a run failed. Its verdict is written as one record in the shader cache's content directory and
read back as the next device of the same driver, release and runtime is made. Before the verdict,
every queue keeps the VkQueue it took at creation.
Device::new_command_queue_unshared(count): a queue that never moves and that no adaptive queue
joins; a queue already on its VkQueue leaves at its next idle point. Placement where the device
shares: a round-robin VkQueue no command queue holds, least recently used first; else one no
long or unshared queue holds, the fewest queues first; else the round robin's next. Why that
order: an empty VkQueue gives isolation at once, with no wait for another queue's idle point; of
the empty ones the least recently used is the one least likely to hold a moving queue's work in
flight (a queue that just left it may still have batches there, and the unshared queue would
wait behind those); where none is empty, the least held one has the fewest queues to move off,
each at its own next idle point, so isolation arrives soonest, and a VkQueue a long or unshared
queue holds is never taken since that would put the opt-out behind exactly the work it opts out
of. A queue's claim of a VkQueue and an unshared queue's are ordered so that two at once never
both succeed: each counts itself there first, then reads the other's count (SeqCst both sides).
Under PerQueue, and where the device does not share, it is
new_command_queue_with_max_command_buffer_count. A count of 0 and a lost device are refused.
Why: NVIDIA 615.71.09 on the RTX 5080 Laptop GPU leaves the GPU idle 56 to 62 us whenever its
next work comes from another VkQueue, so one VkQueue per command queue, round robin, capped eight
threads' one-draw command buffers at 25,800 to 29,500 a second (GPU idle 60% of its time at the
switches), where one VkQueue ran 54,700 to 58,700 (the audit that set this design). Moving only
at idle points keeps every queue's own order without a cross-queue fence. The cost is the
runtime Degradation kind QueueSharing ("queue-sharing", performance), announced once per device
at the first join, in CommandQueue::command_buffer on the making thread: the first long command
buffer of a queue that shared holds the command buffers committed behind it on its VkQueue for
its whole length. The opt-out exists so a compositor never pays even that one stall.
Counted: WorkCounts::queue_moves, queue_joins, queues_gone_long, long_queue_settles,
queue_moves_off_unshared, joins_withheld_from_unshared, queue_switch_checks_run and
queue_switch_checks_recalled. The policy keys no profile (tests::fast_paths), so
SEMANTICS_VERSION does not move. Docs: FAST-PATHS row, docs/API.md (the policy and the notice
catalogue), the runtime README (the opt-out, with_vk_queue's pin), queue.rs's module doc on
isolation; REFUSALS regenerated (the new site of MaxCommandBufferCount); api_surface and
api_signatures (additions only). The example queue_share runs the workloads under either policy.
Verified: cargo clippy --workspace --all-targets --all-features -D warnings, and the runtime and
validation crates with --cfg m2v_gpu; RUSTDOCFLAGS=-D warnings cargo doc --workspace
--all-features --no-deps; nextest of tests::queue_share (the choice, settling, the unshared order,
the record), tests::fast_paths, tests::degradation*, api_surface, work_counts: 66 passed. On the
RTX 5080 Laptop GPU (release) the check answered Idles at 51.3 us, and its form measured 49.0 to
50.7 us in five more runs, where a chained form measured 53.2 to 59.3 us. The device tests
(tests::queue_share_device, runtime_lane::command_queues::a_queue_joining_...) are not yet run
on a GPU in this commit.
(cherry picked from commit a2f17a5132faf0312fb3953d634e21c927cde62e)
(cherry picked from commit 862b2cb49a9481d0a2a19fb1bc3acec79932d1bd)
|