Skip to content

drm/asahi: g17: reuse cached queue records after a later release - #3721

Open
DjDeveloperr wants to merge 1 commit into
neo/g17p-cached-render-queue-recordsfrom
neo/g17p-recycle-queue-records
Open

DjDeveloperr wants to merge 1 commit into
neo/g17p-cached-render-queue-recordsfrom
neo/g17p-recycle-queue-records

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

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.

  • drm/asahi: g17: keep G17P render queue records firmware-cached #3705 maps G17P render queue records firmware-cached. It keeps a returned queue-state object out of reuse until firmware stop, which only comes at driver teardown. After 64 retired render graphs, every new graph got uncached records again. On the MacBook Neo one multi-queue CTS run filled the pool, and q4 on new queues went from 40.35 to 42.52 µs, main's level (row).
  • The scheduler release record carries what the older firmware's DestroyContext carried: 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_cache in gpu.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.rs tracks the latest scheduler release and the latest one the firmware consumed. object.rs marks 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 089aeb0e private ICD. One trial boot at 98cef721, 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:

q4 triangle this PR #3705 head (its row)
before the CTS 40.37 (40.15–40.44, 10) 40.35 (39.89–40.64, 10)
new queues after the CTS 40.31 (40.18–40.44, 6) 42.52 (42.29–42.60, 6)
  • Queue-state pool after rows, CTS and the q4 rerun: 10, 13, 13 of 64 used, 0 uncached fallbacks. At the drm/asahi: g17: keep G17P render queue records firmware-cached #3705 head: 54, 64, 64 used, 81 uncached fallbacks.
  • 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.
  • compute.light d1 105.89 µs, d16 15.03 µs. Every readback and per-queue CRC check passed.
  • 0 kernel warnings, 0 GPU faults, 0 AVC denials, 0 failed units, SELinux enforcing, SLC on 4 planes. Stock Fedora -41 was restored and verified afterwards.
  • A test-only build of this commit (never for merge) took the newest reusable queue state first, so each reuse came as soon after its flush as possible. Before every render publication it read both records back and compared the host words with what the new owner wrote. Same boot sequence: 132 reuses, 108 render graphs built on reused records, 481,283 checks on those graphs (524,288 in all), 0 mismatches. The only record words the firmware changed were +0x1c and +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.
  • Host tests: tools/asahi/run-host-tests.py --only g17 298/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_object gave a cached Family::QueueState object no fence (None), so Retained::ready never became true. The object kept its reserved slot until Pool::stop_after_firmware, which runs only from Firmware::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_control moves the consumed mark up to that release once the firmware has consumed it.
  • A cached queue state keeps the fence its family already had (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.
  • The older driver frees firmware-cached memory the same way: it collects freed objects as garbage and frees them only after a later DestroyContext flush (gpu.rs). On G17 the release record has the same contents.
  • Every closed context publishes a release, so under churn the pool refills from retired graphs. Graphs retired after the latest consumed release wait for the next one.

Not run

  • The asahi KUnit suites: this change adds no KUnit test, and no warm KUnit build tree was available. The pool logic is covered by the host harness.

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 <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 1, 2026 02:07
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Merge readiness at 98cef721: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 98cef721
Conflicts ok none
PR text ok Risk: two-way · 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.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant