Skip to content

drm/asahi: g18: repeat the audit's page walks only after a mapping changed (+19-21% fps on small frames) - #2652

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-audit-sampled
Nov 22, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-audit-sampled

Conversation

@sithglan

@sithglan sithglan commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Before every application kick, audit_application() walks the page tables behind the job:

  • every target, in the storage and client VMs;
  • the UMA render mappings;
  • the PB and the job VA, in the kernel, kernel-lower and client VMs.

With one job in flight, the GPU waits for it. On the J873g (M6 Mac mini) the walks took about 80 of the 180 µs between a job's retirement and the next kick.

Change. A walk proves those mappings are as expected. Each VM's mapping epoch (mapping_validation_epoch(), which the G17 validation cache already uses) advances on every unmap and remap, and reads None while a change is in flight. An addition doesn't move it, because it leaves every proven range mapped.

The audit now records the client VM and the epochs of the four VMs with each walk, and walks again only when one of them differs or is unknown:

  • a new client;
  • a target that was remapped or grown;
  • any unbind in the client VM;
  • a kernel mapping that went away.

Everything else is still checked on every frame: the PB and UMA rows, the scheduler and stamps, and the command digests. PB or UMA growth only adds mappings the walk doesn't cover, and the rows that describe them are among the per-frame checks. There is no module parameter.

J873g rows (asyncbench, headless; walking on every frame against walking after a change, interleaved on one boot through a temporary switch that is not part of this PR; four rounds each, frames/s mean and range):

triangles walk every frame walk after a change
200 1588 (1574–1604) 1896 (1854–1932)
20000 606 (596–619) 733 (718–764)
1000000 20.0 20.1 (GPU-bound)

