Skip to content

drm/asahi: g16: adaptive compute pipe affinity, busy-horizon coalescing, and adaptive TA wave scheduling - #3047

Merged
DjDeveloperr merged 5 commits into
mainfrom
djdev/g16-perf-wave16
Nov 25, 2026
Merged

DjDeveloperr merged 5 commits into
mainfrom
djdev/g16-perf-wave16

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What: G16 (M4) scheduling, stacked on #3043: adaptive compute pipe affinity and busy-horizon coalescing, an adaptive TA wave window with an O(1) pending scan, and cursor-ordered async pass pre-scrub.
Tested: M4 Mac mini (J773g, G16G B0, 26B123) with the full stacked series on an earlier build, not this head: gpubench 440/440, 4,670/4,670 supported CTS cases, 0 faults, 0 recoveries. Host tests 64/64 and 82/82.
Risk: two-way · M4 (J773g, J713)
Not yet: a row at the current head; CI, which runs once the base lands and this PR targets main.

Details (original description)

Summary

Optimizes Apple M4 (G16G) command scheduling, pass pre-scrubbing, and compute pipe placement without regressing multi-queue or heavy-workload latency:

  • Adaptive compute pipe affinity & busy coalescing: keeps lightweight single-queue compute pipe-affine and micro-coalesces deep single-queue bursts, while automatically bypassing coalescing and enabling 2-pipe fanout for heavy compute queues or multi-queue workloads.
  • Adaptive TA wave window & O(1) pending scan: expands TA wave capacity for light renders while retaining conservative pacing for heavy TA work, eliminates linear pending-list rescans, and orders async pass pre-scrubbing along the pass cursor so upcoming slots are clean ahead of claim.

Verification

  • Host selftests:
    • tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py — 64 passed, 0 failed.
    • tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py — 82 passed, 0 failed.
  • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks across all 3 commits.
  • Live Apple M4 (G16G B0, 26B123) silicon:
    • Full gpubench suite: 440/440 PASS across 4.00M GPU jobs (0 faults, 0 recoveries, 0 bad CRCs) — vk-rt 98/98 (1.127× vs Metal 4), vk-full 202/202 (1.094×; Wave-2 1.001×), gl-native 70/70 (1.100×), gl-zink 70/70 (1.078×).
    • 3/3 render.light procs d=16: 0 faults, 0 recoveries, 0 bad CRCs.
    • Combined live Vulkan + OpenGL/GLES CTS: 4,670/4,670 supported PASS (0 failures, 0 faults, 0 recoveries).

… and work rings

Match the render pass-slot command-record layout on Apple G16 by moving
per-unit compute microsequences and barrier records, together with the
four compute/render firmware work rings, into device-lifetime
Class::FwCoherent mappings owned outside per-VM arenas.

Each hardware compute unit index (0..COMPUTE_UNITS) is device-global and
claimed by one flight at a time. Previously every VM's ComputeSlot
allocated its own uncached seq and barrier pages, while prefix_compute
hardcoded ComputeRefs::seq to the embedded sequence inside the uncached
compute work image (work + 0x900) and wrote 1248 bytes of write-combined
body per clean same-VM submit. The work image already names its
microsequence by address (+0x760) and size (+0x768), and
encode_compute_rt already emits every microsequence self-reference
relative to ComputeRefs::seq.

Share device-lifetime UnitCmds (seq and barrier) per hardware compute slot
via resources::ComputeCmds (indexed by hw_slot so SCS sets map to the
exact hardware ledger slot they claim), point ComputeRefs::seq to
s.seq.va, write the 768-byte microsequence into cacheable s.seq, and
shrink clean same-VM WC work writes to work[0x720..0x900]. Likewise
allocate the two compute and two render work rings (host-written VA
arrays, never host-read) from a ManuallyDrop device-lifetime
Factory::persistent_objects_probe allocator after sealing session
allocations; because Graphs::finish() runs during platform probe() before
drm_dev_register(), the probe-only allocator prepares its backing against
the bound platform device while non-probe private allocations keep
requiring registration_guard(). Keep ComputeSlot::work in Class::Shared so
host retirement reads of DESCRIPTOR_COMPLETED and 26B123 work_ticks stay
strictly coherent without relying on ASC-to-AP cache clean ordering.

Signed-off-by: Diljit Singh <[email protected]>
Compute retirement checks DESCRIPTOR_COMPLETED (0xe54) and
DESCRIPTOR_COUNTER (0xe4c) via FwObject::r64(). Both packed fields are
4-byte aligned (offset % 8 == 4), which previously bypassed the 8-byte
fast path and fell through to FwObject::read()'s byte loop, issuing 16
single-byte write-combined loads and 4 read barriers per call (32 byte
loads and 8 barriers per retired compute command).

Add a 4-byte-aligned fast path in FwObject::r64() that reads matched
aligned 32-bit word pairs separated by rmb(), preserving the exact
tear-free double-snapshot and EAGAIN retry semantics while cutting each
4-byte-aligned receipt check to 4 aligned 32-bit loads.

In Firmware::compute_ticks_with(), also read ABI-defined work_ticks
before falling back to unit.its. On 26B123, firmware leaves unit.its
zeroed and records compute GPU ticks in work_ticks, so probing work_ticks
first avoids two always-zero WC r64 reads and two read barriers per
compute command while preserving the ITS fallback and 25G83 behavior.

Signed-off-by: Diljit Singh <[email protected]>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 8495c00a: not ready yet

Check Detail
CI at head running running: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 8495c00a, a Mac and a result in the PR body or a comment
Conflicts ok not computed yet
PR text ok Risk: two-way · M4 (J773g, J713)

Areas: area:gpu

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at b84cfd5fd9: FINISH, then merge. No code blockers; one row is missing.

Blockers:

  1. No hardware row at this head. The rows in this PR ran the full stack on an earlier build, not this branch as it is now. Fix: one J773g run at this head, or on a candidate that contains this head unchanged (see below).

Checked: this PR's own 3 commits against its base; the reworked can_queue_behind_with_ta() keeps the doomed, recovery-suspect and InitBM drain checks; no Apple material in code or commit messages; no chip or board gates; no new parameters; only bounded waits; commits carry human authors and Signed-off-by, no AI attribution; CI does not run on a stacked base and will run once this PR targets main. This branch still carries the cross-VM compute overlap from #3042, so it should merge only in the same train as #3087. I reformatted the PR body to What / Tested / Risk / Not yet, with the original kept folded and its attribution line removed.

Row

One J773g run on a candidate that contains the heads of #3087, #3057 and #3046 unchanged (boot, idle/wake, deep sleep, vk-mustpass-short, gpubench vk-full, compute.long, 0 GPU faults) counts for every non-draft PR in this stack at once.

…ce busy horizons

Keep single-queue barrier-free compute streams affine to their active
CDM pipe in choose_compute_pipe() and remove pipe_fold_cap from
publish_prefix_body() so deep single-queue horizons fold into one
workqueue prefix without bouncing between pipes or injecting cross-pipe
c2c barriers, while independent queues and cross-VM compute still
balance across both CDM pipes.

Add busy-state same-queue horizon micro-coalescing (COALESCE_MAX_CMDS =
6, COALESCE_WINDOW_US = 18): only when a single queue already has >= 2
active commands in flight and every pending job belongs to that same
queue and VM as a foldable barrier-free compute or non-InitBM render
horizon, submit_locked() defers publish_checked() behind an hrtimer
(rearm_after()) for up to 18 us so back-to-back SUBMIT ioctls fold into
one multi-command flight. Shallow d=1/d=2 pipelines, barriered streams,
RT/SCS work, and multi-queue/cross-VM arrivals bypass coalescing
immediately with zero added latency, and any flight retirement or
deadline expiry flushes the held batch immediately.

Signed-off-by: Diljit Singh <[email protected]>
…-ordered async pass pre-scrub

Light single-layer render passes (tilemap_bytes <= 64 KiB) do not
saturate M4 firmware's TA/scene pipeline at 4 passes, while deep
single-queue render bursts (d=64) hit three avoidable CPU/pacing cliffs:
1) TA_WAVE_PASSES=4 caps light render waves and limits render busy
micro-coalescing to 2 passes; 2) publish_checked() re-read WC fw_stamp
and rescanned pending[..i] for every blocked follower of the head queue;
and 3) stage_displaced_pass_scrubs() scanned slots 0..47 instead of
starting at pass_cursor, leaving upcoming slots dirty when >8 displaced
slots were pending.

Precompute RenderCommand::heavy_ta on admission, raise the light single-
layer TA wave cap to TA_WAVE_PASSES_LIGHT=8 while keeping conservative
TA_WAVE_PASSES=4 whenever any active or pending pass is heavy, adapt
ta_wave_ready() hysteresis to cap - 2, and raise SCHEDULER_CREDITS to
64. Hoist ta_pending_passes() once per publish_checked() pass and skip
blocked same-queue followers in O(1), and scan
stage_displaced_pass_scrubs() cursor-ordered from pass_cursor while
preserving pick_pass_in_for's same_dirty > unowned preference.

Signed-off-by: Diljit Singh <[email protected]>
Unconditional single-queue 1-pipe compute affinity helped light
compute streams fold onto one CDM workqueue, but serialized heavy
compute streams (bandwidth/fill/overlap passes >= 200 us per
command) onto a single CDM pipe and left multi-queue overlap
workloads susceptible to the 18 us busy-coalesce window when
another queue already had an active flight.

Track a lock-free per-queue EWMA of retired hardware CDM GPU
execution duration in microseconds (from the existing single- and
multi-command timestamp reads in stat_retire, without extra WC
reads) and add a cold-start probe for a sole single-command
compute flight exceeding 180 us before its first retirement:
- Light single-queue compute (< 200 us) keeps 1-pipe affinity,
  unbounded same-pipe horizon folding, and busy coalescing.
- Heavy compute (>= 200 us EWMA or sole inflight >= 180 us)
  bypasses busy coalescing, fans out across both CDM pipes, and
  caps barrier-free folding to keep both pipes balanced.
- Busy coalescing also bypasses immediately whenever any active
  flight belongs to a different queue so multi-queue render and
  async compute/render overlap see zero micro-coalesce delay.

Extend the publication host selftests to cover adaptive heavy
detection, EWMA transitions, pipe balancing, and cross-queue/heavy
busy-coalesce bypasses.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr changed the base branch from djdev/g16-perf-wave15 to djdev/g16-compute-overlap-persistent-rings November 24, 2026 20:25
@DjDeveloperr
DjDeveloperr changed the base branch from djdev/g16-compute-overlap-persistent-rings to main November 25, 2026 01:38
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 25, 2026 01:38
@DjDeveloperr
DjDeveloperr merged commit 03b6e59 into main Nov 25, 2026
4 checks passed
@RyanTheTide
RyanTheTide deleted the djdev/g16-perf-wave16 branch November 27, 2026 13:21
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:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant