Skip to content

drm/asahi: g18: retire jobs sooner and leave the firmware trace off - #2109

Open
LiamRay11 wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
LiamRay11:j804/g18-fast-retire
Open

LiamRay11 wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
LiamRay11:j804/g18-fast-retire

Conversation

@LiamRay11

Copy link
Copy Markdown

Summary

These are three host-side latency fixes in the G18 job path. They change no firmware interface and are not J804-specific. They were measured on a MacBook Pro (M6, J804).

  1. Wake the submitter on completion. ApplicationOwner::work() polled the worker's ticket with fsleep(): 20 us for 2 ms, then 200 us. The caller now sleeps on a Completion that the worker completes from a drop guard, after storing the outcome and releasing the session lock. It sleeps in 1 s slices (wait_for_completion_timeout() in a loop), so a long wait behind other clients' jobs and their recovery does not trip the hung-task detector. A closure dropped without running still wakes the caller, which then fails with EIO.
  2. Notice retirement sooner. wait_job() keeps the fine 20 us interval for 20 ms instead of 2 ms, because full-panel jobs take 2-10 ms. Once the scheduler's completed count or the stage stamps show the job finished, it re-polls with a 2 us delay for at most 200 us instead of sleeping. The retirement condition is unchanged.
  3. Trace mask 0 by default. The driver wrote trace mask 3, so the firmware wrote about 59 trace records per render job, which the host copied out inside the wait loop. The new parameter aurora.g18_fw_trace=1 restores mask 3. g18_graphics_stall_trace=1 still selects 0x203.
    • This changes the default on every G18 machine. The trace journal dumped on G18_APP_FAIL no longer contains firmware trace records unless aurora.g18_fw_trace=1 is set. Maintainers may flip the default back to 3 if they would rather keep those records by default; the latency gain of this commit then becomes opt-in.

Measurements (J804, same Mesa, before -> after all three)

test before after
gllat trivial draw + finish 1.33 ms 0.95 ms
gllat full-panel 2-tap 2.93 ms 2.27 ms
glarea 64x64 clear 1.17 ms 0.96 ms
full-panel clear + draw 3.6 ms 3.25 ms
two gllat processes 1.75 / 4.82 ms 1.40 / 3.92 ms
glphase p1-p99 1.06-1.46 ms 0.86-1.20 ms

The regression suite passed 33/33, with 0 job failures and 0 recoveries.

Testing

On hardware: MacBook Pro 14-inch (M6, J804), 2026-11-16, tested by LiamRay11.

  • What ran: kernel 7.3.0 built from integration/aurora bf423bf0e with all nine J804 linux PRs merged (t8152-mailboxes, dart-gen3, dt-board, centauri, g18-fast-retire, cfg80211-stale-scan, smc, cs42l84-jack, and an NVMe PR that is not sent yet), plus retest-only device-tree changes that are not part of these PRs: SSD nodes (ANS mailbox, SART, NVMe), PCIe port 0 with the N1 Wi-Fi, the USB0 gadget console, and a read-only NVRAM partition. Those nodes were needed to reach the root filesystem and SSH.
  • Booted through aura on the installed root filesystem. A systemctl reboot from this kernel (watchdog restart) returned to the installed system.

Results for this PR: not testable in this retest. The tree has no GPU node, so the G18 driver did not run; on this base the change is build-tested only.

  • The measurements above are from a MacBook Pro (M6, J804) on an earlier base (integration/aurora f5fa539) plus the J804 firmware admission, which is not part of this PR. The 1 s wait slices were added after those runs.
  • On this base (bf423bf): drivers/gpu/drm/asahi/ builds with rustc 1.85 and bindgen 0.71, with no warning in the changed files (the 33 crate warnings are in untouched code). It was not built with the CI's Rust 1.96, and the host-tests (tools/asahi, asahi-g15/m4 selftests) were not run locally.
  • These paths also run on J873. They have not been run there.

integration/aurora has since moved to 677be395b; this branch still merges into it without conflicts.

Not included (from the bring-up stack)

  • g18-builtin: superseded. Upstream no longer calls __module_get() in the G18 boot path.
  • zz-g18-cached-command: superseded by aeee874.
  • The J804 firmware admission and the DT perf-state source: kept out of this PR.
  • The audit cache, client cache and asynchronous pipeline: they need a rebase onto ea5ee6b and are separate PRs.

Notes

MAINTAINERS has no G18 entry. Please coordinate with the G18 authors before merging, especially on the trace-mask default.

🤖 Generated with Claude Code

LiamRay11 and others added 3 commits November 16, 2026 10:59
ApplicationOwner::work() runs a job on a worker and the submitting
thread polls the ticket word with fsleep(): every 20 us for the first
2 ms of its wait, every 200 us after that. The wait starts at the
spawn, so it includes queueing behind other clients' jobs, and in a
desktop session most submissions were in the 200 us regime: they
returned 0.10-0.14 ms (up to 0.28 ms) after their job had ended.

