Repository navigation
borealis: order same-queue binary semaphore waits on the GPU - #1176
RyanTheTide merged 3 commits into
Conversation
When a binary semaphore was last signalled by a submission on the same queue and the kernel supports DRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERS, waiting on it means ordering after the signalling submission's VDM and CDM ordinals rather than stalling on a host scheduler fence round trip. - Wrap drm_syncobj payload-changing, init, import, and export operations (keeping finish intact so vk_sync_type_is_drm_syncobj() holds) and device copy_sync_payloads, plus hk_DestroySemaphore/hk_DestroyFence, so any external mutation, shared payload, move of a shared payload, empty submit, or destruction invalidates the cached tag. - Tag binary signals before kernel submission (forgetting on failure), and convert matching same-queue binary waits on non-split, primary exact-prior submissions into hk_sync_queue::wait_floor applied across resolve_one() and hk_sync_host_flush_prefix(). - Keep sibling kernel queue submissions safe via wait_floor guards and queue->gpu_wait_generation invalidation on queue restart or sibling use. - Extend hk_sync_prior unit tests for wait_floor ordering, deferred host flush floor propagation, and next-submission isolation. 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: FINISH, then merge at b98042329d1ba
Blockers: none
Checked: Read the whole diff (hk_gpu_waits.c/.h, hk_queue.c, hk_sync.c/.h, hk_device.c, hk_physical_device.c/.h, meson.build, the test).
- Payload changes: init, signal(_many), reset(_many), move, opaque-fd and sync_file import/export, and
copy_sync_payloadsare all wrapped. Finish is left alone, sovk_sync_type_is_drm_syncobj()still holds. hk's directdrmSyncobjTransferwrites are either the noted signal or the empty-submit path, which forgets the record. - Reused addresses: a vk_sync created at a freed address goes through init, which forgets the old record. Records are compared by pointer and never dereferenced, so a stale entry after destroy cannot be used.
- Temporary imports and threaded submit: shared syncs are refused. A temporary import is a different vk_sync, so its wait keeps the kernel input sync. The threaded-submit
vk_sync_moveinto the wait temporaries happens after the signal was noted, and the record moves with it. - Cross-queue and ordering: a record only counts on the same
hk_queueand the same generation. The generation is bumped onhk_queue_restart_sync, on sibling use, and whilesib.usedis set. Split submits, prepended CDM commands and replaced queues all keep the input sync, so a wait from another queue still waits in the kernel. The lock is a leaf, so it cannot deadlock against the queue locks. - The floor:
resolve_one()applieswait_floortoprior/prior_taon both subqueues. It is at or below the base, so it is always an absolute prior.hk_sync_host_flush_prefix()honours it. A non-zero floor keeps the waiting submit off sibling queues. - Gating: the path depends on
DRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERSplus the queue's ownexact_prior, and virtio is excluded. There is no chip gate. - Timeline semaphores are untouched.
To finish:
- Merge
aurora-wipinto the branch. Inqueue_submit_segment(), keep wip'sprev_pt/hk_pack_obs_arm()blocks and passallow_gpu_waitsin bothqueue_submit_recordings()calls. Thetest-hk-sync-prior.cconflict is two appended tests: keep both. A scratch merge done that way passes the local gate (see Evidence). - Rows owed at the merged head: the path is taken wherever the kernel reports exact prior barriers, which includes G17P and G16, not only M5. Run the binary_semaphore and sync_fd CTS groups from the body on a Neo (G17P) and a J713 (G16), plus a regression Mac. Please also correct the Risk line: it should name what enables the path (the kernel feature and exact_prior queues), not "M3, M4, M5".
Non-blocking:
- The new test only covers the resolver's
wait_floor. Nothing tests the bookkeeping inhk_gpu_waits.c: take across queues and generations, a wait on another queue consuming the record, carrying the record through the threaded-submit move, refusing shared or timeline syncs, and forgetting on a failed submit. A small host test there would protect the part most likely to drop a wait in a later change. - Fences also fill the 32-entry ring through
note_signals, but no queue ever consumes them. One device-wide mutex is also taken on every reset or signal, includingvkResetFences, and once per element in the_manyloops. - Landing order: this conflicts with #1162 and #1184 in
queue_submit_recordings()'s parameter list. #1162 first, then this one.
Evidence
- Local x86 drm-shim gate (stands in for CI; docker
aurora/hk6356-mesa-x86-tests:local, clang release with asserts,meson test --suite asahi --suite poly):- base aurora-wip
fa8970cda14f: 336 OK / 0 FAIL - scratch merge of
b98042329d1baintofa8970cda14f, resolved as above: 336 OK / 0 FAIL, including the 11 newfloor:cases in the sync-prior test.
- base aurora-wip
|
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 Conflicts, kept both sides:
Host check at 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. |
|
Second forward merge, |
|
Merge-train landing at
Revert: |
What: Order same-queue binary semaphore waits on the GPU via
hk_sync_queue::wait_floorinstead of kernel host-scheduler input syncs whenever the kernel advertisesDRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERSand the signalling submission ran on the same primary kernel queue, eliminating host-fence round trips in chained render/overlay and mixed render/compute submissions.Tested: J716c Apple M5 Max at
b98042329d1: 334/334 Clang debug CI tests (--suite asahi --suite poly) PASS, 16-link same-queue binary-semaphore render chain -75.2% (2.694 -> 0.668 ms,4.04x), 16-link alternating render/compute chain -67.5% (2.455 -> 0.799 ms,3.07x) with exact pixel/SSBO readback, 216/293 Vulkan CTS PASS acrosssynchronization{,2}.*binary_semaphore*+api.external.semaphore.{opaque_fd,sync_fd}(0 fail, 0 diffs), 0 kernel errors.Risk: two-way door · M3, M4, M5 (non-serialized queues with
DRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERS) — A plain revert restores kernel input syncs for all binary semaphore waits; G13/G14 (serialized queues withoutexact_prior) and virtio stay on the existing path. Payload tracking wrapsdrm_syncobjinit/signal/reset/move/import/export (leavingfinishunchanged sovk_sync_type_is_drm_syncobj()holds),copy_sync_payloads, empty submits, andvkDestroySemaphore/vkDestroyFence; shared payloads (VK_SYNC_IS_SHARED), sibling-queue runs (gpu_wait_generation), queue replacements, prepended commands, and split submissions conservatively fall back to kernel input syncs.Not yet: Hardware-tested on J716c Apple M5 Max; needs hardware test runs on M3 (G15) and M4 (G16/G17P). Cross-queue waits, timeline semaphores, and queues that have run a sibling kernel queue keep kernel input syncs.
Details and verification evidence
Summary
src/asahi/vulkan/hk_gpu_waits.h,hk_gpu_waits.c,meson.build:vk_synctag table recording(queue, generation, submitted[VDM/CDM])for non-shared, non-timeline wrappeddrm_syncobjsemaphores, gated purely on!dev->dev.is_virtio && (features & DRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERS).init,signal,signal_many,reset,reset_many,move(forgetting if either side carriesVK_SYNC_IS_SHARED),import_opaque_fd,export_opaque_fd,import_sync_file, andexport_sync_file, while preservingfinish(vk_drm_syncobj_finish).vk_device::copy_sync_payloads(hk_gpu_waits_copy_sync_payloads()) to forget signals and consume waits before delegating tovk_drm_syncobj_copy_payloads().src/asahi/vulkan/hk_physical_device.{h,c},hk_device.{h,c}:syncobj_base_typeand wrapsyncobj_sync_typewhenDRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERSis supported on non-virtio devices (assertingvk_sync_type_is_drm_syncobj()stays true).dev->gpu_waitsinhk_CreateDevice()and clean up in bothfail_dev:andhk_DestroyDevice().src/asahi/vulkan/hk_sync.{h,c},hk_queue.{h,c}:hk_sync_queue::wait_floor[HK_SYNC_NUM_SQ]applied inresolve_one()andhk_sync_host_flush_prefix().wait_floor, prevent sibling routing whilewait_flooris active, tag binary signals before ioctl submission (forgetting on failure), bumpqueue->gpu_wait_generationon queue restart or sibling use, forget tags on empty submits, and clear tags inhk_DestroySemaphore()/hk_DestroyFence().src/asahi/vulkan/tests/test-hk-sync-prior.c:wait_floorapplies to both render (prior+prior_ta) and compute commands across subqueues, preserves tighter in-submission barriers, propagates intohk_sync_host_flush_prefix(), and does not leak to the next submission.Build & Artifacts
J716c Apple M5 Max (G17C B1), Fedora Remix 44, kernel7.3.0-40.j716c19.fc44.aurora.aarch64origin/aurora-wip0b8e9b836cc):libvulkan_asahi.soSHA-256dfeef6f446046502ef9ed398f89657d523b6762fa230798828523f16a85548adb98042329d1):libvulkan_asahi.soSHA-2560973af5fd9a61d8a3d641abee24ca067bb9f1d0da335b1ae2c3d41588e252641Verification
--suite asahi --suite poly, Gallium + Vulkan +drm-shim, assertions enabled):334/334 PASS, 0 FAIL.MESA_SHADER_CACHE_DISABLE=1; exact pixel128,64,32,255, exact SSBO chain arithmetic, wait==signal reuse, empty-submit bridge, and destroy/recreate reuse PASS on every run):gfx16)2.6936 ms0.6676 ms4.04x)mixed16)2.4554 ms0.7985 ms3.07x)comp32)0.6527 ms0.6552 ms+0.4%(within noise)deqp-vk, base vs head,MESA_SHADER_CACHE_DISABLE=1):293-case slice acrossdEQP-VK.synchronization.smoke.*,dEQP-VK.synchronization{,2}.basic.binary_semaphore.*,dEQP-VK.synchronization{,2}.op.{single,multi}_queue.binary_semaphore.*, anddEQP-VK.api.external.semaphore.{opaque_fd,sync_fd}.*:216/293 PASS, 0 FAIL, 77 NotSupported(0status diffs vs base).SELinux=Enforcing,0DRM/asahi/GPU kernel errors.