Skip to content

borealis: allow M5 single-queue global-atomic CDM packing while compute kicker is dormant - #1184

Merged
RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-dormant-kicker-atomic-pack
Dec 1, 2026
Merged

RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-dormant-kicker-atomic-pack

Conversation

@oreater

@oreater oreater commented Nov 27, 2026

Copy link
Copy Markdown

What: Enable single-queue global-atomic CDM submit packing on M5 (matching G17P's single-kernel-queue invariant via agx_chip_native_or_m5()) while the compute kicker is dormant: track activated kick classes in dev->compute_kick_queues (0 until a kick actually fires), guard packed global-atomic submissions with hk_compute_kick_pack_atomics_{begin,end}() under the kicker mutex so kick-queue activation waits for any bounded in-flight packed atomic packet to retire, and publish compute_kick_queues under the mutex before firing a kick.

Tested: J716c Apple M5 Max at 451a7fd: Clang 22.1.8 debugoptimized meson test --suite asahi --suite poly 334/334 pass (0 fail, including expanded hk_pack_atomics tests for M5 and dormant vs active kick queues); live 3-round ABBA 64-CB contested global-atomic atomicAdd benchmark (default env, no HK_PACK_ATOMICS override) vs 41fe336dffa shows runs=0 (64 cmds) -> runs=1 (1 cmd), wall-clock 1.228 -> 0.196 ms (-84.0%, 6.26x), exact 13,107,200 total across 50 bursts and 10 stress iterations with zero lost increments; Vulkan CTS glsl.atomic_operations.* + compute.pipeline.basic.* 118/200 pass (0 fail, 82 NotSupported, 0 status diffs).

Risk: two-way door · M5 (G17G / G17S / G17C; G17P unchanged) — packed atomics remain disabled whenever any second non-emulated Vulkan queue, non-emulated host-AS queue, in-flight sibling queue, or activated compute-kick queue exists; HK_PACK_ATOMICS=0 restores separate submissions immediately.

Not yet: Not yet hardware-tested on M4 / G17G / G17S (G17P has no compute kicker and keeps its existing behavior; M1/M2/M3 are untouched).

Details & benchmark data

Scope

  • src/asahi/vulkan/hk_device.h, src/asahi/vulkan/hk_queue.h: add dev->compute_kick_queues and per-queue packed_atomics_inflight / packed_atomics_point state under k->lock.
  • src/asahi/vulkan/hk_compute_kick.{h,c}: add hk_compute_kick_pack_atomics_{begin,end}(), defer kick activation in hk_compute_kick_thread() while any bounded packed atomic packet is being built or executing, and increment compute_kick_queues under k->lock before activating a kick queue.
  • src/asahi/vulkan/hk_queue.c: extend default_on in hk_pack_atomics_allowed() to agx_chip_native_or_m5(), allow dormant watched kickers (compute_kick != NULL && compute_kick_queues == 0), propagate runs.has_atomics, and bracket packed submits in queue_submit_segment() with hk_compute_kick_pack_atomics_{begin,end}().
  • src/asahi/vulkan/tests/test-hk-pack-atomics.c: add host unit checks for dormant vs active kick queues and M5 single- vs multi-queue gating.

Live M5 Max 3-round ABBA (MESA_SHADER_CACHE_DISABLE=1, default env, base 41fe336dffa SHA-256 0ea0ee4efd3b vs head SHA-256 6a3d6a6c6833)

Workload Base median (6 runs) Head median (6 runs) Delta Trace / Verification
64 CBs x 4096 threads contested atomicAdd (50-submit burst avg) 1.228 ms 0.196 ms -84.0% (6.26x) runs=0 -> runs=1 (64->1 cmds), exact 13,107,200 increments

Vulkan CTS (dEQP-VK.glsl.atomic_operations.* + dEQP-VK.compute.pipeline.basic.*, MESA_SHADER_CACHE_DISABLE=1)

  • Base 41fe336dffa: 118/200 Pass, 0 Fail, 82 NotSupported
  • Head 451a7fddbe1: 118/200 Pass, 0 Fail, 82 NotSupported, 0 status diffs

…te kicker is dormant

On M5 (G17G/G17S/G17C), single-queue global-atomic CDM submit packing
was still off by default, and on G17C hk_compute_kick_init() marks
watched queues at device creation even though kick DRM queues are only
created lazily if a compute submission stalls >HK_KICK_AFTER_MS (50 ms).
Checking queue->kick.watched unconditionally permanently disabled
single-queue global-atomic packing on G17C even while the kicker is
dormant.

Track activated kick classes in dev->compute_kick_queues (0 while
dormant), extend the G17P single-kernel-queue default to M5 via
agx_chip_native_or_m5(), and guard single-queue packed global-atomic
submissions with hk_compute_kick_pack_atomics_{begin,end}() under the
kicker mutex so kick activation is deferred until any bounded in-flight
packed atomic packet retires. Because no application Vulkan submission
waits on a compute-kick semaphore, deferring kick activation cannot
deadlock while preserving zero concurrent-queue global-atomic overlap.

Extend hk_pack_atomics unit tests to cover M5, dormant vs activated
compute-kick queues, and multi-queue exclusion.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 27, 2026 00:50
@RyanTheTide

Copy link
Copy Markdown

This branch no longer merges into current aurora-wip (d2e883ab2e3): git merge-tree reports a conflict in src/asahi/vulkan/hk_queue.c. Could you merge aurora-wip into the branch (a normal merge, no rebase or force push) and re-run the asahi + poly suites at the new head? I will review the content once it merges cleanly. Several open queue/pack PRs touch the same file, so resolving against the tip as it is now will save a second round.

@RyanTheTide RyanTheTide 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.

Verdict: HOLD at 451a7fddbe177

Blockers:

  1. src/asahi/vulkan/hk_compute_kick.c:340-341 (if (packed_atomics_active) due = 0;), together with hk_compute_kick_pack_atomics_begin() (:405-420) and queue_submit_segment() (hk_queue.c:7015, :7046-7050). With this change, the kicker sends no kick at all while any packed global-atomic submission is in flight. A new submission may pack atomics whenever compute_kick_queues == 0, and that counter is published only when a kick is due and no packed atomics are in flight. Each such submission raises packed_atomics_point to its own timeline value. So:
    • Input: on the J716c (G17C, where the kicker is on by default with hk_compute_kick_ms = 10), one client keeps GPU-filling compute in flight on one queue, as a pipelined stream of multi-CB submissions using global atomics (an atomics-heavy simulation, a reduction-heavy inference loop, or the 64-CB atomicAdd benchmark from the body run back to back). A second client, for example the compositor, submits small compute jobs.
    • Before this PR, those submissions are never packed on a watched queue, and after HK_KICK_AFTER_MS the kicker sends kicks so the other client's work starts.
    • With this PR, every submission packs, packed_atomics_point is always ahead of the completed value, packed_atomics_active stays true, and due is zeroed on every pass. No kick is ever sent and compute_kick_queues never leaves 0, so the stall comes back that the kicker exists to fix (hk_compute_kick.c:7-15: seconds-long stalls, "long enough makes them lose their device"). It stays that way for as long as the stream runs. A single long packed submission also suppresses kicks for its whole length, while the pre-PR path would have kicked after 50 ms.
    • Fix: let a due kick win. When due is non-zero and packed atomics are in flight, set counted and increment compute_kick_queues right away, under k->lock, so hk_compute_kick_pack_atomics_begin() refuses every new packed-atomic submission. Then wait only for the packed_atomics_point already registered, which no longer advances, and send the kick when it retires. Add a host test: a kicker with a due class and a packed_atomics_point that keeps being re-armed must still activate the class within one more retire.

Not blocking:

  • default_on widens a chip gate (agx_chip_native_or_m5(), hk_queue.c:3053). The comment explains the single-kernel-queue property as a kernel/firmware property that no uAPI feature reports yet. That reasoning was there before this PR, but please note in the commit message that it should become a kernel capability bit, per the no-gates rule. The old comment also said M5 lost updates with two kernel queues "root cause unknown". The new text drops that caveat, so please keep it unless the cause has since been found.
  • Rows: the only row is the J716c 64-CB benchmark. Once fixed, the row needs the cross-client case as well: a second client's small compute latency beside a long packed-atomics stream, with the kicker on, compared against base. M5 base/Pro (G17G/S, no kicker) are also enabled by this PR and untested.
  • Landing order: this conflicts with #1162 and #1176 in queue_submit_segment()/queue_submit_recordings(). Land it after those, merging aurora-wip in again.

Checked: Read the whole diff (hk_compute_kick.c/.h, hk_device.h, hk_queue.c/.h, test-hk-pack-atomics.c). The begin/end pairing is balanced on every return path of queue_submit_segment() after begin. Begin, end and the kicker's activation all run under k->lock, so a kick queue cannot become active while a submission is between begin and end. That ordering is correct; the problem is only the starvation above. Queues that are not watched (no kicker: G17P, G17G/S) skip the guard, and hk_pack_atomics_allowed() still requires a single non-emulated queue. The new tests check hk_pack_atomics_allowed() for dormant and active kick queues. They do not run the kicker thread, so they cannot catch blocker 1.

Evidence
  • Kicker enablement at the head: hk_compute_kick_init() returns unless chip == AGX_CHIP_G17C; hk_drirc_gen.py:62 defaults hk_compute_kick_ms to 10. So the J716c runs the kicker by default.
  • Thread loop at the head (hk_compute_kick.c:272-352): packed_atomics_active is set from kick.packed_atomics_inflight or value < kick.packed_atomics_point; when set, due = 0 and no class is counted, so dev->compute_kick_queues stays 0 and hk_compute_kick_pack_atomics_begin() keeps admitting new packed-atomic submissions, each raising packed_atomics_point in hk_compute_kick_pack_atomics_end().
  • git merge-tree against aurora-wip fa8970cda14f: 3 conflict hunks in hk_queue.c (queue_submit_segment()). Not gated, because the blocker needs a code change first.

@RyanTheTide

Copy link
Copy Markdown

@oreater, merge-train check-in. Four of your PRs landed today (#1162, #1176, #1179, #1187; we forward-merged aurora-wip into them). This one still has the blocking review from 11-27 07:3xZ and conflicts with aurora-wip. Could you address the listed items and merge aurora-wip in (normal merge, no force push)? If you'd rather a maintainer carry it, say so and we'll do the follow-up commits on your branch.

Track the atomic status of cached and newly built packets and balance the packing guard on every submission path.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Close admission while holding the kicker lock, then retain each due class until accepted atomic work has retired. Multiple submissions can no longer keep advancing the point ahead of a waiting kick. Cover the deferred mask in the host gating test.

Signed-off-by: DjDeveloperr <hey@djdev.me>

@RyanTheTide RyanTheTide 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.

Re-review at 954ec75 (fix commit 954ec75 on top of aurora-wip merges). The blocker from my 451a7fd review is fixed: a due kick now wins.

  • The kicker sets counted and increments compute_kick_queues under k->lock as soon as a class is due. hk_compute_kick_pack_atomics_begin() checks that counter under the same lock, so no later submission can pack atomics or extend packed_atomics_point.
  • hk_compute_kick_take_due() keeps the due classes in pending_kicks while already-accepted packed work is in flight. Work begun before admission closed can raise the point once (in pack_atomics_end), then it retires and the deferred kick is sent. The endless re-arm from my repro can't happen any more.
  • The take_due cases in test-hk-pack-atomics.c cover deferral and release.
    Not blocking:
  • Admission closes even when the due class's work retires during the deferral. The kick then turns out to be unneeded, but packing stays off, as it already did after any first kick. This is a perf-only, fail-safe cost.
  • The host test covers the helper, not the admission-close interaction (begin refused after a due class is counted). A one-line case calling begin after the kicker counts a class would pin it down.
    Still needed before merge: an exact-head hardware row (the PR's J716c rows predate this commit).

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 954ec75e4987 from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip 84ba0bee + #570 #1128 #1180 #1184 #1260 #1266 #1424 #1428 #1430 #1435) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 954ec75e: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 954ec75e
Conflicts ok not computed yet
PR text ok Risk: two-way · M5 (G17G / G17S / G17C; G17P unchanged) — packed atomics remain disabled whenever any second non-emulated Vulkan queue, non-emulated host-AS queue, in-flight sibling queue, or activated compute-kick queue exists; HKPACKATOMICS=0 restores separate submissions immediately.

Areas: area:borealis

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

@DjDeveloperr

Copy link
Copy Markdown

Merged aurora-wip and fixed kick priority at 954ec75e4987. A due class now closes atomic admission under the kicker lock before waiting for already accepted work to retire. Cached and fresh packets track whether they actually contain atomics. Both driver objects compiled; the warm packed-atomics gating test passed including deferred and combined due classes. J716c still needs the cross-client latency comparison and an M5 no-kicker control before re-review.

@github-actions github-actions Bot removed the ready-to-merge Meets the merge policy: merge it (bot) label Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown

Merging at 954ec75e4987 (B2 merge train, 12-01 merge bar). Approval at this head: RyanTheTide. Row: j713 (M4 Air, G16G, fleet91) full VK+GL row of the M1 candidate vs tip: VK Pass 14679 vs 14659, GL Pass 7497 vs 7448, 0 firmware crashes/fail-stops; every Pass->non-Pass case re-ran clean (6 suspects passed 5/5 alone on both builds). Traces: traces/gpu/20261201-b2-mesa-M1. CI: mesa train M1 = aurora-wip 69a6b8d + #570 #1180 #1184 #1266 #1428 #1435 #1415 #1433 #1437 #631 #664 #673 (candidate e56f7487): host meson asahi+poly 351 OK / 26 fail vs tip 344 / 26 (same 26 pre-existing, 0 new; 7 new tests pass), agx_tests pass. Fork Actions don't run in this repo, so this local run is the CI. Revert: git revert -m 1 <merge commit>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:borealis Area from CODEOWNERS (bot) blast:m5 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.

3 participants