Let the worker complete a Completion and the caller sleep on it, in
1 s slices so that a long wait (queued behind other clients' jobs and
their recovery) does not trip the hung-task detector. The
ticket word still carries the outcome, and the worker releases the
session lock before the wake-up, since the caller or the next
client's worker takes it next. The completion is signalled from a
drop guard, so a worker closure that is dropped without running also
wakes the caller, which then sees the ticket still running and fails
with EIO rather than waiting forever.

Measured on a MacBook Pro (M6, J804) from the driver's job phase
timestamps, on an earlier base (integration/aurora f5fa539) with the
J804 firmware support that is not part of this series, and without the
1 s slices. Not tested on J873.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wait_job() polls the firmware state every 20 us for the first 2 ms of
a job and every 200 us after that. Every full-panel job takes longer
than 2 ms (2-10 ms), so its retirement was noticed about 0.14 ms late
on average: 7 of 12 sampled long jobs show one extra 230-282 us step
between the scheduler's completion and the last retirement condition.
Keep the fine interval for the first 20 ms.

The retirement conditions also do not become true together: the
scheduler's completed count and the stage stamps lead the inner queue
counters and the completion masks by 50-150 us, and each sleeping
poll added 60-100 us on top. Once the render path's check sees the
scheduler completed or the stamps written, re-poll with a 2 us delay
instead of sleeping, for at most 200 us, then sleep as before. The
retirement condition itself is unchanged.

Measured on a MacBook Pro (M6, J804) from the driver's job phase
timestamps, on an earlier base (integration/aurora f5fa539) with the
J804 firmware support that is not part of this series. Not tested on
J873.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The driver writes trace mask 3 into the GFX status-A word. With it
the firmware writes about 59 trace records per render job, 48 of them
before the completion event and 2.6-3.0 us apart by their timestamps,
and the host copies every one out inside its wait loop. Write 0
instead unless the new aurora.g18_fw_trace parameter is 1, which
restores mask 3; g18_graphics_stall_trace=1 still selects 0x203.
Retirement uses the event ring and the shared counters, not the trace
records.

This changes the default on every G18 machine: the trace journal that
is dumped on G18_APP_FAIL no longer has firmware trace records unless
aurora.g18_fw_trace=1 is set.

Measured on a MacBook Pro (M6, J804), on an earlier base
(integration/aurora f5fa539) with the J804 firmware support that is
not part of this series: with mask 0 no trace records are produced for
a render job, and rendering is unaffected. Not tested on J873.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sithglan sithglan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test report, 2026-11-17: Apple Mac mini M6 (J873g/T8152, board 0x24). PR revision tested: 5dbb3a85205d9f606f155dba7fdfca0484f794bc.

The three original PR patches were applied as clean cherry-picks to the existing working M6 branch (base 805d9fcc6812). The comparison used one rebuilt Image and matching Rust 1.98.1 modules; only the GPU module's three #2109 patches differed. Both sides used installed Mesa 26.3.0~aurora.wip.ac9d556248c-1, all 12 CPUs, fixed client affinity and performance governors (4.788/2.94 GHz).

Median clear+finish timings (median of per-process averages):

Workload Control Patched Reduction
64x64, five trials 0.441 ms 0.343 ms 22.2%
2048x2048, five trials 0.597 ms 0.492 ms 17.6%
Two concurrent 2048x2048 clients, three pairs 1.4145 ms 1.2445 ms 12.0%

Exact triangle readbacks passed at 64/256/1024/2048. Captured logs showed no new GPU failure/recovery, DART fault, WARN/Oops or SError. Separate 20-second 4K60 OpenGL playback samples recorded 0 dropped frames for control and 2 for patched, with 0 delayed in both; these single samples do not establish a statistically significant playback change.

Initial controls with one online CPU or mismatched governors were excluded. The valid control's governors were checked before and after. Both sides shared #2110 and #2112 plus the latter's sleep prerequisite. This was a matched GPU-module comparison on the working M6 branch, not a pristine upstream-base boot.

Limits: microbenchmark results, not a general application-speed claim. Forced fault/recovery, waits beyond 1 s and the firmware-trace override were not tested. The original boot files were restored and their checksums verified after testing.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the J804 GPU work and for keeping the firmware trace switchable.

One part doesn't match how we usually do it. drivers/gpu/drm/asahi/g18/boot/recovery.rs:442-450 adds a busy-wait to the job-retire wait: up to 200 us of udelay(2) re-polls once RETIRE_NEAR is set. We avoid adding retry or sleep loops where the hardware or firmware gives a completion signal. The GPU firmware reports job completion through its event ring and interrupt, so the faster retire could come from waking the waiter on that event rather than polling harder in a spin.

Could the retire move onto the completion event, even as a first step for this stage? If something about the current G18 bring-up makes that impossible, a comment explaining why would cover it. We can run no-regression rows on our other GPUs if the change touches shared code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants