RUNTIME 2249: a recovery's carry of pooled ICB records waits out the setters' unlocked writes; getters hold the overflow slots; reset GPU time counted

RUNTIME 2225 and 2242 let an indirect command buffer's setters write without the lock. RUNTIME
2247 put the records in the runtime's own imported pages wherever the device imports host
pointers, so every carry there keeps the pages, the pointer and the records (Kept; the carry's
forget_keys sends the next named set under the lock), and an unlocked write needs no tracking.
Records that still lie in pooled memory (a device without host-pointer import, or a failed
import) move at a recovery (Lost, every command reset), and an unlocked write could hold their
old pointer across the carry's release: a use-after-free.

- Pooled records only: each unlocked setter call counts itself with one read-modify-write
  (decided per ICB at creation, counted_write #[cold]); the carry waits the count out before it
  releases the old parts. Own-pages records write as before RUNTIME 2247, behind one branch.
- A getter's read of the slots past the records (overflow) holds their parts, as record reads do.
- WorkCounts::indirect_record_reset_gpu_nanos: the GPU time of each resetCommandsInBuffer
  dispatch, timed with the rate-map pieces' timestamp slots (a third kind), read when the command
  buffer lets go of what it retained; no sync added; 0 where timestamps are absent or wait for
  every queue's.
- set_each's setters run inlined in its loop (#[inline(always)] on set_one): the consumer saw the
  set passed by pointer read wide after narrow writes (a store-forwarding stall).
- HOWTO: each live ICB's records are one held import.

Verified (carryrace, 13fd624294 on 31a07f2867, msi lavapipe):
- Suite 27209: 92/92 (ICB carry race, reset timing, rate-mapped, indirect, executions, device
  recovery, fresh pages, no pointer import, recycling); pooled tests print Lost, own pages Kept;
  the reset timing read 0 ns for a copy alone and 1.28 ms for a reset.
- Negative controls: with the count off, the carry-waits test fails (the recovery ended while an
  unlocked write held the records' bytes); with bytes read at batch creation and no getter hold,
  the unlocked-set and getter tests crash (SIGSEGV).
- Bench 27171 (Core Ultra 9 275HX, one core, least of 3 passes), 256 commands, development
  before 2247 / 2247 / this: compute set_compute_command 70.8-74.8 / 70.8-72.4 / 71.2-71.9 ns;
  full slot 95.9-106.1 / 98.1-100.6 / 102.4-105.8; draw only 32.4-33.5 / 32.4-32.9 / 33.3-34.0.
  Pooled path with the count +35 ns a command. Inlined set_one: batched render rows -10 ns, compute
  -3 to -4 ns. Submissions with 0 / 64 / 256 live ICBs: 104.8 / 99.6 / 100.3 us median.
- API tests 15/15, rustdoc 0. Clippy's only errors at this base are development's 2248 lints in
  render.rs and render/fan_out/tests.rs, untouched here.

RUNTIME_VERSION 2248 -> 2249.
This commit is contained in:
Anees Iqbal committed 2026-11-13 16:38:21 -08:00
1 parent 31a07f2867
commit cbd2898434
16 files changed
+940 -154

No files matched your search

+4 -1
View File
@@ -5077,7 +5077,10 @@ each item named states the rule in full.
may not have written, takes no lock: a buffer slot, a draw, dispatch or barrier the CPU's
writes added already, and a pipeline state the command names already, which is not held
either. Each command's first set of a state, and every set after a device recovery carried
the buffer, takes the lock and checks the state.
the buffer, takes the lock and checks the state. Records in the runtime's own pages, as they
are on a device that imports host pointers, are the pages a recovery's carry keeps, so such a
write needs nothing more; in pooled memory, which the carry moves, the carry waits for such a
write under way, and one begun during the carry takes the lock: an atomic add a write.
- **A command's read-back answers Metal's private getters**: `command_type`, the buffer addresses
and attribute strides, as Metal's `get*` getters answer them. `IndirectComputeCommand` and
`IndirectRenderCommand` read one field of their record alone (`command_type`, `has_barrier`,