Test held work against the event's value now when another thread asks without the submission lock, and read the held count and the submission count as atomics there.

vk_exec_held_ready runs without sub_lock (vk_backend.c held_resume, submit_sync). It decided from the published copy
since 688b2506, but tested the wait with vk_exec_event_met, which compares at the copy point of the submission being
recorded (vk_exec_xfer.c ev_mem, ev_sync_seq). That point is set by whichever thread holds the lock, so a thread asking
while another one recorded tested "at sync" against that other submission's copies. Its question is whether held work
can go on in a submission of its own, which takes its copies later: vk_exec_event_met_now tests the value in memory now
or the signals replayed so far. Under the lock nothing changes: evo_resume and cont_ready keep the copy-point test, and
vk_exec_record asks right after its own copy point, where the two agree.

evo_pending and vk_exec_submit_seq are written under the lock and were read as plain values by vk_exec_held,
vk_exec_held_ready and the held present's since and PH_MAX checks; they are now stored and loaded as atomics
(vk_exec_submit_seq_now), so the compiler cannot keep a stale copy in an unlocked reader.

Not reproduced before the change. Checks that passed: pass_cc_check on every runtime file (a header changed), no new
-Wall -Wextra warnings in vk_exec.c, vk_exec_xfer.c and vk_backend.c, evo_peek_check, target_frames_check and
oq_hold_check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 18:57:20 -05:00
parent cde143c5d9
commit 7a1c220e06
4 changed files with 39 additions and 13 deletions

View File

@@ -768,7 +768,7 @@ static void oq_report(VkExec *ex, uint64_t addr) {
// wait whose signal comes in a later submission does not hold its work back: that work runs before what it waits for.
// The replay keeps the value each event reaches in replay order (ev_seen, the signals recorded so far, on top of the
// value in memory) and counts the waits it reaches unmet; NX2NAVI_TRACE=perf logs the count, and the first few are
// logged as they happen. Replay thread only.
// logged as they happen. Replay thread only, apart from vk_exec_event_met_now's unlocked read of ev_seen.
#define EV_SEEN 64
static struct { volatile uint32_t *val; uint32_t v; } ev_seen[EV_SEEN];
static int ev_n, ev_next;
@@ -903,6 +903,22 @@ int vk_exec_event_met(const void *payload) {
return ev_met(payload, &mem, &seen, &late);
}
// The value in memory now, or the signals replayed so far, whatever submission is being recorded: for vk_exec.c
// vk_exec_held_ready, which asks without the submission lock whether held work can go on in a submission of its own.
// That submission takes its copies later, so a CPU signal given before now counts for it; testing at the copy point
// (ev_mem) would take the copy point of the recording another thread may be making. ev_seen belongs to the replay and
// is read here without its lock, so the answer is a decision only: a wrong "ready" makes an empty submission, which
// decides again under the lock (vk_exec.c evo_resume).
int vk_exec_event_met_now(const void *payload) {
const p_wait_event *p = payload;
if (ev_holds(__atomic_load_n(p->val, __ATOMIC_ACQUIRE), p->mode, p->value)) return 1;
int n = __atomic_load_n(&ev_n, __ATOMIC_RELAXED);
for (int i = 0; i < n && i < EV_SEEN; i++)
if (__atomic_load_n(&ev_seen[i].val, __ATOMIC_RELAXED) == p->val)
return ev_holds(__atomic_load_n(&ev_seen[i].v, __ATOMIC_RELAXED), p->mode, p->value);
return 0;
}
int vk_exec_signalled;
int vk_exec_wait_event(const void *payload) {