Skip to content

drm/asahi: g16: batch the render root stream reads and read them once - #4033

Merged
DjDeveloperr merged 2 commits into
mainfrom
perf/g16-root-stream-batch
Dec 3, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
perf/g16-root-stream-batch

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: Make the g16 check of each render's root stream cheaper: batch the 4-byte root reads with one cache barrier, and walk and check each page once. The reads of GPU-visible memory also become single READ_ONCE loads instead of a plain copy of memory userspace can write at the same time.

Tested: No hardware run at the head of this PR; an earlier combined run is in Evidence. Local checks at 0fe0c64f5da5: arm64 W=1 build of drivers/gpu/drm/asahi (clang) with the same warnings as main, run-host-tests.py --only asahi-m4 1/1 and --only g16 2/2, checkpatch --strict clean.

Risk: two-way · M4 (T8132) and M3 (T8122, T6030) for the batched read. read_user() (the READ_ONCE copy and the single walk) is shared by the g16 and G15 stream checks.

Not yet: J773g and J516s at the head of this PR: the stream-gate negative tests, VK-CTS command buffer and draw groups, and a base/head ABBA on multi-pass renders (render.postfx, render.mdi, render.light d16 and d64), with submit CPU time. No performance gain is claimed until that ABBA is in.

Details

The gate reads one root word for each render pass. It read through a 256-byte window, which cleaned more cache lines than it needed and could take a barrier per pass. read_user_u32_batch() translates up to 64 root words, cleans each distinct cache line once, completes the maintenance with one barrier and then reads the words. A guard issues the barrier on error paths too, while the VM reservation is still held. Words that cross a page go through the existing single read.

Both read paths checked the leaf permissions and then walked the same leaf again for its address. They now take the address from the checked entry. A batch checks that a new page is System RAM when it first sees it, and the VM reservation pins that page for the maintenance and the copy.

Evidence

Host tests cover same-line deduplication, page and cache-line boundaries, read sizes, mixed valid and failing roots, aliased VAs and a separately protected alias. In the six-root, two-page fixture the checked RAM page borrows fall from 11 to 2, and the PTE walks from 4 to 2.

Hardware, supporting only: the J773g ran these commits as part of the 16-commit tree 53599499071a (module on kernel 6c83a2a64539, 12-02). The 36-row gpubench check finished with every CRC valid. It is not an A/B of this change.

Checks ran on main d1ae4f292b93 plus this branch.

The VDM stream gate reads one root word per render command. Reading
through a 256-byte window does extra cache maintenance and can require
a separate completion barrier for each pass.

Translate the root words in batches of up to 64. Clean only their
cache lines, deduplicate shared lines, and complete the maintenance
with one barrier per chunk. Use a scope guard so a failed later walk
also completes earlier maintenance before the VM reservation is
released. Words that cross page boundaries use the single-read helper.

Both read paths snapshot userspace-writable mappings through a C
READ_ONCE helper. It copies aligned words and byte edges without
requiring exclusive access to the source page.

Exercise same-line deduplication, page and cache-line boundaries,
read sizes, and mixed valid and failing roots in the host stream test.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The CDM and VDM stream gates check the leaf permissions and then walk
the same leaf again for its physical address under one VM reservation.
Derive the frame from the checked entry with the translation helper.

Validate each new batch page as System RAM before recording its physical
address. The reservation pins that backing through both the maintenance
and copy passes. Reuse that validation while keeping alias handling, the
barrier on errors and the split-page fallback intact.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 01:49
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (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 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 0fe0c64f: not ready yet

Check Detail
CI at head ok 10 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 0fe0c64f
Conflicts ok not computed yet
PR text ok Risk: two-way · M4 (T8132) and M3 (T8122, T6030) for the batched read. readuser() (the READONCE copy and the single walk) is shared by the g16 and G15 stream checks.

Areas: area:gpu

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

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026

@RyanTheTide RyanTheTide 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 0fe0c64. The batched root checks retain readable-mapping and RAM verification under the VM lock, and complete any cache maintenance before copying or returning an error. The single-read path retains the existing byte order and handles unaligned sources. Hardware rows are pending.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro) g16batch row: FAIL (judge exit 1). Except for one CPU-time flag that looks like noise, every failure also happens on base.

For this PR: the gate refused all 6 bad addresses with no GPU recovery. CTS draw and command_buffers are equal. render.postfx, render.mdi and render.light gpu_us are within 1 %. render.postfx 1080p d2 submit_cpu_us is 8.2 % faster, and the d8 flag is below.

