Skip to content

borealis: fast-reap retired submits via vm_status_mirror and deduplicate drmSyncobjQuery - #1162

Merged
RyanTheTide merged 2 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-vm-status-mirror-fast-reap
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-vm-status-mirror-fast-reap

Conversation

@oreater

@oreater oreater commented Nov 26, 2026 •

Copy link
Copy Markdown

What: Fast-reap retired single-chunk Borealis submissions via vm_status_mirror (eliminating per-submit sync_file syscalls) and deduplicate drmSyncobjQuery ioctls within a submission.

Tested: J716c Apple M5 Max at 4348bcc5321: 212/212 asahi unit tests PASS, ExportSyncFile/SYNC_IOC_FILE_INFO -100% (2,097 -> 0), drmSyncobjQuery -42.3%, pipelined depth-4 compute submit -8.99% (1.10x), 167/167 Vulkan CTS PASS (0 fail, 0 diffs), 0 kernel errors.

Risk: two-way door · all Macs — A plain revert restores hk_cmd_pending_poll(). Relies on the existing kernel vm_status_mirror ordering contract documented in hk_init_vm_status_mirror(); multi-chunk submissions, lost devices, missing mirrors, and non-zero mirror words fall back to hk_cmd_pending_poll().

Not yet: Multi-chunk packed submissions (chunks > 1) when chunk_timelines is active still use per-syncobj polling and can be extended later if needed.

Details and verification evidence

Summary

Eliminates per-retired-submission sync_file syscalls and redundant drmSyncobjQuery ioctls on packed compute submissions with zero chip-specific gating:

  1. Fast-reap retired single-chunk submissions via vm_status_mirror (src/asahi/vulkan/hk_cmd_pool.c):

    • Seeds reached from queue->drm.signalled_value and skips drmSyncobjQuery whenever it already covers the newest pending submission on the queue; otherwise publishes any freshly queried point via hk_queue_note_signalled().
    • When dev->vm_status_mirror.word != NULL, the device is not lost (!vk_device_is_lost_no_report(&dev->vk)), and an __ATOMIC_ACQUIRE load after observing p->point <= reached reads 0, single-chunk submissions (p->chunks == 1 && p->attempted == 1) retire directly without drmSyncobjExportSyncFile + SYNC_IOC_FILE_INFO + close.
    • Any non-zero error word, lost device, missing mirror, or multi-chunk submission falls back to hk_cmd_pending_poll().
  2. Deduplicate drmSyncobjQuery within a single submission (src/asahi/vulkan/hk_queue.c, hk_cmd_pool.h):

    • Threads a per-submission struct hk_queue_done_cache through hk_pack_runs() and queue_submit_recordings() so hk_cmd_pending_reap_cached(), hk_pack_atomics_allowed_cached(), hk_queue_query_progress(), hk_sync_submit_needs_completed(), and hk_sibling_deep() issue at most one drmSyncobjQuery for the queue per submission and avoid re-reaping when hk_pack_runs() already reaped.
  3. Unit tests (src/asahi/vulkan/tests/test-hk-cmd-pending.c):

    • Adds test_vm_status_mirror_fast_reap() exercising zero-ioctl retirement via signalled_value and cached points (dev.dev.fd == -1), plus fallback verification for non-zero vm_status_mirror (-EIO), lost device, and multi-chunk submissions.

Build & Artifacts

  • Host: J716c Apple M5 Max (G17C B1), Fedora Remix 44, kernel 7.3.0-40.j716c19.fc44.aurora.aarch64, GCC 16.2.1
  • Meson: --buildtype=release -Db_ndebug=true -Dbuild-tests=true -Dvulkan-drivers=asahi -Dgallium-drivers=
  • Base (origin/aurora-wip 822cf58723a): libvulkan_asahi.so SHA-256 d5b7e4582e1b034642e804f6477b070504ad077c2f0a3212989f6ad785228d68
  • Head (4348bcc5321): libvulkan_asahi.so SHA-256 82174c33ad76962bbbd3d03748c975773198134b13e8ce6044aa654dbbd15ab5

Verification

  • Unit tests (meson test --suite asahi): 212/212 PASS, 0 FAIL (including hk_cmd_pending_test with new test_vm_status_mirror_fast_reap()).
  • Measured DRM / sync_file ioctl counts (2,000 pipelined depth-4 packed 2-CB compute submits + 100 warmup):
Syscall / ioctl Base Head Delta
DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD (ExportSyncFile) 2,097 0 -100%
SYNC_IOC_FILE_INFO 2,097 0 -100%
DRM_IOCTL_SYNCOBJ_QUERY (process total incl. common vk_sync) 5,510 3,182 -42.3% (-2,328)
  • Live M5 Max A/B (strict 3-round ABBA, MESA_SHADER_CACHE_DISABLE=1, bit-exact GPU counters):
Workload Base median Head median Delta
Pipelined depth-4 packed 2-CB compute (4,000 submits) 22.70 us/sub 20.66 us/sub -8.99% (1.10x)
Synchronous submit+wait packed 2-CB (1,000 submits, IRQ-bound) 128.80 us/sub 128.61 us/sub -0.15% (flat)
  • Vulkan CTS (deqp-vk, base vs head):
    • 167-case dEQP-VK.api.smoke.*, dEQP-VK.api.command_buffers.*, dEQP-VK.synchronization.smoke.*, dEQP-VK.synchronization2.smoke.*, dEQP-VK.synchronization.basic.fence.*, dEQP-VK.synchronization.basic.binary_semaphore.*: 167/167 PASS, 0 FAIL, 0 status diffs vs base.
  • Host health: SELinux=Enforcing, 0 DRM/asahi/GPU kernel errors.

…ate drmSyncobjQuery

Retiring driver-owned packed-submission BOs in hk_cmd_pending_reap_queue()
currently performs a drmSyncobjQuery plus three syscalls per retired chunk
(drmSyncobjExportSyncFile, SYNC_IOC_FILE_INFO, and close), even when the
device already has a kernel-maintained vm_status_mirror mapping and the
queue timeline point was already observed during the same submission or an
earlier host wait.

1. Fast-reap single-chunk retired submits via vm_status_mirror:
   - Seed `reached` from `queue->drm.signalled_value` and skip
     `drmSyncobjQuery` when it already covers the newest pending entry;
     otherwise publish the queried point via `hk_queue_note_signalled()`.
   - When `dev->vm_status_mirror.word` is mapped, the device is not lost,
     and an acquire load after observing `p->point <= reached` reads 0,
     retire single-chunk submissions (`p->chunks == 1 && p->attempted == 1`)
     directly without per-syncobj sync_file export/ioctl/close.
   - Any non-zero error word, lost device, missing mirror, or multi-chunk
     submission falls back to `hk_cmd_pending_poll()`.

2. Deduplicate per-submission `drmSyncobjQuery` calls across packing and
   submission:
   - Thread a per-submission `hk_queue_done_cache` through `hk_pack_runs()`
     and `queue_submit_recordings()` so `hk_cmd_pending_reap_cached()`,
     `hk_pack_atomics_allowed_cached()`, `hk_queue_query_progress()`,
     `hk_sync_submit_needs_completed()`, and `hk_sibling_deep()` issue at
     most one `drmSyncobjQuery` for the queue per submission and avoid
     re-reaping when `hk_pack_runs()` already reaped.

3. Add unit tests in `test-hk-cmd-pending.c` covering zero-ioctl fast-reap
   via `signalled_value` and cached points, as well as fallback on non-zero
   `vm_status_mirror`, lost device, and multi-chunk submissions.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 26, 2026 22:33
@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: FINISH, then merge at 4348bcc5321a2

Blockers: none

Checked: Read the whole diff (hk_cmd_pool.c/.h, hk_queue.c, the new test). The fast reap only skips the sync_file status read when the queue timeline has reached the submission's point, the submission has one chunk and one attempted ioctl, the device is not lost, and the VM status mirror reads 0 with an acquire load after the point was observed. I checked the kernel side on aurora/main (g15/job.rs and g16/job.rs finish(), g17/completion.rs publish()): every error that can leave firmware referencing a job's memory (EIO, ENODEV, ETIMEDOUT, or a failure while the engine still had it) is recorded in the sticky VM status before the fence signals. The only errors that are not sticky are ECANCELED and errors after the job left the engine, and in those cases the GPU no longer touches the memory, so returning it to the BO cache is safe. Every use of the per-submission hk_queue_done_cache treats the cached point as a lower bound. The decisions that read it (packed atomics, sibling depth, the prior-busy check, the empty-wait own-timeline wait, the needs_completed point) only become more conservative when the value is stale, so none of them can drop a wait. There is no chip gate: the path depends on DRM_ASAHI_FEATURE_VM_STATUS_MIRROR through hk_init_vm_status_mirror(). The new test calls the new reap entry points and checks the fallback cases (non-zero mirror, lost device, multi-chunk).

To finish:

  1. Merge aurora-wip into the branch (a normal merge, no rebase). The hk_queue.c conflict is mechanical: wip added submit_is_original to hk_pack_runs() and the hk_pack_obs_arm() blocks around both queue_submit_recordings() calls in queue_submit_segment(). Keep wip's code and add &done_cache. A scratch merge resolved that way builds and passes the local gate (see Evidence).
  2. Rows owed at the merged head: this is shared code for every Mac whose kernel offers the mirror, but the only row is on the J716c. Needed: the same CTS subset (api.command_buffers, synchronization basic fence and binary semaphore) on one G17P Mac (Neo) and one G14 or G16 Mac, plus the usual regression Mac.

Non-blocking: reached can come from queue->drm.signalled_value, which another thread may have stored. p_atomic_read is a relaxed load, so on arm64 the later acquire load of the mirror word is not ordered after it. Reading signalled_value with __ATOMIC_ACQUIRE, and storing it with release in hk_queue_note_signalled(), would make the "observed the point, then read the mirror" ordering hold across threads as well as within one.

Landing order with the other open submit-path PRs: #1162, #1176 and #1184 each add a parameter to queue_submit_recordings(), and #1173 and #1184 also rework queue_submit_segment(). I suggest landing #1162 first, then #1176 after merging aurora-wip in again; the others follow after their fixes.

Evidence
  • Local x86 drm-shim gate (stands in for CI; docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):
    • base aurora-wip fa8970cda14f: 336 OK / 0 FAIL
    • scratch merge of 4348bcc5321a2 into fa8970cda14f, with the conflict resolved as described above: 336 OK / 0 FAIL (hk_cmd_pending: ok)
  • Kernel contract read at aurora/main: g16/job.rs finish() records the error in the VM status (vm.status.record) before fence.signal(result), and report_failure (not sticky) covers only ECANCELED and errors after the job left the engine, outside EIO/ENODEV/ETIMEDOUT. g15/job.rs does the same with only ECANCELED left out. In g17/completion.rs, publish() signals an error fence from inside status.signal_failure().

@RyanTheTide

Copy link
Copy Markdown

The 24 h window on the merge request from 11-27 04:20Z has passed, so per our PR fast-track policy I forward-merged aurora-wip (18d3cdc3692d) into this branch as 0ff1703503ef. It's a normal merge commit, with no rebase or force push.

Conflicts, all in src/asahi/vulkan/hk_queue.c, kept both sides:

  • queue_submit_recordings() completed point: starts from aurora-wip's cached signalled_value lower bound, and your hk_queue_query_done(dev, queue, done_cache, &point) result is folded in with MAX2. Your helper already calls hk_queue_note_signalled().
  • hk_pack_runs() now takes aurora-wip's submit_is_original and your done_cache.
  • The two queue_submit_recordings() calls in queue_submit_segment() pass &done_cache and keep aurora-wip's hk_pack_obs_arm() bookkeeping.

Host check at 0ff1703503ef (x86 clang, release + asserts, drm-shim): every Vulkan test passes, including hk_cmd_pending. The suite shows 313/339 overall. The 26 failures are all Gallium run-shim.py tests that this harness fails without your change too.

Before merge it goes into the next combined lab regression row (M1 Pro G13S + M4 G16G). If you'd rather resolve it differently, push on top and I'll re-run.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at 0ff1703503ef from a different lane plus the author's exact-head hardware row. I plan to land it no earlier than 06:29Z, after a combined A/B regression row on two lab GPU families (M1 Pro G13S + M4 G16G). The App approval doesn't count toward the ruleset, so that merge uses --admin under the 6-point rule. Please post a review here if you want it held.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 0ff1703503ef.

  • Review: RyanTheTide review-lane APPROVE (FINISH, then merge; no blockers) at the pre-forward-merge head; the only later commit is my aurora-wip forward merge (host suite green) (non-author).
  • Feature row: the author's exact-head hardware row on this PR.
  • Regression: combined A/B overlay of aurora-wip plus this PR and the other queued PRs, user space, default kernel command line. M1 Pro (G13S, fleet89): 0 status changes. M4 Pro (G16S, fleet89): 0 regressions. The only flips there are 5 synchronization multi_queue timeouts under 4-job load; all 5 pass 3/3 alone on both arms, and the base arm shows the same flake. Each Mac ran 26,595 dEQP-VK + 8,153 dEQP-GLES cases, with 0 GPU firmware crashes, Enforcing, 0 failed units. Evidence traces/gpu/20261128-mergetrain-mesa.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants