The accepted difference said the work that needed such a making fails; what
that work's command buffer then answers was not run. It now says what was run:
the making answers that the process is exiting.
Verified: docs only.
On the M3 at f0dc6c582e, handler_work_exit (an exit handler that commits a fill
and waits for it) ended its child with a panic in 11 of 20 exits (m3-max-17246):
'cannot access a Thread Local Storage value during or after destruction', in a
function that cannot unwind, so an abort. On macOS exit destroys the exiting
thread's thread-locals before it runs the exit handlers, and the commit's
scheduler pass dropped a passing hold, whose drop read the thread's LEFT (what
its holds left to run): m3-max-17270's backtrace (PassingHold::drop from
submit_before_waiting in commit_at_exit). It failed where the thread had touched
LEFT before (its thread-local registers its destructor at first use).
Where those thread-locals are gone, the thread is ending: a passing hold's drop
finds nothing left; a message the device's sink gets inside a hold is delivered
at once; a program's release inside one is kept unrun, as the exit keeps the
program's releases; and the thread is no handler thread (contexts::POOL, which
a wait and a pool's stop read).
Verified: cargo fmt only locally; build and runs are potluck jobs.
On the 3090 at 778f661e74 (m3-max-17210) handler_work_exit still failed 20 of 20:
after the program's handler, its making's registration and one more, a
section's first calls. The priming records the entry points it calls in its own
set (to check it made them all) but told the guard only of those made inside
sections (its releases), so a later section's call of an entry point the priming
had made outside one still counted as its first, and registered the hook again
after the handler, closing the guard before it.
exit_guard::primed takes the priming's set as it ends, before the device
registers: those calls are the first since the load (before_priming), and the
statics they made have their destructors run after the hook. A section's first
call of an entry point the priming did not make still registers the hook again.
Test: exit_guard's a_device_s_primed_calls_register_the_hook_no_more (43; 42
with the priming's calls unreported).
Verified: cargo fmt only locally; build, lint and runs are potluck jobs.
The exits lane's handler_work_exit, on the 3090 (m3-max-17150, with the section
count rule gone): after the program's exit handler, its first pipeline making
ended a section whose calls (vkGetPipelineCacheData, vkCreatePipelineCache,
vkCreateComputePipelines) counted as first calls, so the hook was registered
again after the handler, which then found the guard closed. The device's
priming had made those calls, but register_device forgot every call made so far
as it registered the first device after a load, after the priming, so each
entry point's next call counted as its first again.
A layer reloaded with an instance makes its statics again at each entry point's
first call after the load: the priming's, which come before the device's
registration. So before_priming forgets the calls where the device will register
as the first after a load (Devices::at_load, the rule admit uses), and the
priming's calls count; register_device forgets nothing. An entry point the
priming did not call still registers the hook again at its section's end.
Test: exit_guard's a_device_s_priming_makes_the_first_calls_since_a_load (a
forked child primes, registers, registers a handler, then calls the primed entry
point again: the handler runs before the hook, 43; 42 with the forgetting at
the registration).
Verified: cargo fmt only locally; build, lint and runs are potluck jobs.
An exit handler a program registers once its device is made (the consumer's exit
gate) commits work at exit and waits for it, as Metal's exit runs it. The runtime
registers its hook again after every pipeline making, for the destructors the
driver's compiler registered in it (the 5080's SIGSEGV in libnvidia-glvkspirv.so,
lavapipe's LLVM destructors), so with any making after the handler the hook ran
first, closed the guard, and the handler's wait answered Exiting: the exits
lane's handler_work_exit failed 3 of 3 on the 3090 (m3-max-17079).
Each registration now carries what it follows (exit_guard::After: the argument
of on_exit on glibc, of __cxa_atexit elsewhere), and its run ends what the
destructors registered just before it may break:
- after a making (pipelines_made, the 2 ms registrar): the run ends the makings
(Guard::end_makings) and waits for those in progress in sections, at most
MAKING_BOUND, as the close did; no making begins after, on any thread
(driver_making answers None, and the makings' callers WaitWouldDeadlock of
DeadlockCause::Exiting). The guard stays open, so the program's handlers
registered before that making run with the runtime's threads.
- after a device, an instance or a section's first call: the full close, as
before.
- beside a live CPU device (lavapipe, SwiftShader), whose queues compile as they
run their work, a making's run is a device's (the close): measured before, a
queue's compile beside the exit's destructors ended 5 of 300 lavapipe exits.
handler_work_exit expects that there (hook_ran=1, Exiting), and docs/API.md
records it as an accepted difference, with the making a handler begins.
Tests (runtime, exit_guard): a_making_s_run_of_the_hook_leaves_the_program_s_
handler_the_guard_open, the_device_s_run_of_the_hook_closes_the_guard_after_a_
making_s_run, a_making_s_run_of_the_hook_closes_the_guard_beside_a_cpu_device,
the_makings_end_once_those_in_progress_ended_and_none_starts_after,
a_making_s_run_ends_the_makings_alone_in_its_own_process; the makings' earlier
tests keep their meaning (a_pipeline_making_that_returned_registers_the_hook_
again now sees the makings ended and the guard open). The exits lane's
handler_work_exit is the contract test.
Verified: cargo fmt only locally; build, lint and runs are potluck jobs.
The exits lane's handler_work_exit: a child registers an exit handler once its
device is made, as a program (and the consumer's exit gate) does, then makes a
pipeline on its own thread and exits. The handler commits a fill of a shared
marker and waits for it. Metal runs that work to completion; the runtime's hook,
registered again after the making, runs first and closes the guard, so the
handler's work stays pending. The test fails until the hook's later
registrations leave the program's handlers the guard open.
Verified: cargo fmt only locally; build and runs are potluck jobs.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
A consumer measured Metal Private buffers at 13-14.6 GB/s on an RTX 5080 Laptop against 255-306
for Managed, and the memory log could not say which kept block each took. Investigated and closed:
not a placement bug. Private took kept dedicated blocks of device-local type 1 (LOG_MEMORY on the
3090, m3-max-17108); the slow passes were the driver's power management after a 3 s idle: on the
5080 (m3-max-17125, exclusive, nvidia-smi at 50 ms) per-pass GPU time sat on 28, 15.5, 1.0 and
0.69 ms levels tracking the memory clock (P8 405 MHz .. P0 14001 MHz), stepping down mid-stage
with the same blocks and no WorkCounts change; the 2080 shows the same steps (17175).
- memory.rs: METAL2VULKAN_LOG_MEMORY logs "took a kept dedicated block for <class> ... of type N"
(memory_log.rs, env_vars.rs, docs/API.md).
- memory.rs: placement_order, one order shared by place() and allocate_exported(); no behaviour
change.
- Tests: the kept-block order on the 5080's memory types (a system-memory kept block is reached
only after the device-local types fail, 17126); managed_copy_device's Managed no-copy over a
copied buffer's bytes through an import, pages alone and vouched pages with a refusing gate
(DeviceCopy, no write undone, the GPU's bytes reach the pages; 17176, 17218: 21/21 on the 2080);
host_ram_copy_device's Managed no-copy over a copied guest-RAM run (17242).
- examples/private_bandwidth.rs: 256 MiB pairs per storage mode after an idle, per-pass wall and
GPU times, WorkCounts deltas and host backing.
Verified: lint (fmt, clippy three ways, rustdoc) at the tip (m3-max-17267); lavapipe runtime suite
2184/2184 at the same code minus a test-only fix (17225).
The 2080 run (m3-max-17218) showed a Shared no-copy buffer over one run
inside a chunk bound in the chunk's import (InHostRam) whatever the gate
answers, so the one-run case never made the copy the check asked for. The
copy now comes from two runs, as a_copied_backing_over_the_pages does, and the
one-run case checks a Managed buffer over a run bound in its chunk instead:
both must be two copies.
A consumer's Managed no-copy buffers come over pages it vouches writable
(HostMemory::assume_writable) with a gate that may refuse their import. The
copies leg and the over-a-copy leg gain that route (Route::Vouched), and both
check that no completion took the pages again (managed_writes_undone) and that
a GPU write reaches the pages at a synchronize_resource.
host_ram_copy_device gains the guest-RAM shape of the over-copy check: a
Shared no-copy buffer over a RAM's run, one run or two, whose import the gate
refuses with its chunk not imported (a copy), then a Managed no-copy buffer
over exactly the same bytes and runs. On a device without unified memory it
must be two copies (DeviceCopy, one device copy, none in a copy or in place)
and read the pages' bytes. over_ram gains an options form (over_ram_as).
Not run yet.
A Managed no-copy buffer over pages the process maps read-only, whose import
the gate refuses, is two copies whose GPU writes are dropped: each command
buffer's completion copies the pages in whole again (managed_copy.rs). The
over-copy sequence gains such a pair, its check expecting the pages' zeros,
so its per-pass cost and WorkCounts (managed_write_undone,
managed_bytes_copied_in) can be read next to a consumer's.
The 2080 run of the over-copy sequence (m3-max-17175) already showed a
Managed no-copy pair over a copied Shared buffer's bytes as DeviceCopy at
403.6 GB/s, the speed of a plain Managed no-copy pair.
The private_bandwidth example gains an over-copy sequence: a Managed no-copy
pair, each over exactly the bytes of a live Shared no-copy buffer whose
import a refusing gate made a copy, beside a plain Managed no-copy pair and a
Shared pair over a copy's bytes. Each BANDWIDTH line names the first buffer's
host backing.
managed_copy_device gains the same shape as a device test, through an import
and over pages no import maps: the Managed buffer is two copies (its device
copy in device-local memory), lies in no copy, and reads the pages' bytes.
Not run yet: the device test needs a discrete GPU.
placement_order is the walk both callers chained by hand: the class's
candidates, then the types it overflows into, each marked so. Behaviour is
unchanged (an empty order returns the same OutOfMemory the early return gave).
tests::memory::a_private_placement_takes_a_kept_block_of_a_device_local_type_first
takes the RTX 5080 Laptop GPU's memory types (vulkaninfo on msi, NVIDIA
615.71.09, job m3-max-17046), every type allowed, and kept 256 MiB dedicated
blocks in pools of types 1 (device-local) and 3 (host-cached system memory),
as a released two-copy Managed pair leaves them: a Private placement's walk
takes the type-1 block, and the type-3 one only as an overflow once no
device-local block is kept. It passes at the base: a kept block of a system
memory type does not take a Private placement while a device-local one can.
Not yet run.
As a guest's Metal buffers come: Shared ones over its pages, Managed ones made
with a Shared no-copy buffer over pages beside each, then Private ones at
pinned addresses, three seconds waited between a pair's release and the next
making. The counts each pair's first timed pass and its last moved are
printed.
METAL2VULKAN_LOG_MEMORY's registry entry and docs/API.md now name the line
the log writes where a placement takes a kept empty dedicated block, which
allocates nothing (memory.rs's place_kept_dedicated).
Shared and Managed buffers over pages of the example's own, then Private ones
at pinned addresses and of a length, each with option bit 20 as a guest's calls
carry it. Run on the RTX 3090 before this (job m3-max-17005): every Private
pair lay in device-local type 1 at 834 GB/s GPU time, as Managed.
private_bandwidth (not a consumer's example) makes two 256 MiB buffers of the
runtime's own memory as a program makes them (new_buffer, or
new_buffer_with_descriptor at a picked or a pinned address), each pair after
earlier pairs of each storage mode went in the same device, fills them once by
a blit, and times a kernel reading one and writing the other, one dispatch a
committed and waited command buffer: GB/s by wall time and by GPU time, with
the memory counts the making moved. It reproduces a Private buffer's slow
kernel on a discrete GPU.
The memory log said nothing where a placement took a kept empty dedicated
block, which makes no block: it now names the block and its memory type.
Not yet run.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
The pin 38 round's NVIDIA regression (runtime_lane::exits::an_exit_runs_no_handler_beside_a_cpu_
device_s_work took 10 s on the 3090 and the 5080): exit_guard registered its hook again each time
the sections' count reached a power of two, a rule no seen failure was behind. Where that crossing
fell after an exit handler the program registered after making its device, the hook ran first,
closed the guard, and the program's handler found its work never submitted. Pin 38 shifted the
count so the 2^15 crossing landed near the case's last commits. The rule is gone; the evidenced
triggers (a device, an instance, a load, a first call of a table entry point, a making) stay.
Verified (potluck jobs): rule on 13 of 60 runs failed on the gem10 3090 (m3-max-16999 5/10 quiet,
7/30 beside lane load; 17079 1/20), every failure one registration after the gate; rule off in the
same build 0 of 20. At the fix, lavapipe with the validation layer (17131): exit_guard unit tests
48/48, cpu_work_exit 20/20 with no registration after the gate, the whole exits lane (making_exit
and first_making_exit included) 3 of 3 iterations. The 3090 (17143), M3 (17142) and lint (17144)
runs were in flight at landing.
The exits lane's cpu_work_exit failed on the RTX 3090 since pin 38 (round leg
3090:lane 1/4, and the 5080's m3-max-16772): its gate's exit handler, registered
after the device as a program registers its own, found the hook already run, so
the work it released stayed pending and its 10 s wait for the submission ran out.
The hook had been registered again after the handler by a section whose count in
the process reached a power of two (the lane's since=1: no making, device,
instance or load between the handler's registration and its run). Which
crossing lands after the handler moves with the sections the process runs; pin
38's changes moved it there in about one exit of four.
That rule had no failure behind it (the module docs gave it for statics a later
call might make with new parameters), and it fires again for the process's
whole life (2^16, 2^17, ...), each time putting the hook ahead of every exit
handler the program registered before. Removed: a section registers the hook
again only after the first call of an entry point of the table (at most one per
entry point at each load). The makings', devices', instances' and loads'
registrations, each with a measured failure behind it, are unchanged.
Tests:
- exit_guard: sections_of_entry_points_called_before_register_the_hook_no_more
(1024 sections of an entry point called before, after a destructor's
registration: the destructor runs first, 43; 42 with the rule). The power of
two test goes, and the first-call tests no longer step around powers of two.
- Registrations::section_bound drops its 64.
- The exits lane's cpu_work_exit now asserts since=0 (the hook registered
nothing after its gate's handler).
Measured before, on the 3090 (gem10, NVIDIA): 13 of 60 cpu_work_exit runs failed
(m3-max-16999: 5/10 quiet, 7/30 beside lane load; m3-max-17079: 1/20), every
failure since=1; with the rule switched off in the same build, 0 of 20, since=0
in all. Verified: cargo fmt only locally; build, lint and runs are potluck jobs.
The case's gate handler, registered last before the exit, must run before
the device's exit hook. In the pin 38 round it ran after it on an RTX 3090
and the RTX 5080 (hook_ran=1, scheduled=0) and waited its 10 s bound for a
submission the closed guard never makes. The handler now reports how many
times the hook was registered again after its own registration and the
process's registrations by kind, and does not wait once the hook ran; the
child prints the queue-switch check's state at the gate; the parent fails
at once on any registration after the gate's handler.
dcs_mark writes a green of 0.5 and its second color's y of 0.5, which dcs_read writes; in a
BGRA8Unorm target that is the midpoint 127.5 of a step. The classifier took only 128, Metal's and
RADV's answer, so the pin 38 round's 3090 lane (m3-max-16904) found every marked pixel '?' under
both policies. The device's own float-to-UNORM conversion is its answer (AGENTS.md rule 1); the
classifier now takes 127 or 128 for those channels.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
The pin 38 round's NVIDIA failures (5080 runtime 6; 3090 dma_buf_leak_8_threads and a
dma_buf_leak_4_threads hang). Causes and fixes:
- NVIDIA 620.70.06's vkAllocateMemory closes the fd it was handed when an import fails, which
Vulkan leaves to the application, and in 3 of 10 failed imports closes the same number twice
within one call (strace on the 2080, m3-max-16817). Another thread's file opened at that number
between the two closes was killed; a third thread's clone then imported the wrong dma-buf and
aborted on Rust's IO-safety check. Each import now hands the driver its clone at a number from a
kept range below the descriptor limit (F_DUPFD_CLOEXEC, never dup2), not shared by two imports
in flight, so a second close finds a free number; after a failure the runtime closes the clone
if it is still open, which also ends one leaked descriptor per failed import.
- Every chunk's first try was a host-visible type NVIDIA always refuses for a udmabuf; the type a
kind of import last succeeded as is now tried first (the others keep their order and are never
dropped), so steady state makes no failing import. Without it, 3 of 7 four-thread probe runs
stalled inside the driver on the 2080; with it, 8/8 on the 2080 (17077) and 8/8 on the 3090
(17065).
- A source is split into chunks only where a sparse buffer takes every type a plain one imports
as; the granule note scoped to 615.71.09 (620 asks for no split, 17073).
- The recorder keeps a slot's driver entry points when it is let go of once the process exits.
- Tests: the leak probe bounds its own run time and names the steps in progress; blocks_ahead's
hurried call excludes its making's own time; hand_out_waits names its timing assumption.
Verified: 2080 (m3-max-17076) and 3090 (17024) 15/15 touched tests; CPU before-run (17034): the
slot test and the handed-descriptor tests fail without the fixes; lint three ways + rustdoc
(17066). The 5080 confirmation (b5080 t2 m3-max-17063, then c2) is still queued.
On NVIDIA the leak probe could run without end. On the RTX 5080 Laptop GPU (615.71.09, round job
m3-max-16620 at 600b535875) dma_buf_leak_one_thread_imports_another_frees ran 1139 s, until it
was killed, and the eight threads' first round took 379 s. On the RTX 3090 (620.70.06, round job
m3-max-16792) dma_buf_leak_4_threads ran past 540 s; a wait failed at 505 s, and the test ended
on SIGTERM at 1121 s. The cause was a failed dma-buf import spinning inside vkAllocateMemory
while holding the driver's lock (docs/FAST-PATHS.md, known gaps). Whatever the cause, a probe
must bound its own run time.
- DMA_BUF_LEAK_DEADLINE_S (60 s by default) bounds the rounds' time. Once it has passed, each
worker makes no more buffers, the round ends as any round does (its buffers freed, its waits
and checks made), no round follows, and a line says so.
- The rounds run on a thread of their own. Where they are still running TAIL (120 s) past the
deadline, the test fails at once with the workers' steps in progress (a buffer's making, a
free, a wait for a command buffer) and how long each has run. It leaves that thread to the
process's end.
- Each round's line now gives its time and the workers' time in makings, frees and waits, in
all and at the longest.
Verified on NVIDIA 620.70.06:
- The bound at work, before the type order of the previous commit: on the RTX 3090 (potluck
m3-max-16941) dma_buf_leak_4_threads stalled again, and the bound failed it at 185.6 s, naming
"a buffer's making for 168.4 s" for each of the four workers. dma_buf_leak_8_threads passed in
70 s, its deadline cutting round 4.
- dma_buf_leak_one_thread_imports_another_frees passed in 24.6 s there, and in 16 s on the RTX
2080 alone (m3-max-16811). The 5080's 1139 s therefore looks like the same stall, not a slow
run.
- At this tree, every round ran within the deadline. On the RTX 3090 (m3-max-17024) the four,
eight and one-thread probes passed in 39.6 s, 64.9 s and 15.5 s. On the RTX 2080
(m3-max-17076) they passed in 31.2 s, 58.2 s and 13.8 s.
dma_buf_leak_4_threads ended in SIGABRT and dma_buf_leak_8_threads in a GPU recovery
(GpuRecoveryVictim) on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, round job m3-max-16620 at
600b535875). On the RTX 3090 (620.70.06, round job m3-max-16728) dma_buf_leak_8_threads ended on
Rust's I/O safety check, with "owned fd already closed" in import_dma_buf's drop of its clone.
The cause is the driver's handling of a failed import. NVIDIA lists a udmabuf of host pages as
two memory types, 0 and 4 (host-visible, coherent, cached), and refuses every import as type 4
as out of device memory. The runtime ranked type 4 first. strace -f -k under the eight-thread
probe on the RTX 2080 (620.70.06, potluck m3-max-16817) showed that every failed import closed
the descriptor it was handed. Vulkan gives the descriptor to the driver only on success. In 3
of 10 failed imports the driver closed the same number twice within the one call, with two
more opens of /dev/nvidiactl between the closes. The kernel gives a new descriptor the lowest
free number, so between the two closes another thread's new udmabuf took the number, and the
second close closed it. That thread then imported a third thread's dma-buf under the number,
and the process aborted on the I/O safety check.
- handed_descriptor.rs: an import hands the driver a clone at a number kept for imports in
flight. The range is the 64 numbers below min(soft RLIMIT_NOFILE, 65536). The clone is taken
with fcntl(F_DUPFD_CLOEXEC, n) and kept only where it landed on n itself, never by dup2, and
no two imports in flight hold the same number. So a number the driver closes stays free until
the import returns, and a second close reaches nothing. After a failure, the number is still
the import's alone, so whether the driver left it open is read without a race and, where it
did, it is closed. That also ends the leak of one descriptor per failed import on a driver
that leaves it open. Where the limit is under 256, the process holds the range itself, or
more than 64 imports are in flight, the clone is an ordinary one: correct, but unprotected,
and a failed import lets it go rather than close a number that may be another's by then.
- memory.rs: each kind of import (what it backs, and its memory class) remembers the type it
last imported as, and the next import of that kind tries that type first (worked_first). Every
other type is still tried after it, in today's order. In steady state this avoids the import
the driver refuses, along with its closes and the stall below.
- docs/FAST-PATHS.md, known gaps: the type listing and refusal, the closes, the kept numbers and
their fallback, and the stall. A failed import can spin inside vkAllocateMemory holding the
driver's lock: 3 of 7 four-thread runs on the RTX 2080 alone, and one on the RTX 3090. It
stays open for the first imports of each kind, which still try type 4.
- tests/dma_buf_fds.rs (device test): what a driver does with the handed descriptor, for each
type, size and form. It checks that no number the driver let go of is closed again later. A
let-go number is taken by F_DUPFD_CLOEXEC and watched only where the clone landed on it.
Tests: handed_descriptor (CPU) drives Handed with stand-in imports. One driver closes the
number twice with another thread's open between the closes. Another leaves the clone open on a
failure. Imports in flight each hold a number of their own. A test covers the range for low,
high and unlimited limits. Two cover the fallback: the clone with no number kept, and a range
the process holds itself. memory::a_dma_buf_import_tries_the_type_its_kind_last_imported_as_first
covers the ordering.
Verified:
- The handed_descriptor tests fail with ordinary clones (potluck m3-max-17034, a scratch commit)
and pass with the kept numbers on CPU (m3-max-16978) and in the RTX 3090 (m3-max-17024) and
RTX 2080 (m3-max-17076) runs, NVIDIA 620.70.06. Each of those runs passed 15 of 15 touched
tests. dma_buf_leak_4_threads ran its five rounds in 39.6 s on the 3090 and 31.2 s on the 2080,
and dma_buf_leak_8_threads in 64.9 s and 58.2 s. dma_buf_fds on the 2080 took 12 numbers the
driver let go of: none was taken by another descriptor first, and none was closed again.
- The stall, with the type order: eight four-thread runs in a row ended 8 of 8 on the RTX 2080
(m3-max-17077) and 8 of 8 on the RTX 3090 (m3-max-17065). Without it, 3 of 7 stalled on the
2080, and the 3090 stalled in m3-max-16941. The kernel logged 28 and 30 refusals of the
host-visible import over the eight runs (3 to 4 a run): the first imports of each kind.
- Lint: clippy with all features, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, and Rustdoc,
all clean (m3-max-17066).
The type comparison that ee9abd03dd added to Device::sparse_granule changes the answer on
NVIDIA 615.71.09 (the RTX 5080 Laptop GPU of round job m3-max-16620, which asked for a split it
could not import). It does not change the answer on 620.70.06. On the RTX 3090, a scratch commit
without the comparison still asked for no split (potluck m3-max-17073: 20 cycles, 20 imports,
no sparse buffer), because an earlier condition fails there. ee9abd03dd's "with the change,
620.70.06 asks for no split" is true, but the change is not the reason. The docs now name the
driver each statement was seen on.
Two timing tests failed on the RTX 5080 Laptop GPU inside the runtime suite (NVIDIA 615.71.09,
round job m3-max-16620 at 600b535875). In both, the test's bound was wrong, not the runtime.
blocks_ahead::a_creation_that_needs_a_block_whose_making_waits_for_quiet_waits_for_its_allocation_alone
failed with "a creation call waited 53.389074ms, out to the making's wait for quiet". The call
the test holds to QUIET_MOST is the one that cut a making's wait for quiet short. That call then
waits for the making itself: a 64 MiB block's allocation, which the driver takes as long as it
takes. The bound counted that allocation as if it were a wait for quiet. The ready thread now
times each making once its wait for a burst's end is over (ready::Made::making). AheadBlocks sums
the times of the makings a call waited for (waited_making). Both are test-only fields. The test
holds the hurrying call's time less its making's own to half of QUIET_MOST, and every other call
to QUIET_MOST. The test's doc states the assumption: the host runs the test's thread within
QUIET_MOST.
hand_out_waits::a_hand_out_makes_its_own_first_work_without_waiting_for_another_queue_s_work
failed at 80 s. The test times its fills alone and predicts the busy work's length from them.
Beside the dma-buf leak probe's GPU work, a fill timed 1.59 ms, and the busy work of 378 fills
was done within 270 ms of the 601 ms they predicted. Each hand-out's staging submission waited
133 ms for the GPU, so the hand-outs returned after the busy work. The module docs now state the
assumption: the GPU runs the test's work alone. Where a hand-out finds the busy work done before
half the predicted time, the test says that assumption failed rather than that the hand-out
waited. The check rounds already run it alone (the GPU-time list).
Verified: both pass on the RTX 2080 (potluck m3-max-16811; blocks_ahead again in m3-max-16901,
where the hurrying call took 1.47 ms, 1.25 ms of it its making's own, 0.22 ms beside) and on the
RTX 3090 (m3-max-16941: 1.41 ms, 1.23 ms, 0.18 ms), NVIDIA 620.70.06.
dma_buf_cycles_several_imports failed on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, round job
m3-max-16620 at 600b535875) with "the chunks imported left: 0 right: 800". The device asked for a
split (a granule of 65536 bytes, 4 chunks a buffer), yet it made no sparse buffer and imported
no chunk. Every buffer fell back to a copy of its pages. The test's line said "the device binds
no sparse buffer over dma-bufs", which was wrong: a split had been asked for.
The granule was chosen from the sparse buffer's alignment alone. A dma-buf's memory types are
known only once its source has made it, so the split has to be safe for any type an import may
be of. Device::sparse_granule now asks for the memory requirements of a sparse buffer and of a
plain one, both made for dma-bufs. It splits only where the sparse buffer takes every
importable type (Memory::dma_buf_importable: allocatable, not protected, not lazily allocated)
that the plain buffer takes. There, wherever one chunk of the pages imports as a type the plain
buffer takes, each of several chunks imports as that type, which the sparse buffer takes too.
Elsewhere the granule is the request's length: one chunk, one plain buffer's import. The
buffer-making step moves into dma_buf_buffer_requirements, which serves both buffers.
importable_types is split out of dma_buf_candidates so that both use the same rule.
The test now says whether the device asked for a split. It checks that every request asked
alike, that each cycle made a sparse buffer where it split and none where it did not, and, as
before, that every chunk was imported.
Verified: with the change, NVIDIA 620.70.06 asks for no split and imports every buffer whole on
the RTX 3090 (potluck m3-max-16941) and the RTX 2080 (m3-max-16901): 20 cycles, 20 imports. RADV
on the 780M (Mesa 26.2.6) keeps its split (m3-max-16942): a granule of 65536 bytes, 4 chunks a
buffer, 20 sparse buffers.
dma_buf_leak_4_threads ended in SIGABRT on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, round job
m3-max-16620 at 600b535875). One of the two causes: once a test had failed and the process
exited, a device that dropped after the exit guard closed let go of its recorder slot, clearing
the slot's entry points, while a thread of that device's (the queue-switch check making its
objects) was still inside a section and recording through the slot. The slot's missing-command
thunk then panicked inside an extern "system" function, which aborts.
Every other path that lets go of a slot is the device's ordinary drop, which runs after the
device's threads stopped and so with no section of theirs live. Only an exit leaves sections
running past the slot's release: a section that started runs to its end. Slot::drop now enters
the exit guard; once the guard has closed it returns at once and leaves the slot as it is, with
its entry points stored and its index taken, just as the exit leaves the device to the process's
end.
Test: exit_guard::a_slot_let_go_of_while_the_process_exits_keeps_its_commands. A forked child
routes a stand-in device's functions through a slot and registers the hook. An exit handler that
runs after the hook drops the slot and records through it, and the child expects the stand-in to
be reached.
Verified: the test passes on CPU (potluck m3-max-16978) and in the RTX 3090 run (m3-max-16941).
It fails without the guard check (m3-max-17034, whose child aborts in the thunk).
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
On a driver with one graphics queue, an unshared queue (a compositor's) shares its VkQueue with
the application's queues. DevicePolicy::unshared_isolation (Bounded, the default; Off) now holds
the other queues' batches back so that an unshared batch waits behind at most about one of them:
- a batch is submitted ahead of the unshared queue's only while the work already submitted ahead
is expected to end within the bound (each queue's expected run from its batches seen complete);
- a batch of a queue with no run seen yet holds the others back until it completes;
- an unshared batch seen complete in the same completion turn as another queue's takes no share
of that batch's run;
- an unshared queue's batches never wait in a group, and no group is kept, on a held VkQueue;
- nothing is held back on a lost device, whose submissions fail at once.
FAST-PATHS records the switch, its measured benefit and its cost under host CPU load.
Measured (owned workload: an app keeping 3 command buffers in flight, a compositor every 16 ms;
Off -> Bounded):
- Iris Xe, quiet host (m3-max-16880, 16885): 30 ms command buffers: compositor p50 75 -> 17.5 ms,
p99 90 -> 37-38 ms; app 33.2-33.3 vs 33.3-33.5/s. 5 ms: p50 12.6 -> 4.7 ms, p99 15 -> 7.2 ms;
app 198.3-198.4 vs 196.4-198.0/s.
- 780M, host load 6-19 (m3-max-16900): 30 ms: p50 71-84 -> 18 ms, worst 94-114 -> 35-40 ms.
5 ms: p50 10.5-11.8 -> 4.2-5.1 ms.
- Cost under host CPU load: Iris 5 ms at load ~10, 181.8 vs 189.3/s (16885); 780M 192.4 vs
203.7/s (16900).
- Unit tests that fail without their fixes:
an_unshared_batch_seen_complete_with_another_queue_s_leaves_it_the_whole_run (22.5 ms instead
of 30 without the fix) and a_batch_of_unknown_length_holds_the_next_back_until_it_completes.
- lavapipe device test, both values: Bounded runs the unshared command buffer between the two
long ones (41.8-42.0 ms); Off runs it last (125.1 ms).
- Lint (fmt, clippy three ways, rustdoc) m3-max-16928, 16945; api/fast_paths 41/41 and lavapipe
unshared_hold + queue_share 26/26 (16929, 16937), at 37eae90024 (the same code before rebase).
Under Off the unshared command buffer runs after the third long one, and the print subtracted its
end from the second long one's start: -76.28 ms of 'GPU idle' on lavapipe (m3-max-16929). A print
only; the assertions are unchanged.
FAST-PATHS's row for unshared_isolation, API.md's bullet, the policy's Bounded doc and
unshared_hold.rs's costs now say that a batch of a queue with no run seen holds the others back
until it completes, and give the owned workload's numbers (queue_share frames --unshared, Off
against Bounded): the Iris Xe (m3-max-16880, -16885) and the Radeon 780M (m3-max-16900), the
compositor's median and worst waits, the application's rate and GPU idle on a quiet host, and the
loss under host CPU load (the hold's 2 ms of slack against Off's queued batches). Bounded stays the
default on every one-graphics-queue driver.
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.
A queue with no run seen was expected to run the 2 ms budget, so an application that commits
several command buffers at once (the owned workload keeps three in flight) put them all on the
VkQueue before its first was seen complete, and the compositor's first frames waited behind all of
them: on the Radeon 780M (gem10, m3-max-16785, three 30 ms command buffers beside a 16 ms
compositor) the switch on still left p99 48-58 ms and a worst wait of 79-90 ms, about three batches,
where the median was 17-19 ms.
Such a batch is now of unknown length: while one is in flight on a VkQueue held back for an unshared
queue, no other queue's batch goes there until it is seen complete, which gives its queue a run. It
costs one completion's turn per queue. Unit test: a batch of unknown length holds the next back
whatever it has run, and its completion gives its queue the run.
Flight::completed split the host-observed run equally among every batch the completion covered,
the unshared queue's included. A compositor's light batch submitted behind an application's is
usually seen complete in the same completion turn, so the application's batch was credited half
its run and its queue's expected run halved toward it. On the Radeon 780M (gem10, m3-max-16762,
three 30 ms command buffers in flight beside a 16 ms compositor) the hold then let a second
application batch in about halfway through the one ahead, and the compositor's median wait stayed
at one whole batch (32-34 ms, against 74-77 ms with the switch off) where about half of one is
the bound's.
The run is now shared among the other queues' batches only; an unshared batch seen complete alone
updates nothing. The unit test of a shared run now expects 4.5 ms each of a 9 ms run over two other
queues' batches and an unshared one, and a new one checks that an application's 30 ms run seen
complete with a compositor's batch keeps its 30 ms (it fails before this change: 22.5 ms).
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.
The unit test asked 10 ms where halving 20 ms toward 1 ns answers 10 ms and 1 ns (job
m3-max-16503, the one failure of its 62 tests); the profile test is the one every runtime
choice of DevicePolicy has.
FAST-PATHS: unshared_isolation's two values under the switches whose default is Metal's (not an
accuracy choice: it trades other queues' submission ahead for the unshared queue's wait); the
known gap now says what stays true under Bounded: a submitted batch runs to its end, so a
compositor still waits for the whole of a long one, and neither a second VkDevice nor splitting is
built. API.md section 5's policy list, the runtime README's unshared queue entry and
new_command_queue_unshared's rustdoc say the same.
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.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.