Mapping-change row. A GLES client binds a 16 KiB buffer into its own VM between frames and unbinds it again (DRM_IOCTL_ASAHI_VM_BIND, so there's an unmap between every two frames). It gets a walk on every frame: 256 walks per 256 frames, with the client VM's epoch advancing in step (555 → 811 → 1067). Its frames render with the expected pixel.

A plain client (asyncbench) gets 13 walks in 8192 frames, all on clients' first frames. A GL client that recreates its FBO texture every frame causes no walks, because Mesa recycles its buffers and the VM doesn't change. There were no job failures.

Checks: builds on the integration tip with no new warnings.

cc @DjDeveloperr @RyanTheTide @Acelogic @LiamRay10

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The speedup is clear, but this changes what the audit guarantees, so it needs an argument for why skipping is safe.

  • publish_h1() refuses a job that hasn't been audited, so the audit is the gate between a client's job and the firmware: PB residency, the UMA descriptor, every render mapping in up to three VMs, and the command digests. On a skipped frame, audited_between() sets audited without any of those checks. A client that unmaps or remaps a target, or changes what the PB or the commands point at between two full audits, then gets a job published against state nobody checked. With one client that can last up to 255 frames. The likely result is a GPU fault or firmware crash that takes down every client, and possibly worse if a stale mapping now belongs to someone else.
  • What makes a frame traced()? The description says "its first three frames, when its mappings are new". If anything that changes the job's VM (map/unmap/bind), its PB, or its UMA rows forces the next frame back onto the full audit, the skip is sound, and the commit should say so and point to where that happens. If traced() only means the first three frames, the skip should be keyed on that instead: a per-VM mapping generation, plus the PB/UMA generations, compared with the last audited values. A frame then skips the walk only when none of them has moved. The digests could be kept per audited state and compared cheaply rather than recomputed through uncached reads.
  • g18_audit_interval is a new runtime switch. Merged code should pick its behaviour itself, and once skipping is tied to "nothing changed since the last audit" the interval isn't needed.

A row that changes a client's mappings between frames (for example, unmap and rebind a render target while it keeps rendering) would show the gate still catches it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Following up on the earlier review with the project convention behind it.

We treat checks that stand between a client's job and the firmware as safety policy, and those apply on every frame, without a switch. At drivers/gpu/drm/asahi/g18/initdata/application.rs:17-21 a job that skips the audit is still marked audited (audited_between(), graphics_job.rs:248-251), so for up to 255 frames publish_h1() admits state nobody checked. And g18_audit_interval (g18/params.rs:123-124) is a new module parameter that changes that production behaviour.

The shape that keeps the speedup: skip the walk only when nothing it covers has changed since the last audit (a per-VM mapping generation plus the PB and UMA generations, compared with the audited values), and drop the parameter. We are happy to run the mapping-change row on our side once that is in.

@sithglan
sithglan force-pushed the thomas/g18-audit-sampled branch from 45d6d20 to 82d2c8b Compare November 21, 2026 03:18
@sithglan sithglan changed the title drm/asahi: g18: audit an application job fully on a client's first frames and every 256th (+26-32% fps on small frames) drm/asahi: g18: repeat the audit's page walks only after a mapping changed (+19-21% fps on small frames) Nov 21, 2026
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide agreed on both counts. I reworked it in 82d2c8bd3967 the way you describe.

  • Nothing is skipped on a counter any more. Every check still runs on every frame (PB and UMA rows, scheduler and stamps, command digests) except the page walk, which repeats whenever the VMs it read have changed. The proof uses the existing mapping epochs, the same mechanism the G17 validation cache uses. Each walk records the client VM and the mapping_validation_epoch() of the storage, client, kernel and kernel-lower VMs. A later frame walks again if any of them differs, or reads None (a change in flight). The epoch advances on every unmap and remap, so a new client, a remapped or grown target, any unbind in the client VM, or a kernel mapping going away all force a walk. Additions don't move it, but they leave every proven range mapped.
  • PB and UMA. PB growth only adds blocks the walk never covered (it walks the fixed PB objects), and the UMA pool has no runtime growth. The rows that describe both are re-read on every frame, as before.
  • g18_audit_interval is gone. No parameter remains.
  • The digests couldn't be cached: the commands carry per-frame values, and the digests repeated in 0 of 4096 frames. They stay a per-frame uncached check (about 25 µs).

The mapping-change row you asked for is a GLES client that binds a buffer into its own VM and unbinds it between every two frames (VM_BIND). It got a walk on every frame: 256 per 256 frames, the client epoch advancing with them. Its frames are correct and there were no failures.

The speedup is smaller than the counter version's but still clear: +19% at 200 triangles and +21% at 20000, interleaved on one boot. Tables are in the description.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Checked 82d2c8b. This answers my concern. Only the page walk is reused, and only when the client VM and all four mapping epochs match the last walk. The key is read before the walk, so a change during it forces another walk on the next frame. A VM in the middle of a change (None) always walks. PB/UMA rows, stamps and digests still run every frame, and the parameter is gone. The VM_BIND bind/unbind row walking 256 of 256 frames is the right proof.

One thing to confirm: WalkKey.client is the VM's id(). If a client's VM can be freed and a new one created with the same id while walked survives (the same ApplicationJob reused across a reopen), the epochs would have to differ too. If ids are never reused, or walked is reset with the VM, a word in the comment would settle it.

Assisted-by: LLM (Claude:Opus 5.5)

…anged

Before every application kick, audit_application() walks the page tables
behind the job: every target in the storage and client VMs, the UMA render
mappings, the parameter buffer and the job VA in the kernel, kernel-lower
and client VMs. With one job in flight, the GPU waits for it. On the J873g
the walks took about 80 of the 180 us between a job's retirement and the
next kick.

A walk proves that those mappings are as expected. Each VM's mapping epoch
(mapping_validation_epoch(), as the G17 validation cache uses) advances on
every unmap and remap; an addition leaves every proven range mapped, and the
epoch reads None while a change is in flight. Record the client VM and the
epochs of the four VMs with each walk, and walk again only when any of them
differs or is unknown: a new client, a target that was remapped or grown,
any unbind in the client VM, a kernel mapping that went away. The PB and
UMA rows, the scheduler and stamp checks and the command digests are still
checked on every frame. Growth of the PB or the UMA pool only adds
mappings the walk does not cover; the rows that describe them are among
the per-frame checks.

J873g, asyncbench, walking on every frame against walking after a change,
interleaved on one boot through a temporary switch, four rounds each
(frames/s, mean and range):
- 200 triangles: 1588 (1574-1604) against 1896 (1854-1932)
- 20000 triangles: 606 (596-619) against 733 (718-764)
- 1000000 triangles: 20.0 against 20.1 (GPU-bound)

A client that binds and unbinds a buffer in its VM between frames (an
unmap between every two frames) gets a walk on every frame: 256 walks per
256 frames, the client VM's epoch advancing with them, and its frames
render correctly.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/g18-audit-sampled branch from 82d2c8b to 58fe4d8 Compare November 21, 2026 03:23
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide ids aren't reused. G18 creates each user VM with self.ids.vm.next() (g18/drm.rs, new_vm()), and that is the device's ID counter in gpu.rs: a 64-bit fetch_add(1) that never goes back. A VM created after another one is freed therefore gets a new id and never matches a recorded walked, even if the ApplicationJob survives. The storage VM in the key is the job's own fixture VM and lives as long as the job. I said so in the WalkKey comment in 58fe4d8d90fe (comment only; it builds).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, that settles it. VM ids come from the device's 64-bit counter and are never reused, so a recorded walk can't match a VM created later, and the WalkKey comment in 58fe4d8 now says so. No further points from us on this head.

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

Adversarial review against pre-pr-checklist.md (§1–§6) at 58fe4d8d90fe.

Code & checklist check (§1–§4, §6, CI)

  • Correctness & safety (§3): Verified against drivers/gpu/drm/asahi/mmu.rs, g18/boot/session.rs, g18/buffer/pool.rs, g18/buffer/object.rs, and g18/queue/graphics.rs.
    • Every range checked by audit_render_mappings() and the if walk block of ApplicationJob::audit() lives in [self.storage, self.job.vm(), uat.kernel_vm(), uat.kernel_lower_vm()].
    • Vm::id() is allocated from the monotonic 64-bit ids.vm counter (g18/drm.rs), never reused.
    • On G18 (NoPeerRoots), all four VMs carry a MappingEpoch; every KernelMapping map/drop, unmap_gpuva, and remap calls mapping_mutation() (advancing the epoch and returning None while in flight), while mapping_addition() returns None while in flight and preserves all previously proven ranges.
    • Reading walk_key() before the walk ensures any concurrent mutation during a walk leaves the cached key stale (None or old epoch) so the next frame re-walks.
    • PB residency, UMA descriptor validation, scheduler counters, stamps, and uncached FNV64 command digests still run on every frame.
  • §1 / §2 / §4 / §6 & CI: Clean. g18_audit_interval is gone (default kernel command line, no switches/hacks), single commit carries human identity + Signed-off-by: only, and host-tests is green.
  • (Non-blocking note: on frames 2–3 when walk == false, G18_APP_AUDIT logs translations=0 because pages is 0; harmless unless anything parses non-zero translations= on those frames.)

Holding for §5 evidence

The same-machine J873g interleaved A/B (+19–21% on 200/20000 triangles) and the DRM_IOCTL_ASAHI_VM_BIND bind/unbind row (256/256 walks) are strong, but two §5 items remain owed for a performance-claim PR:

  1. Kernel/build identifier and regression run on 58fe4d8d90fe (or the identical code at 82d2c8bd if clearly stated): explicit 0 SELinux denials, 0 failed units, 0 new kernel errors.
  2. Conformance unchanged on G18 (J873g) — required by §5 for performance claims ("a same-machine A/B with conformance unchanged on every GPU generation the change applies to").

Code looks solid; happy to approve once those §5 rows are recorded.

Assisted-by: LLM (Gemini 4 Neon)

@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 58fe4d8d90fe826f4e98605c4ffa38be31669d38: 0 code/policy/attribution/naming/CI blockers (host-tests: pass, mergeable/clean).

Status since 08:00Z

  • §4 Attribution: Confirmed — the 08:15Z PR body update appended Assisted-by: at the end of the description, and commit 58fe4d8d90fe carries human author/committer + Signed-off-by: only.
  • §1 / §2 / §3 / §6: Unchanged and clean (no code changes since the prior review; WalkKey epochs, 64-bit monotonic Vm::id(), and per-frame PB/UMA/scheduler/stamp/digest checks all hold).

Still holding strictly for §5 HW evidence before APPROVE

No new §5 hardware rows were added in the 08:15Z body edit. Two items remain owed for a performance-claim PR:

  1. Kernel/build identifier and §5 regression run on 58fe4d8d90fe (or the code-identical 82d2c8bd if explicitly stated): 0 SELinux denials, 0 failed units, 0 new kernel errors.
  2. Conformance unchanged on G18 (J873g), as required by §5 ("a same-machine A/B with conformance unchanged on every GPU generation the change applies to").

Happy to upgrade to APPROVE as soon as those §5 rows are recorded.

Assisted-by: LLM (Gemini 4 Neon)

@sithglan

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr the two §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 walk every frame this PR
200 2179, 2247 2370, 2382
20000 872, 889 896, 909
1000000 19.8, 20.0 20.0, 20.1

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

suite (cases) this PR walk every frame
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 1343 pass, the same 6 fail, 49 flake, 108 skip
  • The 6 fails are the transform_feedback lines cases. They fail the same way in every mode.
  • The 49 flakes came from two batches run with the switch on.
    • In both, 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 on an earlier boot where the switch hadn't applied, i.e. with this PR's code. It doesn't depend on how often the audit walks.
    • A single long fragment shader reproduces it on its own. I added the details to mesa#617.
    • It isn't caused by this change.

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 58fe4d8d90fe826f4e98605c4ffa38be31669d38: LGTM — approving.

Verified Since Prior Review

  • §1–§4, §6 & CI: Unchanged and clean at 58fe4d8d90fe (WalkKey over monotonic 64-bit Vm::id() and all 4 VM mapping_validation_epoch() values read before walking, per-frame PB/UMA/scheduler/stamp/digest checks intact, no module parameters, clean human commit identity + Signed-off-by:, Assisted-by: in PR body, host-tests green, clean against integration/aurora).
  • §5 Evidence (complete): Newly posted J873g (G18) rows on 7.3.0-aurora-j873-avd-usb4-perf+ (default cmdline, aurora.ko carrying code-identical 82d2c8bd walk reuse) 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 + mapping-change proof: interleaved asyncbench speedup confirmed alongside the DRM_IOCTL_ASAHI_VM_BIND bind/unbind proof (256/256 walks with advancing epoch).
    • 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).

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide
RyanTheTide merged commit a5e9344 into aurora-silicon:integration/aurora Nov 22, 2026
1 check passed
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