Repository navigation
drm/asahi: g17: keep G17P render queue records firmware-cached - #3705
DjDeveloperr wants to merge 2 commits into
Conversation
linux#3170 mapped the render queue records uncached because the host rewrote them in place. Memory::set_owner retargeted a pair's records to another context of the same VM, and on G17P bind_work_slot stored the work slot at +0x38 of both records on every render submission, while the previous kick could still run. Firmware-cached G17 lines are not coherent with host stores and cannot be flushed. A dirty firmware line can revert such a store when it is evicted, and the firmware can keep reading its stale copy: the J716c QueueRecord.job_list_va revert. On the A18 Pro the uncached records cost a four-queue render row about 5% against the 7.3.0-41 kernel, which still cached them. Stop rewriting the records and map them firmware-cached again on G17P: - Only the same logical context keeps a pair's graph. Any other context, also of the same VM, gets its own graph and queue records, as on M5. The outgoing graph's VM pool mappings move out first, as M5 already does. A kept graph's records already name its context: that is checked, never written. - G17P writes the work slot into both records once, for the graph's first publication, before any kick names them. The context's render channel for the pair keeps that slot from then on. A pair whose records carry slot N takes only channel N, and waits for that channel's publications on another pair to retire, as for any channel move. A different slot is refused. Invariant: the host writes a G17P render queue record only before the first kick that names it (whole in Graph::new, the work slot in the first bind_work_slot). Only the firmware writes it after that kick. Every host-owned word in a firmware cache line therefore equals the value in memory, so the firmware never reads a stale host word, and a dirty line it evicts writes back the same host words. The pointer blocks, job list and item rings, which the host writes on every kick, stay on the uncached pages after the records. The pool zeroes a returned queue-state object only after its fence is met, as for every pooled firmware-cached family. M5 keeps its records uncached. Signed-off-by: DjDeveloperr <[email protected]>
There was a problem hiding this comment.
Verdict: HOLD at 08a29b94
Blockers:
- Hosted CI workflows (
Apple build and KUnit,Host tests,pr-text,pr-readiness) are still queued at08a29b94. - Pending second-generation / cross-variant hardware rows listed under
Not yet:- M5 (
J716c/G17Cor M5)dEQP-VK.synchronization2.op.multi_queue.*regression check (shared rebind and render-channel paths). - M4 Pro/Max (
G17P) hardware verification row (also receives firmware-cached render queue records).
- M5 (
Checked:
- Audited all 8 files (
+186/-150):drivers/gpu/drm/asahi/g17/queue/render/memory.rs:RECORD_BYTES(static_assert!(RECORD_BYTES <= POINTERS[0])) maps only the G17P queue-record pages firmware-cached while keepingPOINTERS, job lists, and item rings uncached (and all ofFamily::QueueStateuncached on M5).bind_work_slot()writesWORK_SLOT(+0x38) only once before the graph's first kick (work_slot == None) and rejects any mismatched slot (EINVAL).set_owner()is replaced by read-onlynames_owner().drivers/gpu/drm/asahi/g17/queue/render.rs&runtime/render/prepare.rs: unified per-context graph ownership (keep_graph = Arc::ptr_eq(self.context(), &context)/foreign = !Arc::ptr_eq(pair.context(), &self.context)), moving outgoing same-VM pool mappings out before installing the new graph so live records are never retargeted in place.drivers/gpu/drm/asahi/g17/context.rs,context/identity.rs,fw/queue.rs:RenderSlots::bind()/get()enforcerequired: Option<u32>viaallows(required, index)so a G17P pair whose records carry slotNonly takes channelN(covered by new KUnit testa_pair_takes_only_the_channel_its_records_carry);QueueRecord::names_owner()safely copies packed fields by value.tools/asahi/g17-object-fence-tests.py&run-host-tests.py: 5 new policy mutations enforce the M5-uncached / G17P-cached / write-once work-slot / per-context graph / pinned render-channel invariants.- Exact-head
08a29b94J700 (A18 Pro,G17P) verification:-5.2%4-queue render triangle (42.33-42.63 -> 40.17-40.28 µs),16,680sync2 +12,798sync multi-queue CTS +1,607EGL churn cases identical with 0 recoveries/faults/AVCs,262,144/262,144host-word readbacks unchanged,295/295g17 host tests and494/494asahi KUnit tests pass.
Evidence
- Code is clean with zero defects found; ready to upgrade once hosted CI finishes green and the M5 + M4 Pro/Max hardware rows land.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
A control-ring witness proves that the firmware consumed a release. It does not establish that the firmware discarded the old queue records. Recycling their backing lets the pool zero and reinitialize cache lines that the firmware can still hold across queue owners. Keep a returned queue-state object with a cached prefix in its reserved pool slot until firmware stop. No control witness makes it reusable. This keeps the mapping and its backing alive within the existing slot and byte limits. Once full, the pool supplies fresh uncached objects. Exercise successive queue lifetimes under both release policies in the host pool harness. Check distinct backing and addresses, the uncached fallback at capacity, and teardown at firmware stop. Fixes: 08a29b9 ("drm/asahi: g17: keep G17P render queue records firmware-cached") Signed-off-by: DjDeveloperr <[email protected]>
There was a problem hiding this comment.
Verdict: HOLD at 6d632d43
Blockers:
- CI checks are still queued at
6d632d43. Build, host tests (g17-object-fence-tests.py), KUnit, andpr-textruns are still queued/running (2P/0F/18Q). - Exact-head hardware verification at
6d632d43. The earlier J700 row ran at08a29b94before6d632d43changedPool::return_object()to retain cachedFamily::QueueStateobjects until firmware stop (with uncached fallback oncePOOL_SLOTSfills). Please post an exact-head6d632d43G17P verification row alongside the remaining M5 (synchronization2.op.multi_queue.*) and M4 Pro/Max (G17P) regression rows.
Checked:
- Delta
08a29b94 -> 6d632d43(drivers/gpu/drm/asahi/g17/object.rs,queue/render/memory.rs,tools/asahi/g17-object-fence-tests.py,+67/-14):Retained::fencechanged toOption<u64>withready()returningfalseforNone;Pool::return_object()setsfence = NoneforFamily::QueueState if lease.prefix != 0, closing the cross-owner firmware-cache reuse hazard where a control-ring release witness does not guarantee firmware cache line eviction.Pool::allocate()(match oldest { Some((index, _, true)) => ... }) never reusesfence: Noneentries, guarantees a return slot viainner.reserved[family_index], and falls back cleanly to deferred uncached allocations oncePOOL_SLOTSorPOOL_BYTESfills.cached_queue_lifetimes()ing17-object-fence-tests.pyexercises0..=POOL_SLOTSgenerations across bothafter_releasemodes.
Evidence
- Verified
drivers/gpu/drm/asahi/g17/object.rs:624-640,825-933, and936-988at6d632d4341c599150e7f739ff9051d27fd23e34f. - Note on steady-state behavior: after
POOL_SLOTSrender graphs have been created and destroyed on G17P without a firmware stop,Family::QueueStatecache capacity is permanently occupied by retainedfence: Noneentries and subsequent render graphs take the uncached fallback (consistent withmemory.rs:159-160).
|
FINISH, then merge at
What I checkedWithin one graph, both slot stores precede publication. Ordinary re-kicks and replay keep the slot, same-context rebind only reads the records, and recovery writes the uncached pointer blocks. The G17S/C/G render records and the compute graph covered by #3170 stay uncached. The change uses the existing firmware layout and derives the prefix from the record size, QID range and page size. Older GPU paths are unaffected. I ran the pool code from this head in the PR's host harness. With each G17P fence policy, the next allocation returned the same backing and address and zeroed the prior record. That confirms the host write. The harness does not model the firmware cache. The J700 measurements and 494 passing KUnit tests are recorded at this head. The outstanding hardware checks are the M4 Pro/Max G17P run and the J716c multi-queue run from #3170. For the G17P check, verifying the new owner's words across reuse of the same record address would test the lifetime at issue. |
|
J700 (Neo, G17P) at head Tested The boot ran three steps in order: the packet rows, then the full multi-queue CTS, then the q4 triangle again on fresh queues. The G17 capacity file was read before and after each step.
That is +5.4 %, back at main's level with uncached records (42.33–42.63). The two ranges do not overlap. Every leg passed its per-queue CRC readback. Queue-state pool (
No firmware stop happened during the boot, so retired graphs never gave their slots back. After 64 retired graphs, every new render graph gets uncached records and pays the #3170 cost again. So at this head the q4 fix lasts only until the pool fills. On this boot that took one CTS run. Correctness on the same boot:
Result: no correctness regression. The q4 gain is lost once the pool fills (+5.4 %, the same as before the fix). The before/after q4 numbers come from one boot and are not ABBA, because the pool state cannot be undone within a boot. |
There was a problem hiding this comment.
Verdict: MERGE at 6d632d4341c5
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Delta 08a29b94 -> 6d632d43 (drivers/gpu/drm/asahi/g17/object.rs, queue/render/memory.rs, tools/asahi/g17-object-fence-tests.py, +67/-14):
Retained::fencechanged toOption<u64>withready()returningfalseforNone;Pool::return_object()setsfence = NoneforFamily::QueueState if lease.prefix != 0, closing the cross-owner firmware-cache reuse hazard where a control-ring release witness does not guarantee firmware cache line eviction.Pool::allocate()(match oldest { Some((index, _, true)) => ... }) never reusesfence: Noneentries, guarantees a return slot viainner.reserved[family_index], and falls back cleanly to deferred uncached allocations oncePOOL_SLOTSorPOOL_BYTESfills.cached_queue_lifetimes()ing17-object-fence-tests.pyexercises0..=POOL_SLOTSgenerations across bothafter_releasemodes.
Follow-ups (not blocking): queued CI; exact-head G17P row (M5/M4 rows not required)
|
Row: J616s (M4 Pro, T6040) at
|
What: Map the G17P render queue records firmware-cached again, and never store to a record after a kick has named it.
Memory::set_ownerretargeted a pair's records to another context of the same VM. On G17P,bind_work_slotalso stored the work slot at+0x38on every render submission while the previous kick could still run. drm/asahi: g17: keep G17P work nodes and compute descriptors firmware-cached #3186 left them uncached for the same reason.7.3.0-41, which still cached them.tools/asahi/g17-object-fence-tests.pypins the policy with five new mutations, and a KUnit test covers the channel rule.Tested: J700 (A18 Pro, G17P), Mesa
089aeb0eprivate ICD. One-shot boots ofmaine6c7b032633cwithout and with this commit, built from one tree with the same config, 10 visits per row per boot, 8 boots in A B B A, B A, A B order. Median µs per boot; lower is better:7.3.0-41dEQP-VK.synchronization2.op.multi_queue.*gave 16,680 Pass, 7,080 NotSupported, 0 Fail.dEQP-VK.synchronization.op.multi_queue.*gave 12,798 Pass, 9 NotSupported, 0 Fail. Results were identical case for case, with 0 recoveries.dEQP-EGL.functional.{create_context,create_context_ext,multicontext,multithread,sharing,thread_cleanup}.*gave 1,607 Pass, 105 NotSupported, 0 Fail on both.+0x1cand+0x94;+0x1cshares a cache line with the work slot andjob_list_va.tools/asahi/run-host-tests.py --only g17295/295,neo-auxiliary-tests3/3,legacy-wq-prepub-abort-tests10/10. The asahi KUnit suites on arm64 QEMU: 494 pass, 0 fail.checkpatch.pl --strict: 0 errors, 1 warning (a 101-column line). It is kept so this head stays byte-identical to the testedaurora.ko.6d632d43, one J700 boot (row): q4 40.35 µs before the pool filled; sync2op.multi_queue16,680 Pass / 0 Fail, sync 12,798 Pass / 0 Fail; 0 GPU faults, 0 warnings.Risk: two-way door · G17P Macs (A18 Pro, M4 Pro/Max) get cached render queue records. On every G17, a context that rebinds an idle pair of another context of the same VM now builds a new graph, as M5 already did. That rebind did not occur in any of the workloads above, because a closed context's pairs are parked, and parked pairs already get new records.
Not yet:
Details
Rows not run
dEQP-VK.synchronization2.op.multi_queue.*gate from drm/asahi: g17: keep firmware-mutable pooled state uncached #3170. The rebind and render channel code is shared with M5.Why the old writes were unsafe
Firmware-cached G17 lines are not coherent with host stores, and G17 has no firmware cache flush. If the firmware holds a record line dirty, a later eviction writes its stale copy of a host word back over the host's store (the J716c
job_list_varevert). It can also keep reading that stale copy. On G17P the firmware writes+0x1cof a render queue record, which is in the same line as+0x10(job_list_va) and+0x38(work slot).What changed
queue/render/memory.rs:Family::QueueStatemaps its first pages, which hold one record per QID, firmware-cached on G17P.bind_work_slotstores+0x38only while the graph has no slot yet, and refuses a different slot afterwards.set_owneris replaced by a read-only check that the kept records name the context.queue/render.rs,runtime/render/prepare.rs: only the same context keeps a graph. For a same-VM rebind the outgoing graph's VM pool mappings move out first, as on M5.context.rs,context/identity.rs:RenderSlots::bindtakes the slot the pair's records carry.fw/queue.rs:QueueRecord::names_ownerfor the check.Per-boot medians (µs)