Skip to content

drm/asahi: g16: keep 64 standby parameter-buffer epochs per VM - #4035

Merged
DjDeveloperr merged 1 commit into
mainfrom
perf/g16-standby-epochs-64
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
perf/g16-standby-epochs-64

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: Keep up to 64 standby parameter-buffer epochs per VM on g16 instead of 32, so a client with 64 renders in flight stops freeing and rebuilding one on every submit.

Tested: No hardware run at the head of this PR; an earlier combined run is in Evidence. Local checks at 00f3d43b9640: 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). A VM that renders 64 deep can keep up to 3 MiB more records and use 1.5 MiB more GPU address space; a VM that renders up to 32 deep keeps what it keeps today.

Not yet: J773g and J516s base/head ABBA at the head of this PR: render.light d16, d32 and d64, with submit CPU time (median and p95) and memory per VM; many-client open/close. No performance gain is claimed until that ABBA is in.

Details

At depth 64 the standby pool holds more epochs than its ceiling, so each commit_render() trims one, with a deferred client unmap and a TLB sync, and the next submit allocates, zeroes, maps and syncs a new one. 64 is a quarter of budget::LIMIT, and a compile-time assertion keeps it inside that budget. Extra epochs are allocated only when a VM renders that deep. Bursts above the ceiling still trim back, and closing the cache still drains it.

Evidence

CPU profile on the J773g, stock kernel efed1ae377ba, gpubench 7a0dfcf8, 12-01, render.light tri d64: Window::sync_inner, rust_helper_readq and the cleanup worker's mutex spin took 55.6 % of the focused CPU samples. The submit ioctl had a 6.92 µs median and a 249.56 µs p95.

Hardware, supporting only: render.light tri d64 went from 61.3 µs on that kernel to 45.2 µs on the 16-commit tree 53599499071a (module on kernel 6c83a2a64539, 12-02, CRCs valid). Other changes in that tree affect the row, so this is not an A/B of this PR.

The host test runs the production release path at a steady depth of 64, above the ceiling, and at close.

Checks ran on main d1ae4f292b93 plus this branch.

At render depth 64 (render.light tri d=64), standby.reserved exceeds
SPARE_EPOCHS = 32, so every commit_render() -> release_reserved() trims
an epoch (deferring client unmap and UAT TLB sync) and the very next
ASAHI_SUBMIT -> Cache::prepare() allocates, zero-fills, client-maps,
and UAT-syncs a replacement via PbEpoch::new_for(). J773g CPU sampling
attributed 55.6% of focused CPU (Window::sync_inner, rust_helper_readq,
and cleanup worker mutex contention) and a 249.56 us p95 submit tail to
this per-submit churn.

Raise SPARE_EPOCHS from 32 to 64 (1/4 of budget::LIMIT = 256, matching
d=64 render pipelines) with a compile-time budget assertion:
- Shallow VMs (d <= 32) never pre-allocate extra epochs and see zero
  memory change.
- Deep d=64 render VMs retain their standby epochs across steady-state
  submits without per-submit eviction, zeroing, or UAT syncs. Each
  extra set has 96 KiB of page-rounded backing, for up to 3 MiB of
  backing plus metadata and 1.5 MiB of DYNAMIC VA per deep VM.
  Bursts above 64 still trim back to 64 and
  Cache::close() still drains all unreserved epochs immediately.
- Add a host selftest regression exercising production release_reserved()
  at steady-state depth 64, above-ceiling trim, and close drain.

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 00f3d43b: 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 00f3d43b
Conflicts ok not computed yet
PR text ok Risk: two-way · M4 (T8132) and M3 (T8122, T6030). A VM that renders 64 deep can keep up to 3 MiB more records and use 1.5 MiB more GPU address space; a VM that renders up to 32 deep keeps what it keeps today.

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 00f3d43. The larger standby cap remains within the existing budget. Allocation is demand-driven and the existing cache close still drains standby records. Hardware A/B is 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: render.light submit_cpu_us median d16 +2.2 %, d32 -41 %, d64 -5.1 % (p95 18.1 to 15.7, 18.3 to 17.7, 14.8 to 14.8 µs). 48 clients, 0 failed. The kept pb epochs are in the same range as base.

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 retained only 4–7 standby epochs. The remaining row at 00f3d43b9640 is J773g ABBA render.light at d16/d32/d64 with median and p95 submit CPU time, per-VM memory and retained epochs under pressure, and many-client open/close. Record whether the workload reaches the raised cap.

@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 — #4035 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 #4035 at exact head 00f3d43b9640).

  • ABBA render.light tri d16/d32/d64 (0 regressions across 82 rows):
    • d16: us_per_submit 54.38 -> 53.81 us (-1.1%), submit_cpu_us 5.09 -> 4.94 us (-3.0%, p95 15.2 -> 14.9 us).
    • d32: us_per_submit 51.07 -> 50.61 us (-0.9%), submit_cpu_us 6.38 -> 4.79 us (-24.9%, p95 18.7 -> 15.0 us).
    • d64: us_per_submit 46.62 -> 46.11 us (-1.1%), submit_cpu_us 7.24 -> 7.18 us (-0.9%, p95 15.0 -> 13.9 us).
  • Memory per VM at d64 (mem.txt):
    • fdinfo drm-resident-system: 624,556,808 (drm-total-system: 624,556,960) identical across all 4 slots (a1/b1/b2/a2).
    • MemAvailable: 21,012,256 / 21,021,920 kB (base a1/a2) vs 21,010,256 / 21,005,712 kB (batch b1/b2).
    • pb: M4 private allocators: blocks 2048 requests 0 bad 0, kept 4 (a1) / 6 (a2) vs 6 (b1) / 6 (b2), reused >557k.
  • Many-client open/close churn (clients.txt): CLIENTS 48 failed 0, epoch_budget_waits: 0 on all 4 slots (a1/b1/b2/a2).
  • Health: WARN=0, FAILED_UNITS=0, health: failed 0 errno 0 degraded 0 on all 4 slots; VK-CTS 0 diff / 0 new fails. (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 and J516s showed no regression and 48/48 clean client teardowns, with only 4–7 epochs retained. The host test covers the 64-epoch ceiling and drain. The merge tree after #4033 is identical to the one that passed ARM64 W=1, both scoped host suites, and checkpatch.

@DjDeveloperr
DjDeveloperr merged commit 7303d70 into main Dec 3, 2026
13 checks passed
@DjDeveloperr
DjDeveloperr deleted the perf/g16-standby-epochs-64 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