From 1ada4a75866150e28ad03b82658799ded77c937d Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 14 Nov 2026 11:15:01 +0300 Subject: [PATCH] Wake the recorder through the fenced check on every publish (#1174) pub_now stored head and read Q.sleeping with no fence between them, while rec_main sets Q.sleeping and then reads head. x86 may read Q.sleeping before the head store is visible, so both sides could miss each other and the recorder slept out its 2 ms timeout with packets waiting. Since rec_submit returns without a drain (TOTK_REC_ASYNC=1), its publish is the last of a submission, and the present, uploads and readbacks waited for that timeout in rec_queue_wait: a #1174 log on an RX 9070 XT shows 1.6 to 3.4 ms a wait late in the session against 0.04 ms at its start. pub_now now wakes through wake(), which has the fence. Cost: one locked instruction per publish, about 2300 a frame in that scene. Co-Authored-By: Claude Opus 5.5 --- runtime/vk_rec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/vk_rec.c b/runtime/vk_rec.c index ee664c29..56dc5361 100644 --- a/runtime/vk_rec.c +++ b/runtime/vk_rec.c @@ -175,11 +175,16 @@ static void *put(uint32_t op, size_t bytes) { // cost the producer an event set and the recorder a wake-up. Savage Wind Recomp measured that at 6.7% of its render // thread's busy time on 4 cores and moved to 64 KiB there (runtime/nvn/vulkan/record.c rec_init, publish_every). // TOTK_REC_PUB= sets the batch; =ab: 64 words in the A blocks of TOTK_AB, 8192 in the B blocks. +// The wake goes through wake(), whose full fence orders the head store before the read of Q.sleeping. rec_main sets +// Q.sleeping and then reads head; without the fence x86 may read Q.sleeping before the head store is visible, both +// sides miss each other and the recorder sleeps out its 2 ms timeout with the packets waiting. Since rec_submit returns +// without a drain (TOTK_REC_ASYNC=1), its publish is the last one of a submission, and every queue user then waited in +// rec_queue_wait for that timeout (issue #1174: 1.6 to 3.4 ms a wait on an RX 9070 XT). static int pub_ab; static void pub_now(void) { Q.pub_h = Q.put_h; __atomic_store_n(&Q.head, Q.put_h, __ATOMIC_RELEASE); - if (__atomic_load_n(&Q.sleeping, __ATOMIC_RELAXED)) plat_event_set(&wake_ev), RS_.wakes++; + wake(); } static void pub(void) {