Skip to content

drm/asahi: g16: widen compute concurrency to 64/16 and cache shared UMA and fw_stamp - #3340

Open
DjDeveloperr wants to merge 3 commits into
mainfrom
perf/g16-compute-cu64-cached-uma
Open

DjDeveloperr wants to merge 3 commits into
mainfrom
perf/g16-compute-cu64-cached-uma

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #3287

What: widen G16 compute concurrency to firmware/ring bounds and map shared compute UMA descriptors and compute fw_stamp cells ASC-cached.

Two commits stacked cleanly on #3287 (078f963c, perf/g16-compute-shared-uma):

  1. Widen compute units, pipes, and flights (ee819069):
    Now that non-SCS compute VMs share one 32 MiB UMA pool and hardware UMA slot (1..=32) instead of one per unit, compute concurrency is no longer capped at 24 units / 8 pipes / 32 flights. Every size is derived from its hardware/firmware limit:

    • COMPUTE_UNITS = 64: bounded by the u64 slot/quarantine mask width (<= 64), SCHEDULER_CREDITS = 64, the 256-entry compute work ring ((COMPUTE_UNITS - 1) * MAX_COMPUTE_RING_ENTRIES = 63 * 3 = 189 < QUEUE_CAP = 256), and client VA compaction (62 * 1 MiB extension records at EXT_COMPUTE_REC_BASE..scs_compute_records(0), preserving 26 disjoint 33 MiB SharedComputeUma migration windows below EXT_COMPUTE_REC_BASE, all compile-time asserted).
    • COMPUTE_PIPES = 16: 16 contiguous Type-1 completion events (15..=30) in event word 1, fitting entirely inside word 1 without reading an extra event word (RETIRED_COMPUTE_PIPES = 16).
    • FLIGHTS = 64: one in-flight Flight per compute unit, well inside AHEAD_RECORDS = 128 and the wrapped stamp half-window.
    • compute_flights() = COMPUTE_UNITS.saturating_sub(1).min(FLIGHTS) = 63: retains one spare compute unit for displacement so one queue never starves another queue or VM.
    • SCS_COMPUTE_UNITS stays bounded by COMPUTE_UMA_SLOTS = 32 and pick_scs_compute_slots() clamps to COMPUTE_UMA_SLOTS.
  2. Map shared compute UMA descriptors and compute fw_stamp ASC-cached (97d88a25):

    • Add a device-lifetime ComputeUmaPool on Factory that allocates persistent ASC-cached (Class::FwCoherent, 0x443) SharedComputeUma descriptors paired with uncached (Class::Fw) submission counters. Because descriptors are never unmapped, firmware caches them across flights; a ComputeUmaLease returns to the pool on drop only when every published flight retired normally (published_flights == retired_flights), keeping aborted or quarantined records permanently out of circulation.
    • Map compute QueueSession.fw_stamp ASC-cached (Class::FwCached, 0x443), matching macOS 26B123 (render fw_stamp stays Class::Shared), and observe compute progress and retirement through the uncached compute service stamp written by the notifier service after firmware updates fw_stamp and completes descriptor bookkeeping.
    • Drop host reads of the ASC-cached shared descriptor at retirement and idle reuse, checking the uncached host submission counter and host conservation instead.

A third candidate commit (clearing work+0x81c on non-tail commands of multi-command compute flights + an 8 us sliding compute coalesce deadline) was A/B tested and dropped: the 8 us sliding timeout fragmented 4–5 command flights into 1–2 command flights (grouped 435k -> 309k, +95k SubmitRecords) and regressed compute.light d=16/32/64 by +3.3% to +6.2%.

Tested:

  • J773g at 3695a16489beb, including the documented per-queue limit increase from 32 to 64.
    • Arm64 kernel compile + asahi KUnit (./tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/gpu/drm/asahi/.kunitconfig): 463 tests: 459 passed, 4 skipped, 0 failed.
    • Host selftests (tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py): 26/26 passed, including test-resources.py (75/75: FwCoherent descriptor / Fw counter classes, settled pool recycling, permanent quarantine non-recycling, 64-unit VA disjointness), test-publication.py (87/87), test-poll-retire.py (43/43), test-stamp-wrap.py (28/28), and test-progress-wrap.py (20/20).
    • scripts/checkpatch.pl --strict on all 3 commits (078f963c..3695a16489beb): 0 errors, 0 warnings, 0 checks per commit; rustfmt: 0 new diffs.
    • J773g native build + exact-head re-gate boot (7.3.0-ARCH-m4cir2final-3695a164, module build ID 58aae568f3648ecfdb946e319fad5077e30ad71b, standalone on drm/asahi: g16: share one compute UMA descriptor and pool per VM #3287 without drm/asahi: g16: map the compute notifier records ASC-cached #3285, 946,628 jobs, 0 kernel findings, 0 GPU faults/recoveries/hangs, compute_owners: retired 64 quarantined 0 reusable 48):
      • 35-VM concurrent live Vulkan compute stress (vk-uma-quarantine clean 35): pre_ok=35 post_ok=35/35 fresh_ok=1.
      • compute.light d=4/8/16/32/64: 40.94 / 29.45 / 22.70 / 20.96 / 20.29 us (d=16/32/64 beat Metal 4 by 4.3%–5.5% even before stacking drm/asahi: g16: map the compute notifier records ASC-cached #3285); procs d=16: 38.93 us.
      • sync.signal binary / timeline / host: 24.77 / 24.87 / 169.25 us (binary/timeline beat Metal 4 by 0.9%–1.6%).
      • compute.heavy alu d=1/2/4: 771.61 / 537.35 / 537.35 us; bw d=1/2/4: 1519.91 / 1267.43 / 1269.04 us; concurrent.cr interleave / queues: 64.17 us / 1.03x; render.light tri d=16: 58.93 us.
  • J773g (M4 Mac mini, T8132, G16G B0, 26B123 firmware) full ABBA + CTS + s2idle gate ran stacked on #3285 + #3287 (r2base = 9e0a1b30, r2cu64 = efe761b6, r2c2 = 70ad7b64, where #3285 relocates the same uncached work+0x800 service stamp from notifier + COMPUTE_STAMP to user_stamp):
    • Commit isolation (2-boot A/B per step, 0 faults/recoveries/findings):
      • C1 (r2base -> r2cu64): compute.light d=64 22.87 -> 21.48 us (-6.10%), d=32 22.59 -> 21.97 us (-2.73%), procs d=16 39.96 -> 39.04 us (-2.31%); slot holds dropped 95.5% (384,607 -> 17,266) and cross-VM compute retargets dropped 98% (2,900 -> 60).
      • C2 (r2cu64 -> r2c2): compute.light d=4 -5.24%, d=16 -9.92%, d=32 -12.04%, d=64 -11.49%, procs d=16 -8.25%, sync.signal binary -10.46%, sync.signal timeline -10.10%.
    • Formal 4-boot ABBA (r2base -> r2c2 -> r2c2 -> r2base, 144/144 ok, 0 kernel findings, 0 GPU faults/recoveries/hangs, ~963k–994k jobs per r2c2 boot):
benchmark r2base (#3285+#3287) r2c2 (C1+C2) delta Metal 4 vs Metal
compute.light d=4 40.73 us 39.29 us -3.54% 37.31 us +5.31%
compute.light d=8 29.31 us 28.63 us -2.33% 27.72 us +3.28%
compute.light d=16 23.41 us 22.25 us -4.95% 23.89 us -6.86%
compute.light d=32 22.56 us 20.20 us -10.46% 21.90 us -7.74%
compute.light d=64 22.80 us 19.74 us -13.40% 21.46 us -8.01%
compute.light procs d=16 40.55 us 36.40 us -10.24% 32.38 us +12.42%
sync.signal binary d=2 25.92 us 23.97 us -7.52% 25.00 us -4.12%
sync.signal timeline d=2 26.00 us 24.00 us -7.70% 25.28 us -5.06%
sync.signal host d=1 163.56 us 166.59 us +1.85% 156.00 us +6.79%
compute.heavy alu d=1 757.00 us 764.53 us +0.99% 827.81 us -7.64%
compute.heavy alu d=2 537.06 us 537.06 us 0.00% 538.79 us -0.32%
compute.heavy alu d=4 537.06 us 537.06 us 0.00% 538.79 us -0.32%
compute.heavy bw d=1 1512.87 us 1524.39 us +0.76% 1773.05 us -14.02%
compute.heavy bw d=2 1272.27 us 1275.53 us +0.26% 1436.78 us -11.22%
compute.heavy bw d=4 1270.65 us 1275.53 us +0.38% 1436.78 us -11.22%
concurrent.cr light interleave d=4 64.02 us 63.38 us -0.99% 57.10 us +11.00%
concurrent.cr heavy queues d=4 1.03x 1.03x -0.03% 1.00x +3.00%
render.light tri d=16 60.60 us 59.74 us -1.41% 48.29 us +23.71%
  • J773g gate boot (kit-r2c2, 198,348 jobs / 348,964 commands / job_max 64, 0 kernel findings, 0 GPU faults/recoveries/hangs):
    • 35-VM concurrent live Vulkan compute stress (vk-uma-quarantine clean 35): pre_ok=35 post_ok=35/35 fresh_ok=1.
    • VK-GL-CTS compute + synchronization subsets (--jobs 1, excluding drm/asahi g16: dEQP-VK.synchronization*multi_queue* faults the GPU and fail-stops it on J773g (main 61c7b88a) #3201 multi_queue / cross_instance, 16,500 cases executed in slot): 8,088 Pass / 8,412 NotSupported / 0 Fail, recoveries=0.
    • s2idle suspend/resume: woke cleanly after 13 s (S2IDLE_POST success=1 fail=0, DELTA_ERR=0), post-wake 7/7 suite passed (including CRC-verified render.postfx MSAA 4x, compress.bw 1440p, render.mdi 1024 draws; compute.light d=16 = 22.19 us).

Risk: two-way · Macs on the g16 backend (M4 G16G; M3 G15S and G15G). A plain revert undoes it.

  • Mapping SharedComputeUma.descriptor as FwCoherent and compute fw_stamp as FwCached relies on device-lifetime backing for cached descriptors and on firmware writing the uncached compute service stamp only after descriptor bookkeeping completes. The J773g stress and suspend/resume rows above exercised this assumption. Mitigated by ComputeUmaPool never unmapping allocated descriptors, refusing to recycle any lease whose published flights did not all retire normally (published_flights == retired_flights), retaining active leases in Slots across hardware slot handoff, and host selftests verifying both normal reuse and permanent quarantine pinning.
  • sync.signal host d=1 (+1.85%) and compute.heavy d=1 (+0.76% to +0.99%) show minor shifts while remaining 7.6%–14.0% ahead of Metal 4 on compute.heavy d=1.

Not yet:

…o 64

With non-SCS compute VMs sharing one UMA descriptor, pool, and hardware
UMA slot across all units, each extension compute unit only backs
288 KiB of preempt, auxiliary, and context-store state. Previously,
COMPUTE_UNITS=24, COMPUTE_PIPES=8, and a 32-flight compute cap forced
16 concurrent compute processes to share 8 pipes and contend over only
16 reusable units, and capped deep d=32/d=64 single-queue streams at 23
commands in flight.

Widen COMPUTE_UNITS to 64, COMPUTE_PIPES to 16 (events 15..=30 in
type-1 event word 1), and FLIGHTS to 64, and derive
params::compute_flights() from COMPUTE_UNITS and FLIGHTS:
- Compact extension compute unit records (k >= 2) into 1 MiB intervals
  at EXT_COMPUTE_REC_BASE (0x70b4000000..0x70b7e00000), keeping 26
  disjoint 33 MiB SharedComputeUma migration windows below it and base
  units 0..2 unchanged.
- Widen compute unit bitmasks (quarantined_compute_mask,
  compute_slot_mask, Lifetime masks) from u32 to u64 while keeping SCS
  slot selection bounded by COMPUTE_UMA_SLOTS (32).
- Update host selftests to validate 64 compute units, 16 compute pipes,
  26 UMA migration windows, and 64-bit unit masks.

Signed-off-by: DjDeveloperr <[email protected]>
…ached

Shared compute UMA descriptors and compute queue fw_stamp records do
not need to be uncached on the firmware side:

- Add a device-lifetime ComputeUmaPool on Factory that allocates
  persistent ASC-cached (FwCoherent) SharedComputeUma descriptors
  paired with uncached (Fw) counters. Because the descriptor is never
  unmapped, firmware can cache it across flights; a lease returns to
  the pool on drop only when every published flight has retired
  normally, keeping aborted or quarantined records out of circulation.
- Map compute QueueSession fw_stamp records ASC-cached (FwCached) and
  observe compute retirement through the uncached service stamp written
  by the notifier service after firmware descriptor bookkeeping.

This drops uncached firmware writes on every shared compute flight and
eliminates the host read of the shared descriptor at retirement.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 03:19
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all 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) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at 1de4e8f8: not ready yet

Check Detail
CI at head ok 1 check passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok the PR body at 3695a164; the changed files are byte-identical at 1de4e8f8
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · Macs on the g16 backend (M4 G16G; M3 G15S and G15G). A plain revert undoes it. - Mapping SharedComputeUma.descriptor as FwCoherent and compute fw_stamp as FwCached relies on device-lifetime backing for cached descriptors and on firmware writing the uncached compute service stamp only after descriptor bookkeeping completes. The J773g stress and suspend/resume rows above exercised this assumption. Mitigated by ComputeUmaPool never unmapping allocated descriptors, refusing to recycle any lease whose published flights did not all retire normally (published_flights == retired_flights), retaining active leases in Slots across hardware slot handoff, and host selftests verifying both normal reuse and permanent quarantine pinning. - sync.signal host d=1 (+1.85%) and compute.heavy d=1 (+0.76% to +0.99%) show minor shifts while remaining 7.6%–14.0% ahead of Metal 4 on compute.heavy d=1.

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

Non-author review at 97d88a257221: READY on the code, 0 blockers. This PR is stacked on #3287 (perf/g16-compute-shared-uma, 078f963c8b97) and merges after it. CI and hardware rows at this head are still owed (below).

Commit 1: 64 units, 16 pipes, 64 flights (ee8190697514)

  • Bounds: these hold and are asserted at compile time.
    • Compute ring: 63 × 3 = 189 entries, below QUEUE_CAP 256.
    • Flights: compute flights are 63 (COMPUTE_UNITS - 1) within FLIGHTS 64, and all flights stay under AHEAD_RECORDS 128.
    • Events: the 16 pipe events 15..=30 fit in type-1 event word 1 (EVENT + COMPUTE_PIPES <= 32 is asserted), and TA/FS stay in word 4.
  • Masks: the compute unit masks (quarantine, slot, Lifetime) are now u64, and the UMA-slot masks stay u32 for the 32 slots. pick_scs_compute_slots() now clamps to COMPUTE_UMA_SLOTS, which also keeps the compute_slot_mask() as u32 cast in compute_uma_mask() lossless.
  • Client VA:
    • Extension unit records move to EXT_COMPUTE_REC_BASE at a 1 MiB stride and end below scs_compute_records(0) (asserted).
    • The 26 shared UMA pool windows end at or below EXT_COMPUTE_REC_BASE (asserted).
    • Both Placement::Base unit sets are built with the shared UMA, so compute_pool(k) never sees a unit index past the windows; ComputeSlot::new is dead code.
  • Chips: the sizes apply to the whole g16 backend, so T6030 and T8122 change as well, hence the J516s row below.

Commit 2: ASC-cached shared UMA descriptor and compute fw_stamp (97d88a257221)

  • Lease accounting: ComputeUmaLease counts publish() once per published shared flight, and retire() only on a full receipt (owner_retired()). After an abnormal retirement the set stays out of the pool for good; that is bounded by quarantine.
  • When a set can be reused:
    • A set returns to the pool only when its last holder drops.
    • retained_uma[slot] keeps it until another owner overwrites that hardware slot, so firmware's uma_mgr_table never points at a set that is being reused.
    • A reused set is zero-filled and then fully rewritten with compute_uma_manager_image before first use.
    • The early-error paths drop an unpublished, settled lease, so the set goes back to the pool.
  • Coherency: the descriptor is a firmware-only FwCoherent record (cacheable host and ASC mappings), the same contract its first use already relies on.
  • fw_stamp:
    • Compute fw_stamp is now FwCached, and the host never writes it.
    • Every host read now goes to the uncached notifier COMPUTE_STAMP.
    • The remaining users of the fw_stamp VA are firmware barrier records (c2c, c2ta, c2fs), which the ASC evaluates through its own mapping.
    • Render fw_stamp stays Shared.

Local checks (scratch worktree)

  • checkpatch.pl --strict: clean on both commits.
  • asahi-m4 host suite (run-host-tests.py): 26/26 pass.
  • rustfmt: one new hunk. The two new const _: () = assert! lines in g16/hw.rs would each fit on one line. The other files add no new differences.
  • Both commits are signed off, with no attribution.

Owed before merge

  • Build and KUnit at this head. Only pr-text / pr-text ran here at posting: apple-build, KUnit and host-tests only run for PRs against main, so nothing has compiled this exact head yet. That includes the Default derives removed from Stats and Prof. Either build it on the mini or retarget once drm/asahi: g16: share one compute UMA descriptor and pool per VM #3287 lands.
  • A J773g row at this exact head.
  • A J516s (M3 Pro, G15S) row, because this is shared g16 code.
  • Notes, not blocking:
    • Retirement now trusts the service stamp alone: compute_uma_retired() compares only host-written values, and the idle check no longer reads COMPLETED or COUNTER. Please name in the commit message the 26B123 capture that shows the service stamp is stored after the UMA descriptor bookkeeping.
    • QUEUE_LIMITS.max_in_flight_per_queue, as reported to userspace, goes from 32 to 64 with FLIGHTS. That is worth a line in the commit message.
    • The RENDER_SLOTS doc in g16/hw.rs still says "post at most FLIGHTS = 32 SubmitRecords".

DjDeveloperr added a commit that referenced this pull request Nov 27, 2026
Address non-blocking review notes on PR #3340:

- Update the stale FLIGHTS = 32 reference in the RENDER_SLOTS doc
  comment to FLIGHTS = 64.
- Format the two new compute_list/compute_context compile-time asserts
  in g16/hw.rs to match rustfmt.

Documented clarifications from review:
- Userspace visibility: widening FLIGHTS to 64 raises
  QUEUE_LIMITS.max_in_flight_per_queue from 32 to 64.
- Compute retirement ordering: in 26B123 armfw_g16g.im4p, firmware
  advances UMA COMPLETED and cleans the ASC-cached descriptor in
  FUNC_0x2d540 before AGFCLDataMasterPostProcessingCallback (0x24fd8)
  and notifier flush FUNC_0x25198 store the uncached service stamp at
  0x25634 (matching the J773g 26B123 live Metal compute hypervisor
  capture where descriptors and fw_stamp map 0x443 ASC-cached while
  service stamps map uncached).

Signed-off-by: DjDeveloperr <[email protected]>
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 27, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Re-review at 3695a16489be: CHANGES NEEDED, 1 blocker. The blocker is in the text only; the code is fine.

Blocker: firmware disassembly details in the new commit message and the PR body

  • To explain the retirement ordering, the 3695a16489be commit message cites function offsets, a code address and an Apple symbol name taken from a disassembly of the 26B123 GPU firmware. The PR body's Tested line repeats the offsets.
  • These are RE byproducts, and the org rules keep them private (AGENTS.md rule 1, policy/ip-and-tainted-data.md). What we learned from them can be stated in our own words.
  • Fix:
    • State the ordering the way our own J773g 26B123 capture or a measurement shows it, and drop the offsets, the address and the symbol name. If the ordering rests only on the disassembly, it needs a basis of our own, such as a trace or a measurement.
    • Edit the PR body now.
    • Fix the commit message before merge: the stack gets rebased when it is retargeted to main. At that point the two clarifications (the ordering, and QUEUE_LIMITS going from 32 to 64) are best folded into the commits that make those changes.

Checked at this head

  • Delta: 97d88a257221..3695a16489be is a fast-forward of one commit that touches only g16/hw.rs. It fixes the RENDER_SLOTS doc (FLIGHTS = 64) and reformats the two new asserts, with no code change. rustfmt now reports no differences in hw.rs, and checkpatch.pl --strict is clean. The commit is signed off, with no attribution.
  • Hardware: the J773g rows at this exact head (35-VM stress 35/35 and the gpubench rows) close the exact-head row I asked for. The CTS and s2idle gate is still from the stack that includes drm/asahi: g16: map the compute notifier records ASC-cached #3285.
  • CI: pr-text / pr-text,readiness / readiness. The other checks only run for PRs against main, so build and KUnit come with the retarget.

Still owed: the text fix above, the J516s (M3 Pro, G15S) row, and build and KUnit once the PR is retargeted to main.

Document the 64-flight limit and format the layout assertions. The
reported per-queue limit rises from 32 to 64. Compute completion uses
the uncached service stamp so progress and retirement do not depend
on CPU reads of cached firmware records.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the perf/g16-compute-cu64-cached-uma branch from 3695a16 to 1de4e8f Compare November 27, 2026 23:29
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 27, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded 12-01: not a hold under the merge bar (no shown failure). Full diff review deferred; follow-ups: land #3287 and retarget, main CI, hardware row, keep firmware-disassembly text out

Verdict: HOLD at 1de4e8f8

Blockers:

  1. Targets open non-main base branch perf/g16-compute-shared-uma (#3287 is still OPEN); full main CI has not run.
  2. Missing hardware row at head (needs-hw-row), and ensure any firmware-disassembly details flagged in the earlier review comment stay stripped from commit messages and PR text before merge.

Checked:

  • Verified #3287 is still OPEN and base ref is perf/g16-compute-shared-uma.
  • Deferred full diff review until #3287 lands and this PR is retargeted onto main with green CI and hardware row.
Evidence
  • Base ref: perf/g16-compute-shared-uma (#3287 state: OPEN).

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Nov 29, 2026
Base automatically changed from perf/g16-compute-shared-uma to main November 29, 2026 16:01
@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 30, 2026

This branch has not been deployed

No deployments
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:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (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