Repository navigation
drm/asahi: g17: reuse cached queue records after a later release - #3721
DjDeveloperr wants to merge 3 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 <hey@djdev.me>
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 <hey@djdev.me>
A returned G17P queue-state object, whose records the firmware caches, waits for firmware stop before reuse, because consuming its owner's scheduler release does not show that the firmware dropped their lines. Firmware stop only comes at teardown. After 64 retired render graphs, every new graph gets uncached records again. On the J700 one multi-queue CTS run filled the pool, and q4 on new queues went from 40.35 to 42.52 us, main's level. The scheduler release carries what the older firmware's DestroyContext did: the context page and its bytes 0, 1, 4 and 0x23 (here 0x26). That command also flushes the firmware data cache, and the older firmware's driver frees firmware-cached memory only after one (flush_fw_cache). Do the same: reuse a returned cached queue state once a release published after its fence has been consumed. Track the latest release and the latest consumed one next to the control-ring counts. The host harness checks that a release published before the return does not count, that a later one counts only once consumed, and that retired graphs with releases between them never fall back to uncached records. Three new mutations cover each rule. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Independent review of What holds up:
Test gap (not blocking, worth fixing): Premise, still a hardware question:
Local checks on this head merged with main
What's left: an M4 Pro/Max (G17P) row at this head, J616s or J616c, ideally on 26B123; the comment contradiction resolved; and the positive control or the per-firmware flag. |
There was a problem hiding this comment.
Verdict: MERGE at 98cef72 (code).
Checked: The #3705 prerequisite is merged. The new check marks a scheduler release after its successful publication and advances the release witness only once its record has been consumed. Cached queue-state reuse requires that witness to be strictly later than the returned object's fence. Other objects retain their existing fences. A failed publication leaves the release mark alone.
The exact object-fence suite passed, and all three queue-record mutations failed at the expected assertions. I also compiled the exact production release functions and checked 3,072 cases across four actual-size control-ring wraps, including pending records and invalid cursors. The posted J700 receipt reports zero readback mismatches and zero multi-queue CTS failures. The host checks establish the ordering rule. The hardware receipt covers the firmware behavior on J700.
What: Reuse a returned G17P render queue-state object once the firmware has consumed a scheduler release published after the object's fence. Until now it waited for firmware stop.
DestroyContextcarried: the context page and its bytes 0, 1, 4 and 0x23 (0x26 here). The older driver uses that command as a full firmware data-cache flush (flush_fw_cacheingpu.rs), and frees firmware-cached memory only after one. This PR applies the same rule to cached queue records: once a release published after the object's fence is consumed, the firmware no longer holds the record lines, so the pool may zero and rewrite them.channel.rstracks the latest scheduler release and the latest one the firmware consumed.object.rsmarks cached queue states and checks that rule instead of the plain fence. Other families keep their fences.tools/asahi/g17-object-fence-tests.py: a new test and three new mutations (release published before the return, reuse without a later release, retention until stop).Tested: J700 (A18 Pro, G17P), Mesa
089aeb0eprivate ICD. One trial boot at98cef721, run in the same order as the #3705 row: packet rows, then the full multi-queue CTS, then q4 again on queues created after the CTS. Median µs, range and visits, lower is better:dEQP-VK.synchronization2.op.multi_queue.*16,680 Pass, 7,080 NotSupported, 0 Fail.dEQP-VK.synchronization.op.multi_queue.*12,798 Pass, 9 NotSupported, 0 Fail. 0 recoveries.+0x1cand+0x94, as on drm/asahi: g17: keep G17P render queue records firmware-cached #3705. The CTS ran on reused records with the same result (16,680 and 12,798 Pass, 0 Fail, 0 recoveries, 0 GPU faults), and q4 was 40.27 µs before and 40.30 µs after.tools/asahi/run-host-tests.py --only g17298/298, including the three new mutations.checkpatch.pl --strict: 0 errors, 0 warnings.Risk: two-way door · G17P Macs (A18 Pro, M4 Pro/Max) reuse a cached render queue-state object after a later scheduler release instead of never. If a release did not flush the firmware data cache, the firmware could read a stale record line after reuse. The rule relies on the release behaving like the older
DestroyContext. The test-only check above found no stale host word in a reused record.Not yet:
Details
Why the pool filled
Pool::return_objectgave a cachedFamily::QueueStateobject no fence (None), soRetained::readynever became true. The object kept its reserved slot untilPool::stop_after_firmware, which runs only fromFirmware::drop. Each new render graph allocates one queue-state object, so 64 retired graphs filled the family, and every later graph fell back to an uncached allocation.The rule
published_release()records the control-record count of each scheduler release at publication (runtime/teardown.rs).observe_controlmoves the consumed mark up to that release once the firmware has consumed it.control_published()on the A18 Pro,control_fence()elsewhere). It becomes reusable only when a release published after that fence has been consumed (release_witnessed() > fence). A release published before the return never counts, so the flush runs after the firmware last named the records.DestroyContextflush (gpu.rs). On G17 the release record has the same contents.Not run