Skip to content

drm/asahi: g16: never run compute beside another VM's compute - #3087

Merged
DjDeveloperr merged 5 commits into
mainfrom
djdev/g16-no-cross-vm-compute
Nov 25, 2026
Merged

DjDeveloperr merged 5 commits into
mainfrom
djdev/g16-no-cross-vm-compute

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: On the g16 (M4) backend, compute now publishes only behind its own VM's flights.

Before, compute queued behind another VM's compute on the CDM pipes with no barrier between the two. With several clients, the overlapped dispatches occasionally lost their results without a fault: dEQP-VK texture_functions readbacks came back zero or partial, and a ray-query dispatch was reported complete with its results unwritten. Renders still pipeline across VMs, and one VM's compute still pipelines on both pipes.

Stacked on #3074 (djdev/g16-poll-cadence-hold-causes).

Tested:

  • Host only, at 04671de:
    • asahi-m4 host tests 25/25, 430 Rust tests, 0 failed (this base has no ray-tracing test yet).
    • asahi-g15 81 passed, 0 failed, 2 ignored.
    • checkpatch.pl --strict 0/0/0; git diff --check clean.
  • M4 Mac mini (J773g, G16G B0), with the identical change on the M4 7.3 integration kernel, same machine and Mesa:
    • dEQP-VK.glsl.texture_functions.* (7,925 cases) with 6 parallel processes, 3 consecutive runs.
      • Before: 105, 111 and 105 failures.
      • After: 0, 0 and 0 (4,903 pass each, the rest not supported).
      • 0 device lost, 0 GPU faults, 0 recoveries, 0 new kernel errors.
    • gpubench vk-full and vk-rt: 300/300 rows, 0 CRC mismatches, 0 GPU faults.
      • Single-process rows (271): +0.12 % geomean.
      • Multi-process render rows: 0.995× to 1.006×.
    • Slower, by design: multi-process compute now runs one VM at a time.
      • compute.light [procs] d=2..16: −30 % to −64 %.
      • compute.heavy alu [procs]: −11 % to −25 %.
      • vk-full over all 200 rows: −1.5 % geomean.
  • g16 is the M4-only backend; no other Mac runs this code.

Risk: two-way · M4 (J773g / G16G)

Not yet:

  • An M4 hardware boot of this exact stacked branch. The hardware rows are from the integration kernel, where the same change sits next to the SCS compute rule (its test updates cover that rule too).
  • CI: the base is a feature branch, so host-tests do not run here.
Details

Before.

  • needs_engine_drain() drained compute only behind another VM's render.
  • can_queue_behind_with_ta() let compute queue behind any healthy compute flight, of any VM, on either CDM pipe.

After.

  • Compute drains behind any flight of another VM: (is_compute || (is_render && f.computes != 0)) && !same VM.
  • Compute queues only when every flight in flight belongs to its own VM.
  • Render is unchanged: it pipelines behind other VMs' renders, and drains behind other VMs' compute as before.
  • G15 runs one VM at a time for the same reason: its publish stops at any flight of another VM.

Why one VM at a time and not a barrier.

  • With one dEQP-VK process, none of the 7,925 cases fails.
  • Every case that failed with six processes passes alone.
  • The failures stop entirely once compute waits for other VMs' flights.
  • The loss is silent (no fault, no recovery), so it is excluded structurally rather than fenced per dispatch.

Cost. Concurrent compute from different processes no longer overlaps; see the slower rows above. Single-process work, and multi-process render, are unchanged.

Also changed.

  • The drain_cross hold cause now documents both cases.
  • The FLIGHTS comment.
  • The publication harness's cross-VM expectations: the overlap matrix, the alternate-bypass test, the two-pipe dispatch test, and timed compute beside render.
Evidence
  • Base: djdev/g16-poll-cadence-hold-causes at 9f1dc2f59d46 (drm/asahi: g16: poll cadence fixes and publication hold causes #3074).
  • Commit: 04671de4b919 drm/asahi: g16: never run compute beside another VM's compute.
  • Host, at the head:
    • tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py: 25 ok, 0 not ok. test-publication.py 83/83.
    • tools/testing/selftests/drivers/gpu/asahi-g15/run.py: 81 passed, 0 failed, 2 ignored.
    • Reverting only the engine.rs change fails 4 publication tests: cross_vm_render_compute_overlap_matrix, timed_compute_queues_behind_same_vm_and_coexists_with_render, two_pipe_concurrent_compute_dispatch_and_fw_timestamp_safety and alt_bypass_does_not_starve_cold_cross_vm_initbm_while_warm_overlaps.
  • M4 A/B (J773g, G16G B0; integration kernel with and without this change; same Mesa):
    • texture_functions with 6 processes:

      • before: Fail 105/111/105;
      • after: Fail 0/0/0, Pass 4,903 ×3, NotSupported 3,022 ×3.
    • gpubench vk-rt (98 rows) and vk-full (202 rows):

      • all rows ok, crc_bad 0, 0 faults, 0 recoveries, 0 dmesg errors;
      • single-process rows (271): 1.0012×;
      • all 282 comparable rows: 0.9886×, W/T/L (>5 %) 3/267/12.
    • Slower [procs] compute rows (before → after):

      row before after
      compute.light d=2 76.8 µs 110.3 µs
      compute.light d=4 57.1 µs 107.6 µs
      compute.light d=8 46.2 µs 106.6 µs
      compute.light d=16 39.7 µs 111.3 µs
      compute.heavy alu d=2 637.8 µs 714.3 µs
      compute.heavy alu d=4 538.8 µs 714.3 µs
      compute.heavy alu d=8 537.6 µs 718.4 µs

@github-actions github-actions Bot added 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) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at d77b0f0d: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
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 d77b0f0d, 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 / G16G)

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 04671de4b9: FINISH, then merge. No code blockers; one row is missing.

Blockers:

  1. No hardware row at this head (the PR says so). Fix: one J773g run at this head, or on a candidate that contains this head unchanged (see below), with the six-process dEQP-VK.glsl.texture_functions.* run that showed the loss.

Checked: the one commit against the base: compute now drains behind any flight of another VM, in both needs_engine_drain() and the queue-behind test, while one VM's compute still uses both pipes and renders still pipeline across VMs; the host tests are updated to match; 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 is the fix for the cross-VM compute overlap that #3042 adds, so it should land in the same train as #3042, or its commit should move down onto #3042. The PR body already has What / Tested / Risk / Not yet.

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.

publish_checked() marks a ready job that it could not publish for want
of TA wave headroom (ta_wave_wait) or pass and flight headroom
(slot_wait). A poll pass that sees either flag repolls after repoll_us
(8 us by default), so the job publishes as soon as TA progress or a
retirement makes room.

A SUBMIT that publishes inline and leaves the same state behind did not
do this. It rearmed the poll timer with rearm_us(false), which is half
the flight duration EWMA clamped to resnap_us, so 100 us for renders
longer than 200 us. Unless a stage event arrived first, the job waited
that long after the room appeared. This is the case for the later
passes of a multi-pass render that does not fit in one TA wave.

Treat the two flags in submit_locked() as poll_step() does: rearm
soon when the engine is not frozen and a job is still pending.

Signed-off-by: Diljit Singh <[email protected]>
poll_step() ran the full idle housekeeping on every pass that started
with nothing in flight: Session::check() (an ASC control read, a powered
SGX pstate read and a walk of the adopted UAT bindings),
Objects::health(), service_power() and a drain of every receive ring,
including the nine log sub-rings and ktrace. A pass with work in flight
holds the same checks to their cadence, 5 ms while active.

Shallow back-to-back submissions reach the idle state after every
completion, and idle_resnap() keeps a short poll timer armed across that
gap. The timer pass then repeated all of these checks under the device
lock, between one completion and the next SUBMIT, which waits on the
same lock.

Inside the 1 ms idle cadence, drain only the event and statistics rings,
which carry completion and recovery notifications, then check for a
pending recovery. A recovery or a receipt fault still runs the full pass
at once. The skipped housekeeping is owed: run_poll() queues the backup
poll for the end of the cadence, and the owed state clears when any full
or periodic housekeeping runs. The backup poll may replace a later idle
power poll; that pass calls service_power() and arms the power poll
again.

Signed-off-by: Diljit Singh <[email protected]>
hold[0] counts publication passes that stopped at a ready job behind
in-flight work, but it lumps together a job that must wait for an empty
engine and one that waits for headroom. The two are released by
different events, so the counter cannot say which one a stalled
multi-pass render is waiting for.

Count each such hold once more by its cause, and print the split as a
hold_causes line of aurora-g16/stats:

- drain_failed: the VM failed, or a flight is doomed or recovery-suspect;
- drain_initbm: a cold InitBM render is in flight;
- drain_cross: render and compute of different VMs;
- drain_pb: no warm PB/UMA allocator slot of the VM can take the render;
- ta_wave: the TA wave window is full;
- slot: flight, render pass or compute unit headroom;
- dependency: the job's dependency check failed;
- other: any other refusal behind in-flight work.

The cause is evaluated only when a pass holds. The PB pipelining test
that needs_engine_drain() and can_queue_behind_with_ta() each spelled
out moves to render_can_pipeline(), which the classification uses too.
hold[0] keeps its meaning.

Signed-off-by: Diljit Singh <[email protected]>
When publish_checked() stops at a ready job, the poll repolls after
repoll_us only if it set slot_wait or ta_wave_wait. A job held for any
other reason waits for the next retirement poll. That is an EP 0x20
event, or the poll timer: rearm_us(false) is half the flight-duration
EWMA clamped to resnap_us, so 100 us for renders longer than 200 us. An
event for a stage that is not terminal is also not allowed to spin the
receipt tail. A multi-pass render held this way behind its own earlier
passes can therefore be published up to resnap_us after the retirement
that frees it, with the GPU idle in between.

Mark such holds held_wait when every flight belongs to the held job's
VM and the cause is not a failure, a cross-VM overlap or a failed
dependency. The job's own VM's retirements are then what releases it.
held_wait is treated like the two existing flags: poll_step() repolls at
repoll_us and keeps stage events eligible for the receipt tail,
submit_locked() rearms soon, and busy coalescing does not hold behind
it. publish_checked() clears it with them.

A hold behind another VM's work keeps the existing cadence, so a long
cross-VM drain does not repoll every few microseconds.

Signed-off-by: Diljit Singh <[email protected]>
Compute commands queued behind compute flights of any VM, so the CDM
pipes ran dispatches of different VMs at once, without a barrier
between them. With six dEQP-VK processes, about one draw in 285 of
dEQP-VK.glsl.texture_functions.* then read back zero or a partial
image, with no fault and no recovery: the readback copy, running beside
another VM's compute, lost its results. One process never fails, every
failed case passes alone, and the failures stop entirely once compute
waits for other VMs' flights, over three full runs. gpubench
compute.long showed the same loss: a ray-query dispatch that another
VM's compute overlapped was reported complete with its results
unwritten.

Let compute publish behind its own VM's flights only, on either pipe,
as it already did behind another VM's render, and as G15 runs one VM at
a time. Compute of one VM still pipelines on both pipes, and renders
still pipeline across VMs.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/g16-no-cross-vm-compute branch from 04671de to d77b0f0 Compare November 24, 2026 20:25
@DjDeveloperr
DjDeveloperr force-pushed the djdev/g16-poll-cadence-hold-causes branch from 9f1dc2f to 6c6dac6 Compare November 24, 2026 20:25
@DjDeveloperr
DjDeveloperr changed the base branch from djdev/g16-poll-cadence-hold-causes to main November 25, 2026 01:38
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 01:38
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 01:38
@DjDeveloperr
DjDeveloperr merged commit e542a50 into main Nov 25, 2026
3 checks passed
@RyanTheTide
RyanTheTide deleted the djdev/g16-no-cross-vm-compute 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