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 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-14 11:15:01 +03:00
1 parent 42b36b0e0b
commit 1ada4a7586
1 file changed
+6 -1
+6 -1
View File
@@ -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=<words> 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) {