Skip to content

drm/asahi: g18: compare the command read-back instead of hashing it - #2680

Open
sithglan wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-command-compare
Open

sithglan wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-command-compare

Conversation

@sithglan

@sithglan sithglan commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

On the J873g (M6 Mac mini), the GPU sits idle for about 154 µs between two application jobs. That is the time from one job's retirement to the next job's kick.

Where the time goes. Per-segment timers in ApplicationJob::prepare() and audit_application() (a temporary build, averaged over 8192 frames; the same at 200 and 20000 triangles):

segment µs
encode: the 7 FNV digests of both commands and their register blocks (~14 KiB) 56
encode: register programs, commands, allocation, copy to the graph 12
audit: reading both commands back from the write-combined graph 7
audit: hashing what was read 45
target zero-fill, scene, PB/UMA rows, scheduler, the rest ~14

FNV-1a does one dependent multiply per byte. About 100 µs of the gap is hashing.

Change.

  • Byte-for-byte compare. The encoded job keeps the encoder's cached copy of the commands. The per-frame audit compares the read-back with it byte for byte. That is an exact check where the digests were a hash comparison, and it reads the graph in wide loads.
  • Digests only where logged. They are computed from the cached copy only for the first three frames of a client (G18_APP_DIGEST, unchanged values) and for the H1 audit. The H1 audit compares its read-back the same way and still logs the digests of what it read.
  • Code moves. EncodedJob moves to graphics_job.rs, since render_assembly.rs is shared with the host dry-run and stays free of kernel allocations. fnv64_uncached() loses its last user and is removed.
  • Every frame is still checked. No per-frame check is dropped, and there is no module parameter.

