Repository navigation
hk: send a G17P host-only event wait after vkSetEvent - #555
jgoyvaerts wants to merge 1 commit into
Conversation
On G17P, vkCmdWaitEvents2 is a one-thread compute launch that polls the event word (hk_g17p_meta_wait_addr()). A host vkSetEvent made while that poll runs is never seen: G17P loads, coherent loads and atomics do not see a host write made while their command runs, only one made before the command starts, so the wait never ends and the kernel's watchdog kills the queue. A set made before the poll starts is seen. A wait whose first synchronization scope is the host stage alone waits on a host-set event (VUID-vkCmdWaitEvents2-pEvents-03839; vkCmdSetEvent2 cannot name the host stage). Its poll now starts a hardware command of its own: the stream is not merged with the one before it when the command buffer ends. If the event is still reset when the submission is built, queue_submit_looped() ends the ioctl before that command and sends the rest once vkSetEvent has set it, so the poll starts after the host write and sees it. Work after the wait on the queue starts after the set too, as on hardware that blocks the queue at the wait. The kernel resolves an ioctl's input syncs when it is submitted, so it cannot wait for a host signal that comes later; the wait is a CPU wait on the queue's submit thread. hk_QueueSubmit2() starts that thread for the first command buffer holding such a wait, as the runtime does for a wait before signal. vkDestroyDevice ends a wait whose set never came, so the queue can join its thread. A queue without a submit thread (MESA_VK_ENABLE_SUBMIT_THREAD=0) or whose submissions run under a lock keeps the plain poll. A legacy vkCmdWaitEvents mask that mixes the host stage with device stages for other events stays on the plain poll as well. Each cut adds one ioctl; submissions without host-only waits are unchanged. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com> Assisted-by: LLM
190bd13 to
4b25c7f
Compare
|
Rebased onto aurora-wip 4596393 for the mesa merge train (owner-authorized; authorship kept, conflict resolution only). Old head 190bd13 -> new head 4b25c7f. One conflict, in Next: independent review, then batch 2 of the train (host build + |
Merge train (batch 2): independent review of the rebased head 4b25c7fVerdict: CLEAN WITH NITS. Independent code-only review (Opus 5.5, xhigh). No blocker or major. The mechanism checks out as traced: the poll's own command, where the ioctl splits, the barriers across the split, the submit-thread locking, and the wake on Two MINORs for you, @jgoyvaerts (neither blocks the train; please say whether you want to address them before or after the merge):
NITs:
Reach: G17P only, on by default there; other chips unchanged. Train: batch 2 ( |
|
Merge-train status (02:4x): held for its Neo (G17P) row. The independent review is clean with nits, posted above. This PR reaches the A18 Pro (G17P), so per the train's rule it merges only after both of these:
The Neo has been offline since about 02:04 (it idle-suspended and needs a physical wake), so its row can't run until it is back. Everything else for this PR will be ready by then. G17P owners' rows (A18 Pro / M4 Pro / M4 Max) on the head above would unblock it sooner. |
|
Closing this. @DjDeveloperr, please drop it from While working on your two MINORs I checked the spec. The usage this PR handles is invalid:
Valid apps set the event before Not doing it is the right fix: aurora-wip keeps its current behaviour, and queues no longer pay for keeping their submit thread. Thanks for the review that led here. |
|
@jgoyvaerts, a small request from the merge train: could you rebase this onto current aurora-wip (afcc08b)? It's conflict-free; the train's local rebase gives identical commits.
|
Problem. On G17P,
vkCmdWaitEvents2is a one-thread compute launch that polls the event word (hk_g17p_meta_wait_addr()). A hostvkSetEventmade while that poll runs is never seen, so the wait never ends and the kernel watchdog kills the queue after 30 s.G17P loads, coherent loads and atomics don't see a host write made while their command runs, only one made before the command starts. Measured with a repro that ends a stuck wait through a GPU set from a second queue:
Change. A wait whose first synchronization scope is the host stage alone waits on a host-set event (VUID-vkCmdWaitEvents2-pEvents-03839). Its poll now gets a hardware command of its own:
queue_submit_looped()ends the ioctl before that command. The queue's submit thread sends the rest oncevkSetEventhas set the event, so the poll starts after the host write and sees it.hk_QueueSubmit2()starts that thread for the first command buffer with such a wait, the same way the runtime does for wait-before-signal.vkDestroyDeviceends a wait whose set never came, so the queue can join its thread.Testing. M4 Pro (G17P), GPU runs guarded, 0 recoveries. New shim test
hk-g17p-host-event-wait:host wait: 1 ioctls after vkSetEvent ... expected 2 starting with compute) and passes with this change.vkDestroyDevicereturns when the set never comes.Testing detail
Repro (wait seen at once, out of 3):
Cost (fill, then wait or barrier, then fill; medians of 300 runs, two rounds), submit call / round trip:
A host-only wait costs one extra ioctl plus the submit-thread hop, about 30–45 µs. Plain submissions on a queue that once had such a wait are 9–36 µs slower, because the queue keeps its submit thread. DXVK and vkd3d-proton don't wait on events inside command buffers.
synchronization*.event*(6213): 5779 P / 434 NS, identical to before.api.command_buffers(131): 65 P / 66 NS.--suite asahiran on this branch, rebased onto aurora-wip67066c92f.Not covered:
vkCmdWaitEventswhose source mask mixes the host stage with device stages stays on the plain poll.vkCmdResetEvent2in the same submission isn't split.vkDestroyDevice, a held-back wait keeps waiting for the host's set.MESA_VK_ENABLE_SUBMIT_THREAD=0) keeps the plain poll.Assisted-by: LLM
🤖 Generated with Claude Code