Kernel 7.3.0-g16batch, base c09b61228e62, batch tip 95212b64f7eb (#4032 #4033 #4034 #4035; #4056 #4057 in both arms). ABBA, one boot per slot, arm checked by the aurora.ko build id: a1 base d006ff51, b1 batch a9e3e314, b2 batch dd5516d2, a2 base 01025e37.

Same on both arms:

  • VK-CTS: command_buffers 60 pass / 0 fail, draw 4508 / 0, robustness 2183 / 0. 0 tests differ.
  • Stream gate: 6 bad root addresses, 0 accepted. +4, +2 and the kernel range get EINVAL, unmapped gets ENOENT (base does the same). The next clean run is valid.
  • Hang case 1 (9 clients + a hung render): bad 0, err 0 in all 6 rounds.
  • 48 clients open/close: 0 failed. pb kept 4-7 epochs, the same range on both arms. s2idle 1/1 on a1 and b1.

Why the judge says FAIL:

  • Long jobs: the first 2.5 s job ends in a GPU firmware recovery (fault_scan: GPU powered down, event 0x71) and a lost device. This happens in all four slots, on base and batch alike. The 1 recovery and 5 GPU kernel lines before the hang step come from this. The J516s can't judge the long-job check.
  • Hang case 2 (one client + a hung render): the other client gets a lost device in 2 of 3 rounds on batch, and in 2 of 3 on base. The batch doesn't make it worse, and it doesn't fix it on the J516s.
  • Speed: render.light d8 submit_cpu_us median went from 4.45 to 6.91 µs (+55 %). At d8, us_per_submit is +0.6 % and p95 is 17.8 / 17.2 µs. The other submit_cpu_us rows swing 30-40 % both ways (d32 -41 %, render.mdi +33 %), so this looks like noise. The slot pair was not re-run. gpu_us is within 0.6 % on every row. us_per_submit is within 2.6 %, except render.mdi d1 at +7.2 % (noise 13.5 %).

The J516s is back on its stock kernel (7.3.0-f3822, boot 98468598), and the kit is removed from it.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s render.light d8 recheck (batch merge tip 95212b64f7eb against base c09b61228e62, one boot each: base 70f9b303, batch 6a96f1dc, 5 repeats per core): pinned to a P-core, submit_cpu_us is 4.88 base and 4.88 batch; pinned to an E-core, 7.67 and 7.58; unpinned, 4.75 and 4.92 (+3.6 %); us_per_submit within 1 %; 0 new faults. The earlier +55 % (4.45 to 6.91 µs) is the submit thread landing on an E-core (E/P = 1.56x), not this change, so the d8 flag is cleared. Evidence work/g16batch-20261203/results/j516s/d8-recheck/.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

The J516s run refused all six bad roots and matched draw and command-buffer CTS. The remaining row at 0fe0c64f5da5 is J773g control versus batch: repeat the six refusals and clean control with no GPU recovery, compare the same CTS groups, and record ABBA submit CPU time and checked outputs for render.postfx, render.mdi and render.light at d16/d64. Keep submit-thread core placement fixed.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, T8132, G16G B0) g16batch ABBA hardware row — #4033 functional PASS (kit overall VERDICT FAIL from unrelated longjob and #4032 case-2 checks)

Tested in g16batch-20261203 (SHA256SUMS 5d61509ed258dd96, kit.sh --check 30/30 ok, kernel 7.3.0-g16batch, ABBA slots a1/b1/b2/a2, base c09b61228e62 vs batch 95212b64f7eb including #4033 at exact head 0fe0c64f5da5).

  • Stream gate negative tests (gateneg, a1 base & b1 batch identical):
    • 6/6 negative cases refused (0 accepted, 0 not exercised):
      • plus4/first (render.light), unaligned/first (render.light), kernel/first (render.light), plus4/last (render.postfx): rc -1 errno 22 (EINVAL).
      • unmapped/first (render.light), unmapped/last (render.postfx): rc -1 errno 2 (ENOENT) (unmapped GPU VA lookup miss, identical on base and batch; judge.py summary counts only 22|14 as 4/6 while reporting accepted 0, not exercised 0).
    • Controls none/first/min1 and none/first/min2: client_rc=0; post-check gateneg-after PASS; 0 GPU recoveries from gateneg.
  • VK-CTS (a1 base vs b1 batch):
    • command_buffers: 131/131 (60 pass, 0 fail), different 0, new fails 0.
    • draw: 4913/4913 (4508 pass, 0 fail), different 0, new fails 0.
    • robustness: 4939/4939 (2183 pass, 0 fail), different 0, new fails 0.
  • ABBA timing (base vs batch, 0 regressions across 82 rows):
    • render.postfx 1080p msaa=4 d2 submit_cpu_us: 116.08 -> 81.30 us (-30.0%, noise 9.2%, faster).
    • render.postfx 1440p msaa=1 d1/d2 submit_cpu_us: 122.57 -> 117.16 us (-4.4%), 112.94 -> 82.54 us (-26.9%).
    • render.mdi d1/d4: us_per_submit +0.4% / -2.7%, submit_cpu_us -2.1% / -0.9%.
    • render.light tri d1..d64: us_per_submit -1.1% to +0.2%, submit_cpu_us -24.9% to +4.1%.
  • Health: WARN=0, FAILED_UNITS=0, health: failed 0 errno 0 degraded 0 on all 4 slots. (Kit overall VERDICT FAIL was driven solely by g16pair long 2500 6 calibration timeout rc=42 on all 4 slots and #4032 case 2 ECANCELED on both a2 and b2.)

@github-actions github-actions Bot removed the ready-to-merge Meets the merge policy: merge it (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g ABBA passed the stream-gate checks, and the J516s control on the same heads had zero CTS differences or new failures. On main 9c9e5f0 the ARM64 W=1 build linked aurora.o (45 warnings, zero errors), and both scoped host suites and checkpatch passed.

@DjDeveloperr
DjDeveloperr merged commit 7588a17 into main Dec 3, 2026
13 checks passed
@DjDeveloperr
DjDeveloperr deleted the perf/g16-root-stream-batch branch December 3, 2026 21:27
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:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants