Skip to content

drm/asahi: g16: poll cadence fixes and publication hold causes - #3074

Merged
DjDeveloperr merged 7 commits into
mainfrom
djdev/g16-poll-cadence-hold-causes
Nov 25, 2026
Merged

DjDeveloperr merged 7 commits into
mainfrom
djdev/g16-poll-cadence-hold-causes

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: Poll and publication cadence for the g16 (M4) backend.

  • A SUBMIT that leaves a TA-wave- or slot-paced job waiting repolls at repoll_us, not up to resnap_us.
  • Idle poll passes run the full session/object/power/ring housekeeping only on its 1 ms cadence.
  • aurora-g16/stats splits hold[0] by cause.
  • A ready job held only behind its own VM's flights repolls at repoll_us.

Stacked on #3047 (djdev/g16-perf-wave16).

Tested:

  • Host only, at 9f1dc2f:
    • asahi-m4 host tests 25/25 (this base has no ray-tracing test yet).
    • asahi-g15 81 passed, 0 failed, 2 ignored.
    • checkpatch.pl --strict 0/0/0 on each commit; git diff --check clean.
  • M4 Mac mini (J773g, G16G B0), with the same four changes on the M4 integration branch, a same-machine A/B with the same Mesa:
    • vk-full, 202 rows: +2.23 % per-row geomean (13 rows faster, 178 within noise, 9 slower; worst compute.light procs d=16, −3.3 %).
    • 0 GPU faults, 0 recoveries, 0 new kernel errors.
    • A second boot ran 440/440 gpubench rows plus targeted Vulkan/GLES CTS with 0 failures.
  • g16 is the M4-only backend; no other Mac runs this code.

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

Not yet:

  • An M4 hardware run of this exact branch. On this base, 0003 and 0004 needed two context fixes (below).
  • CI: the base is a feature branch, so host-tests do not run here.
Details

Commits

  1. drm/asahi: g16: repoll soon when SUBMIT leaves a paced job waiting
    • submit_locked() now treats slot_wait/ta_wave_wait, with a job pending and the engine
      not frozen, as a reason to rearm soon. This is what poll_step() already does for the same
      state.
    • Before, an inline SUBMIT that hit TA-wave or slot headroom armed rearm_us(false), which is
      100 µs for flights longer than 200 µs.
  2. drm/asahi: g16: keep idle poll passes on the housekeeping cadence
    • A pass that starts with nothing in flight now, inside the 1 ms cadence, drains only the
      event and statistics rings and checks for a pending recovery.
    • Session::check(), Objects::health(), service_power() and the log/ktrace ring drains
      wait for the cadence.
    • A recovery or a receipt fault still runs the full pass at once.
    • Skipped housekeeping is owed: run_poll() queues the backup poll for the end of the
      cadence, and any full or periodic housekeeping clears it.
  3. drm/asahi: g16: count publication holds by cause
    • Both hold[0] sites go through note_hold(), which also counts one of drain_failed,
      drain_initbm, drain_cross, drain_pb, ta_wave, slot, dependency and other. They
      are printed as hold_causes:.
    • The PB-pipelining test that needs_engine_drain() and can_queue_behind_with_ta() each
      spelled out moves to render_can_pipeline().
    • hold[0] keeps its meaning.
  4. drm/asahi: g16: repoll soon while a job waits behind its own flights
    • A hold of a ready job behind flights that all belong to its VM sets held_wait. The cause
      must not be a failure, a cross-VM overlap or a failed dependency.
    • held_wait gets the short repoll, keeps stage events eligible for the receipt tail, makes
      SUBMIT rearm soon, and blocks busy coalescing.
    • Holds behind another VM's work keep the existing cadence.

Context fixes on this base

  • render_can_pipeline() calls can_pipeline_in_mask_blocks(), because the SCS-mode variant
    comes later in the stack.
  • drain_cross therefore covers cross-VM render/compute overlap only.
  • The test harness's mock Flight has no rt_compute field.

What the counters showed on M4. In multi-pass render rows (compress.bw array, render.postfx),
99.8–99.98 % of hold[0] is ta_wave, so those rows' remaining idle time is TA-wave pacing. The
release follows the TA stage's finalize stamp, not the end of the TA work.

Evidence
  • Base: djdev/g16-perf-wave16 at b84cfd5fd9e8.
  • Commits:
    • 9769d65c3f24 repoll soon when SUBMIT leaves a paced job waiting
    • fdf4b2e4da0d keep idle poll passes on the housekeeping cadence
    • 024e16604dbe count publication holds by cause
    • 9f1dc2f59d46 repoll soon while a job waits behind its own flights
  • Host tests on the head:
    • tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py: 25 ok, 0 not ok.
      • test-poll-retire.py 43/43 (new: submit_locked_repolls_soon_when_its_publication_leaves_a_paced_job, idle_poll_step_runs_full_housekeeping_only_on_its_cadence, held_wait_spins_stage_events_and_repolls_soon_until_a_retirement).
      • test-publication.py 83/83 (new: hold_causes_split_hold0_by_the_gate_that_stopped_publication, plus held_wait checks in the busy-coalescing test).
    • tools/testing/selftests/drivers/gpu/asahi-g15/run.py: 81 passed, 0 failed, 2 ignored.
  • Mutations (on the integration branch): reverting each functional change fails its new test. That covers the paced repoll, the idle cadence gate and the owed clear, each cause path of hold_cause(), and the held_wait repoll, tail, own-VM condition, coalescing exclusion and SUBMIT term.
  • M4 A/B (J773g, G16G B0; integration branch with and without these commits; same Mesa):
    • vk-full 202 rows: +2.23 % per-row geomean, W/T/L 13/178/9.
    • vk-w2 34 rows: +1.56 %.
    • compute.long 5/5, three multi-process runs 3/3.
    • 0 GPU faults, 0 recoveries, 0 dmesg errors.
    • Second boot: gpubench vk-rt/vk-full/gl-native/gl-zink 440/440 rows.
    • Targeted CTS: 1,730 cases, 1,422 pass, the rest not supported, 0 fail; 0 failed units.

@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 6c6dac64: 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 6c6dac64, a Mac and a result in the PR body or a comment
Conflicts ok none
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 9f1dc2f59d: FINISH, then merge. No code blockers; one row is missing.

Blockers:

  1. No hardware row at this head, as the PR says: the M4 A/B ran the same four changes on the integration branch, and two of them needed context fixes on this base. Fix: one J773g run at this head, or on a candidate that contains this head unchanged (see below).

Checked: the 4 commits against the base; skipped idle housekeeping is owed and runs at the end of the 1 ms cadence, and a recovery or receipt fault still runs the full pass at once; the hold-cause counters only add accounting; 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. 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.

…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]>
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]>
@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-perf-wave16 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 b68fab0 into main Nov 25, 2026
3 checks passed
@RyanTheTide
RyanTheTide deleted the djdev/g16-poll-cadence-hold-causes 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