Repository navigation
borealis: allow M5 single-queue global-atomic CDM packing while compute kicker is dormant - #1184
Conversation
…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>
|
This branch no longer merges into current |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 451a7fddbe177
Blockers:
src/asahi/vulkan/hk_compute_kick.c:340-341(if (packed_atomics_active) due = 0;), together withhk_compute_kick_pack_atomics_begin()(:405-420) andqueue_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 whenevercompute_kick_queues == 0, and that counter is published only when a kick is due and no packed atomics are in flight. Each such submission raisespacked_atomics_pointto 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-CBatomicAddbenchmark 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_MSthe kicker sends kicks so the other client's work starts. - With this PR, every submission packs,
packed_atomics_pointis always ahead of the completed value,packed_atomics_activestays true, anddueis zeroed on every pass. No kick is ever sent andcompute_kick_queuesnever 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
dueis non-zero and packed atomics are in flight, setcountedand incrementcompute_kick_queuesright away, underk->lock, sohk_compute_kick_pack_atomics_begin()refuses every new packed-atomic submission. Then wait only for thepacked_atomics_pointalready registered, which no longer advances, and send the kick when it retires. Add a host test: a kicker with a due class and apacked_atomics_pointthat keeps being re-armed must still activate the class within one more retire.
- Input: on the J716c (G17C, where the kicker is on by default with
Not blocking:
default_onwidens 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 unlesschip == AGX_CHIP_G17C;hk_drirc_gen.py:62defaultshk_compute_kick_msto 10. So the J716c runs the kicker by default. - Thread loop at the head (
hk_compute_kick.c:272-352):packed_atomics_activeis set fromkick.packed_atomics_inflightorvalue < kick.packed_atomics_point; when set,due = 0and no class is counted, sodev->compute_kick_queuesstays 0 andhk_compute_kick_pack_atomics_begin()keeps admitting new packed-atomic submissions, each raisingpacked_atomics_pointinhk_compute_kick_pack_atomics_end(). git merge-treeagainst aurora-wipfa8970cda14f: 3 conflict hunks inhk_queue.c(queue_submit_segment()). Not gated, because the blocker needs a code change first.
|
@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 |
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
left a comment
There was a problem hiding this comment.
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
countedand incrementscompute_kick_queuesunderk->lockas 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 extendpacked_atomics_point. hk_compute_kick_take_due()keeps the due classes inpending_kickswhile already-accepted packed work is in flight. Work begun before admission closed can raise the point once (inpack_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).
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Merged aurora-wip and fixed kick priority at |
|
Merging at |
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 indev->compute_kick_queues(0 until a kick actually fires), guard packed global-atomic submissions withhk_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 publishcompute_kick_queuesunder the mutex before firing a kick.Tested: J716c Apple M5 Max at 451a7fd: Clang 22.1.8 debugoptimized
meson test --suite asahi --suite poly334/334 pass (0 fail, including expandedhk_pack_atomicstests for M5 and dormant vs active kick queues); live 3-round ABBA 64-CB contested global-atomicatomicAddbenchmark (default env, noHK_PACK_ATOMICSoverride) vs41fe336dffashowsruns=0 (64 cmds) -> runs=1 (1 cmd), wall-clock1.228 -> 0.196 ms(-84.0%, 6.26x), exact13,107,200total across 50 bursts and 10 stress iterations with zero lost increments; Vulkan CTSglsl.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=0restores 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: adddev->compute_kick_queuesand per-queuepacked_atomics_inflight/packed_atomics_pointstate underk->lock.src/asahi/vulkan/hk_compute_kick.{h,c}: addhk_compute_kick_pack_atomics_{begin,end}(), defer kick activation inhk_compute_kick_thread()while any bounded packed atomic packet is being built or executing, and incrementcompute_kick_queuesunderk->lockbefore activating a kick queue.src/asahi/vulkan/hk_queue.c: extenddefault_oninhk_pack_atomics_allowed()toagx_chip_native_or_m5(), allow dormant watched kickers (compute_kick != NULL && compute_kick_queues == 0), propagateruns.has_atomics, and bracket packed submits inqueue_submit_segment()withhk_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, base41fe336dffaSHA-2560ea0ee4efd3bvs head SHA-2566a3d6a6c6833)atomicAdd(50-submit burst avg)runs=0 -> runs=1 (64->1 cmds), exact13,107,200incrementsVulkan CTS (
dEQP-VK.glsl.atomic_operations.*+dEQP-VK.compute.pipeline.basic.*,MESA_SHADER_CACHE_DISABLE=1)41fe336dffa: 118/200 Pass, 0 Fail, 82 NotSupported451a7fddbe1: 118/200 Pass, 0 Fail, 82 NotSupported, 0 status diffs