J873g rows (asyncbench, headless, async submission from #2679 with its Mesa side). The old hashing and the compare were interleaved on one boot through a temporary switch that is not part of this PR; four rounds each, frames/s mean and range:

triangles hash every frame compare
200 1923 (1851–1962) 2335 (2319–2369)
20000 772 (736–809) 892 (890–894)
1000000 20.1 20.1 (GPU-bound)
  • The compare is also steadier: its range is a quarter of the hashing one at 20000 triangles.
  • There were no job failures.
  • The first frames' G18_APP_DIGEST/G18_APP_AUDIT lines are as before.
  • The H1 fixture audit doesn't run on a normal boot: that path is built but not exercised on hardware.

Checks.

  • Builds on the integration tip with no new warnings.
  • The asahi/agx/clpc host tests pass. No host test compiles these files.

cc @DjDeveloperr @RyanTheTide @Acelogic @LiamRay10

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Looks right. The expected bytes are the kernel's own encoded copy (EncodedJob::commands, a KVec in kernel memory), and the audit compares the whole read-back of both commands, which covers every range the seven digests hashed (the register blocks are sub-ranges of the same two commands). Comparing slices also checks the lengths, so a short read can't pass. That makes it an exact check where the digests were probabilistic, at a fraction of the cost. Keeping the digests only for the logged first frames and the H1 audit keeps the existing log lines comparable.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train adversarial review (MERGETRAIN-LINUX2) at 3dcbbdb: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2680 drm/asahi: g18: compare the command read-back instead of hashing it @3dcbbdb1

VERDICT: NO BLOCKERS

Blockers: none.

What I checked:

  • graphics_job.rs:17-29: EncodedJob now owns the cached KVec, of G18_TA_COMMAND_BYTES (0x980) + G18_3D_COMMAND_BYTES (0x2240) bytes. commands() splits it at the TA size. That is the same buffer encode_into() wrote and that was copied to the graph at :326-333.
  • Both audits compare full slices: the H1 audit at :248, and the application audit at graphics_job_application.rs:190, with FRAGMENT_OFFSET = 0x4000 (render_assembly.rs:10).
  • A slice != also compares lengths. The register-block digests covered sub-ranges of those same two commands, so nothing that was checked before goes unchecked now.
  • The logged digests (digests() from the cached copy) have the same inputs as the removed in-encoder digests, so G18_APP_DIGEST values stay comparable.
  • fnv64_uncached has no remaining users. encode() has no callers outside render_assembly.rs. The g17 m5 render_assembly is a separate module and is untouched.

Nits:

  1. Each job now holds about 11 KiB of kernel memory (the cached commands) for its lifetime, where it was freed at the end of prepare(). That is fine at current queue depths, but worth one line in the struct comment.
  2. graphics_job_application.rs:190 still hardcodes 0x4000 where graphics_job.rs uses assembly::FRAGMENT_OFFSET. This is pre-existing; use the constant while touching the line.

Missing rows:

  • G18 is M6 only. The proof is J873g asyncbench. Other M6 boards (the M6 lane's J8xx) are unproven but share the code path.
  • The H1 fixture audit path (graphics_job.rs:241-255) is built but not exercised on hardware, as the PR body says. One boot with that audit enabled should show G18_RENDER_DIGEST lines with no EIO.

@sithglan
sithglan force-pushed the thomas/g18-command-compare branch from 3dcbbdb to 8a44565 Compare November 22, 2026 03:35
@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 8a44565 (range-diff against 3dcbbdb): the new push only documents the cached copy's size and lifetime and replaces the literal 0x4000 with assembly::FRAGMENT_OFFSET. No behaviour change. Verdict stays NO BLOCKERS; Dj's verdict is needed at this head.

@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide thanks. The new head is 8a445653363d; I amended the commit with both nits:

  1. The EncodedJob comment now says the cached copy, G18_TA_COMMAND_BYTES + G18_3D_COMMAND_BYTES (about 11 KiB), lives as long as the job so the audits can compare against it.
  2. graphics_job_application.rs uses assembly::FRAGMENT_OFFSET instead of 0x4000.

drivers/gpu/drm/asahi/ builds with the same warnings as before, none of them in these files.

H1 audit row: I tried it on the M6 with the desktop port of this change, but stage 9 never reaches the audit.

  • I ran the power stages 1/90/92/91 and then g18_initdata_test=9 g18_sma_minimum=0; with the default g18_sma_minimum=1, stage 9 is refused before MMIO.
  • G18_RENDER_ADMIT variant=Color profile=1 is logged, both RTKit roles boot, and the MMU roots are set up.
  • Then the worker ends with G18_RENDER_STAGE_DONE result=Err(Error(19)) / G18_RENDER_H1_FAIL. That happens before any command is encoded, so there are no G18_RENDER_DIGEST lines.
  • The failure comes before the code this PR touches, so this PR doesn't cause it. I haven't chased the ENODEV yet; I'll file it separately if it isn't known.

So the H1 audit stays unexercised on hardware, as the PR body says. The stage 10 audit that compares the same cached commands runs on every application job. On the boot after the stage 9 attempt, the desktop came up and 2000 asyncbench frames ran with err=0 and no EIO or job failure in the kernel log. The G18_APP_DIGEST lines for frames 1-3 are logged as before.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide I filed the stage 9 ENODEV as #2768. It looks like the H1 worker loses its devres-managed register mapping when stage 9 returns ENODEV from probe. That started with e06fb54 and is unrelated to this PR.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr 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.

Reviewed at 8a445653363d. The code change itself has 0 code or CI blockers (host-tests green), but requesting changes for a §4 PR-body attribution blocker before merge.

Blocker

  • §4 Attribution (hard rule): The amended live head 8a445653363d was prepared with LLM assistance (LLM (Claude:Opus 5.5) as noted in the follow-up comment), and the commit metadata itself is clean (human author/committer + Signed-off-by:, no agent trailers in the commit). Please add a plain Assisted-by: line at the end of the PR body (e.g., Assisted-by: LLM (Claude:Opus 5.5)).

Code & Checklist Summary (§1–§6)

  • Code (graphics_payload.rs, render_assembly.rs, graphics_job.rs, graphics_job_application.rs): Retaining the ~11 KiB encoded commands buffer in EncodedJob and comparing the write-combined graph read-back byte-for-byte in audit_h1() and ApplicationJob::audit() is strictly stronger than comparing the 7 FNV-1a hashes (every hashed register block is a sub-slice of ta/fragment), removes the last caller of fnv64_uncached(), and preserves G18_APP_DIGEST output for frames 1–3.
    • Non-blocking nit: in audit_h1() (drivers/gpu/drm/asahi/g18/runtime/graphics_job.rs:251), assembly::digests(ta, fr) hashes the uncached WC slices immediately after proving ta == ta_expected && fr == fr_expected; hashing (ta_expected, fr_expected) avoids uncached byte loads while logging identical digests.
  • §1–§3, §6: Clean — no model gating, no new module/cmdline parameters, every frame remains audited before kick, naming clean.

Remaining §5 Evidence Notes

  • Performance claims require a same-machine A/B with conformance unchanged on the affected GPU generation (only asyncbench numbers are currently recorded).
  • Please also include regression counts on 8a445653363d (0 SELinux denials, 0 failed units, 0 new kernel errors).
  • Understood that the H1 fixture audit path (graphics_job.rs:246-255) cannot currently be exercised on hardware due to pre-existing #2768.

Assisted-by: LLM (Gemini 4 Neon)

@sithglan
sithglan force-pushed the thomas/g18-command-compare branch from 8a44565 to e56519a Compare November 22, 2026 07:44
@sithglan

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr thanks.

  • Attribution: the PR body now ends with Assisted-by: LLM (Claude:Opus 5.5).
  • Nit, applied: audit_h1() now hashes (ta_expected, fr_expected), the cached copy, once the read-back has been shown equal to it. It no longer reads the write-combined slices a second time, and the logged digests are the same. New head: e56519aa3ad5. The only change against 8a445653363d is that line plus a comment. The asahi driver builds (arm64, LLVM 22).
  • §5: the J873g is in use right now for the aura#419 enrolment test. When it's free, I'll post on this head:
    • a same-machine A/B with conformance: the asahi-relevant dEQP groups from the earlier rows, with and without this commit, plus the asyncbench numbers;
    • the regression counts (SELinux denials, failed units, new kernel errors).

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr @RyanTheTide the §5 rows on the J873g.

Build.

Regression.

  • 0 failed units and 0 AVC denials, at the start of the boot and after all rows.
  • Kernel errors: the same 3 boot-time lines as on the boots before it (apple-dcpib 502e00000 set_mode failed: -5 and the two btcentauri -16 probe lines).
  • Job failures during the rows:

Performance. asyncbench, frames/s, two rounds interleaved:

triangles hash (switch) this PR
200 1432, 1322 2285, 2381
20000 573, 552 897, 901
1000000 19.9, 19.8 20.1, 20.0

Conformance. deqp-runner, --jobs 1, 256x256 pbuffer, same caselists in both modes:

suite (cases) this PR hash
dEQP-GLES31 compute.* + draw_indirect.* (416) 398 pass, 18 skip identical, 0 cases differ
dEQP-GLES3 fence_sync, flush_finish, occlusion_query, pbo, read_pixels, transform_feedback (1506) 1392 pass, 6 fail, 108 skip 1366 pass, the same 6 fail, 26 flake, 108 skip
  • The 6 fails are the transform_feedback lines cases. They fail the same way in every mode.
  • The 26 flakes came from one batch run with the switch on.
    • The job right after flush_finish's timing tests ended with a firmware-raised recovery (reason=0x3). The rest of that process's occlusion_query cases failed, and deqp-gles3 then crashed. Every case passed on rerun.
    • The same recovery happened once with this PR's code on an earlier boot. A single long fragment shader reproduces it on its own (details in mesa#617).
    • It isn't caused by either mode.
  • Every frame of every run above went through the per-frame audit. None was refused, and G18_APP_DIGEST still logs the first frames' digests.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr 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.

Re-review against pre-pr-checklist.md (§1–§6) at verified live head e56519aa3ad5a1fa44cc8fabade5424ab8ea7c90: LGTM — approving.

Verified Since Prior Review

  • §4 Attribution (prior blocker resolved): PR body now includes Assisted-by: at the end, and commit e56519aa3ad5 carries human author/committer (Thomas Glanzmann) + Signed-off-by: only, with zero agent trailers.
  • Code & CI: audit_h1() now hashes (ta_expected, fr_expected) from the cached copy after proving byte-for-byte equality with the write-combined read-back (graphics_job.rs:246-249), avoiding redundant uncached reads while logging identical digests. host-tests is green and the branch is clean against integration/aurora.
  • §5 Evidence (complete): J873g (G18) rows on 7.3.0-aurora-j873-avd-usb4-perf+ (default cmdline, aurora.ko with e56519aa byte compare) confirm:
    • Regression: 0 failed units, 0 AVC denials, 0 new kernel errors, 0 job failures from this PR's mode.
    • Same-machine A/B performance: consistent asyncbench speedup (200 tris 1923 -> 2335 fps, 20000 tris 772 -> 892 fps like-for-like; confirmed again on the fresh interleaved boot).
    • Conformance unchanged: dEQP-GLES31 (compute.* + draw_indirect.*, 416 cases) identical (0 diffs) and dEQP-GLES3 (1506 cases) unchanged on the 6 pre-existing transform_feedback fails with 0 PR-induced regressions (pre-existing reason=0x3 recovery tracked in mesa#617). Pre-existing #2768 blocking stage-9 H1 fixture execution is noted and orthogonal.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-review (MERGETRAIN-LINUX3) at e56519a: NO BLOCKERS. Since our pass at 3dcbbdb there are only three hunks:

  • the EncodedJob lifetime doc;
  • audit_h1() now logs the cached digests instead of hashing the WC slices, which fixes Dj's nit;
  • 0x4000 is now assembly::FRAGMENT_OFFSET.

Behaviour is otherwise unchanged. The H1 fixture audit is still not exercised on hardware, because #2768 blocks it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@sithglan the train merged #2652 (your g18 page-walk change), and #2680 at e56519a now conflicts with integration/aurora in drivers/gpu/drm/asahi/g18/runtime/graphics_job_application.rs. That is the only file with a conflict. Could you rebase onto the current tip? Once Dj approves the new head, we'll re-check the delta, and the train will pick it up then.

Between two application jobs the GPU waits about 154 us on the J873g
for the next kick. About 100 us of it is spent hashing: the encoder
computes FNV-1a digests of both commands and their register blocks
(14 KiB, 56 us), and the audit reads both commands back from the
write-combined graph and hashes them again (45 us for the hash, 7 us
for the read). FNV-1a runs one dependent multiply per byte.

Keep the encoder's cached copy of the commands with the encoded job and
have the per-frame audit compare the read-back with it byte for byte.
That is an exact check where the digests were a hash comparison, and it
reads the graph in wide loads. The digests are computed from the cached
copy only where they are logged: the first three frames of a client and
the H1 audit, which now compares its read-back the same way and still
logs the digests of what it read.

EncodedJob moves to the kernel side, since the shared assembly code
stays free of kernel allocations, and fnv64_uncached() loses its last
user.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/g18-command-compare branch from e56519a to 1012615 Compare November 22, 2026 12:22
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide rebased onto integration/aurora f1d5b24c56b8. The new head is 101261596b9f.

  • The one conflict was in g18/runtime/graphics_job_application.rs: drm/asahi: g18: repeat the audit's page walks only after a mapping changed (+19-21% fps on small frames) #2652's if walk { ... } block now closes just before this PR's byte compare. So the read-back is compared on every frame, and only the page walk depends on the walk key.
  • Range-diff: only that context changes; the compare and the H1 audit are unchanged.
  • Checks: the asahi driver builds (arm64, LLVM 22). checkpatch --strict gives the same two long-line warnings as at e56519aa, in this file's dense style.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-check at 1012615: git range-diff against the reviewed head e56519a shows a rebase onto the current integration/aurora only (context in graphics_job_application.rs after #2652); the patch content is unchanged. Our earlier no-blockers verdict carries to this head. Waiting on Dj's re-approval at 1012615.

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