After RUNTIME 2465 a rebind racing an encoder call on another thread is
detected and the encoder encoded again; one the runtime cannot encode again
(a compute encoder its predication unit reaches past, one that left a
GPU-written indirect dispatch to its host step, a render encoder that keeps
no log) failed EncodedUseRebound at submission instead, which a consumer's
answer table treats as fatal.
The protocol: those encoders' calls are gated, so no publish overlaps one.
- Rebinds gains `calls` (gated calls under way). A gated call begins
(`Holds::begin_call` -> `CallGate::enter`): calls += 1, then reads `open`;
where a publish is open it backs off and waits for it to close
(`wait_published`), before it reads anything of a buffer over host pages.
- A rebind's publish now opens before its replace (`Rebinds::quiet_calls`):
open += 1, then reads `calls`; where a call is under way it waits for the
calls to end (`drain`/`drained`), up to CALLS_DRAIN (2 ms), and is refused
past it (EncodedUses, Unreplaced::Calls), never failing the encoder later.
The four accesses are SeqCst (a store-buffering handshake: of a rebind and
a call that meet, at least one reads the other's rise), so each gated call
reads the buffer wholly before the publish (holding it, which refuses a
rebind until its commit) or wholly after its close. Chosen over the
registry lock: the call side costs two atomics and takes no lock.
- Which encoders: every compute encoder, and a render encoder that opened
with no log. A compute encoder can become unreplayable mid-encoding (the
call that records predication, a loop's record, an unbalanced record that
leaves work out, a later encoder of its unit that lays a loop, a dispatch
left to its host step), after earlier calls ran: a gate that started at
that transition would leave those earlier calls racing. So the gate covers
a compute encoder from its open. Blit encoders always log, and render
encoders with a log, stay re-encodable and pay nothing new. A device with
no buffer over host pages pays one Relaxed load per gated call (`any`).
- Nesting: a thread-local depth, so a call an encoder's call makes of its own
public calls (a blit's unlogged calls, a loop's copies) never waits.
- WorkCounts: rebinds_refused_calls_in_flight (the retry rate),
encoder_calls_held_by_rebind, and encoders_raced_unreplayable (raced
encoders committed with no log: each fails EncodedUseRebound; zero now).
Deadlock audit, extending 2465's, by lock:
- `drain`: taken by a rebind waiting for the calls (no other runtime lock
held: rebind_host_pages holds no lock across replace) and by a gated
call's end, which holds none of the runtime's at its end. Nothing is
taken under it.
- `buffers`: `unopen` takes it alone to lower `open` and notify `closed`
(so a waiter between its check and its wait cannot miss it); a gated
call's back-off waits on `closed` under it, holding at most its render
deferral's `lowerer` lock (lowerer -> buffers is the order holds already
take). No publish step takes `lowerer`; the rebind's `lower_all` runs
before the publish opens.
- The rebind's wait for calls is bounded (2 ms), so a gated call under way
that waits on a thread held at a gated begin (a render end waiting for
its lowering) ends in a refusal, not a deadlock. A gated call waits only
as it begins, never under way, and the publish waits for nothing an
encoder holds (2465's audit), so every begin's wait ends when the open
publishes close.
Docs: the Safety text of Buffer::rebind_bytes_no_copy and
Heap::rebind_bytes_no_copy, the rebind.rs **Other threads** bullet and
RebindProblem::EncodedUses state the new outcome: refused, never failed
later, for the gated kinds. api_signatures.tsv gains the three fields.
Tests (src/tests/rebind_races.rs): a pause-point control (a predicated
dispatch, Unlogged::Predicated, held at its hold while the main thread
rebinds: the rebind refused, the command buffer completes over the old
page, refused-for-calls 1); the threaded run gains a predicated family and a
host-step family (an indirect stage-in region, Unlogged::Segments), and
asserts encoders_raced_unreplayable == 0.
Follow-up in the same landing (cc0b4592a3): Rebinds: the refusal reason carries no pages (clippy: field never read).
Unreplaced::Held and Unreplaced::Calls no longer give the new pages back:
replace drops them once the registry's lock went (unopen drops the guard
first), as the caller's map_err dropped them before. Also the docs of the
encoded-use-rebound notice (degradation.rs, docs/API.md) and the runtime
README say which encoders still fail it after a race (a blit or logged
render encoder whose commit failed it, or whose encoding again a call that
answers otherwise refused) and that gated calls never race.
Verified: m3-max-37298 (msi) clippy at ec3cbb49c7 failed on exactly these
two fields; the next job checks this commit.
Checks (lane rebindsafe2): clippy plain (runtime, all targets, all features) 0 at cc0b4592a3 in m3-max-37302; lavapipe rebind/detach/host-page/host-step/indirect/predication/pending/holds suites with the gated control and the six-family threaded run in m3-max-37299 (ec3cbb49c7, same library code), the gate-off negative control, clippy GPU/CPU-ICD cfgs and rustdoc follow on development.