fix(host): the vsync ticker starts once; a failed ticker or audio renderer leaves no waiter #2151
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2151
Loading…
Reference in a new issue
No description provided.
Delete branch "dazemc/Longshot:fix/vsync-ticker-lock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
nn::vi::GetDisplayVsyncEventregisters the caller's event in a table of 8 undervsync_lock, but starts the ticker outside the lock:Two guest threads can both see
vsync_thread == NULLand each start a ticker. Every ticker runshos_system_event_signalover the table once per period, so an auto-cleared vsync event fires twice per 16.7 ms and a waiter paced on it runs at double rate. On LinuxCreateThreadispthread_createwith a detached thread, and it returns after the thread may already have run — the window is real, not theoretical.Separately, with 8 events registered the
ifis false, the call returns 0, and the 9th event is never in the table: its waiter blocks forever.What changed (
host/nn_vi.c): the registration and the ticker start are one section undervsync_lock; a full table returns Horizon'sos::ResultOutOfResource(0x2C01, the code the host already uses for a full TLS slot table) and logs one line, instead of a silent success. ACreateThreadthat returns NULL — the thread limit, or no memory — is the same failure by another path: the registration is taken back, the call returns0x2C01, and no event is left in the table with no ticker to signal it. A later call tries the ticker again. The ticker logs its start once (vi: the vsync ticker started), so a game run's log shows it.host/nn_audio.c'sOpenAudioRendererhas the same shape: it initializes the caller's auto-cleared renderer event and starts the audio thread. A NULLCreateThreadnow clearsrenderer_event, the handle andrenderer_running, returns0x2C01, logs it and leavesrenderer_threadNULL so a later call retries; the event is never left registered with no thread to signal it.Testing
Tested: at this head:
run_all --strict test_vsync_events test_audio_renderer_start: 2 passed, 0 failed, 0 skipped (0.3 s and 0.1 s; a passing check does not print the fixture's own lines).fix/posix-renderer-thread(a separate branch, no PR yet): PASS —a renderer thread that cannot start: reported failure, event sets 0, attempts 1.origin/main'shost/nn_audio.c: fails onmainfor the reason —FAIL:56 result == 0x2C01, witha renderer thread that cannot start: result 0, handle 0x1, event 0x5000, thread (nil), attempts 1:mainreturns 0 and leaves the event registered.5db210a3: 913 passed / 23 failed / 18 skipped in 815 s (the job's full output is saved at/home/daze/.local/share/longshot-dev/2151-light-job-5db210a3.log),run_all.py --strict --jobs 5insidesystemd-run --user --scope -p MemoryMax=12G -p MemorySwapMax=0with the pinned headers. The 23 failures are the same namesmainfails (listed under the checklist), compared name by name; the two extra passes overa2dc5385's 911 are the newtests/test_vsync_events.pyandtests/test_audio_renderer_start.py.5db210a3: queue job2151-smoke-gpu(gpumode, alone), Arch Linux, RTX 4070 Ti, NVIDIA 620.70.06, headless, from the repository'skokiri-startsave: title to play after 8 A presses, 30 s of play, screenshot at frame 3515, thenquit— run statefinished, exit code 0,stop_method: quit. The log's line 224 isvi: the vsync ticker startedand line 279 isaudio: renderer opened; there is nocould not startline and no startup hang. (The first attempt, insharedmode, was OOM-killed during first-start shader preparation with another game beside it; this run prepared them and finished.) Run folder:/home/daze/.local/share/longshot-dev/runs/control/2151-smoke-20261122-012558/.The fixture lines the new checks assert (the branch run is above; the audio fixture's line is printed only on a failure):
The checks that cut/read
host/nn_vi.c(test_realtime_rate,test_water_substeps,test_camera_speed,test_fps_stats,test_movie_frame_count,test_scene_format) all passed in this suite.Earlier in the game, at
5bc9f83a(before the failure-path cases and this head; the smoke under the machine lock replaces it): Arch Linux, Hyprland, RTX 4070 Ti (NVIDIA 620.70.06), a pack over1885234b: Kokiri Forest (child), 20 s after warm-up — 1816 frames, 90.8 fps, median 11.03 ms, 0 cold frames (base: 1851 frames, 92.6 fps, 10.78 ms).Still to test:
Measurements
Nothing to measure: this fixes a race and a dropped registration, not a frame path; the in-game run above is a boot/play check and its one-run difference is not attributable.
Risks
A full vsync table, a ticker that cannot start, or an audio renderer that cannot start now reports
0x2C01instead of 0 — a caller that ignores the Result still blocks on its unsignalled event, but the failure is visible in the result and the log, and the failed start leaves no event or handle registered behind. A later call can try again. One ticker instead of two changes only the double-signalling case. No switch; a revert is enough.Checklist
Ready for review
main; the title is a Conventional Commit.5db210a3: title to play, 30 s, quit, exit 0; the log showsvi: the vsync ticker startedandaudio: renderer opened, no startup hang (Testing).mise run testpasses (any failure that also fails onmainis named). At this head: 913 passed / 23 failed / 18 skipped in 815 s,tests/run_all.py --strict --jobs 5insidesystemd-run --user --scope -p MemoryMax=12G -p MemorySwapMax=0with the pinned headers, rebased ontoa2dc5385.mainata2dc5385was 911 passed / 23 failed / 18 skipped in 635 s (--jobs 3, 8G); the two extra passes are the newtests/test_vsync_events.pyandtests/test_audio_renderer_start.py. Failing names identical (23, compared name by name):nx2/test_import_windows.py,tests/test_close_waits_for_save.py,tests/test_compile_zero_byte.py,tests/test_cpm_discovery.py,tests/test_damaged_rom_files.py,tests/test_dev_packs.py,tests/test_draw_stream_visibility.py,tests/test_fs_save_commit.py,tests/test_fsr_uniform_ownership.py,tests/test_guest_copies.py,tests/test_hold_toggle.py,tests/test_lower_atomg_cas.py,tests/test_menu_i18n.py,tests/test_menu_keys.py,tests/test_menu_slider_ends.py,tests/test_mise_build.py,tests/test_pads_after_menu.py,tests/test_recording_admission.py,tests/test_sim_turf_pools.py,tests/test_sim_turf_settings.py,tests/test_switch_table.py,tests/test_tls_objects.py,tests/test_vibration_menu.py. The 23rd,tests/test_sim_turf_pools.py, is new ona2dc5385since9e10f6f7and is #2174's stale check (it asserts the old zero turf floor, while #2174 made the floor the game's size); it fails identically here. Both new checks are among the 913 passes.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. The vsync fixture fails onmain(two tickers from two callers, and the 9th event gets result 0) and passes here; the audio fixture fails onmain(FAIL:56 result == 0x2C01, with result 0 and event 0x5000 still registered) and both pass at this head.tests/that reads changed source is new and does not weaken an existing check.host/nn_vi.candhost/nn_audio.ccompile asx86_64-w64-mingw32COFF objects (machine0x8664) with llvm-mingw 20261104's clang 23.1.5 undernx2/build.py's host flags,-Wno-everythingincluded (/home/daze/.local/share/longshot-dev/2151-wincoff/). The full Windows link is not made on this PC.Ready to merge
@Beanstalkrequest was posted on 2026-11-22 00:02, BeanBot answered that only a member ofBigBeanscan start it, and no approval has come yet. The by-hand item has not run either. Ticks when that result is in Tested.5bc9f83a: Arch Linux, RTX 4070 Ti, NVIDIA 620.70.06 (the earlier smoke above); at5db210a3it waits for the machine lock. Tier 1's Windows half has not, which is the same pending Windows item.pr status: Reviews: none); the Beanstalk approval is waiting for a BigBean.main, measured again or a comment says why the numbers still hold. The description is for head5db210a3; the suite at this head is green apart from the 23 failuresmainalso has, and the in-game smoke passed at this head. The CI status of6dd681beorf00baf93is not evidence for5db210a3; re-confirm CI when the head reports.Tested in game: Kokiri Forest (child), pack over
1885234b, 20 s: 90.8 fps median 11.03 ms, 0 cold frames; boots and plays. Arch Linux/Hyprland, RTX 4070 Ti, NVIDIA 620.70.06.fa9f400442936b343728Rebased onto
344deb6c(head936b3437); #2159 also touches host/nn_vi.c and the rebase was clean, test_vsync_events still passes. The in-game run was on1885234b.@Beanstalk Windows: start the game on this branch and confirm
GetDisplayVsyncEventstill runs and the game presents normally — vsync events still delivered, no stall on start. Its fixture is Linux-only, so only the start is asked.Ready otherwise.
@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for936b343, and the PR has changed since (6dd681b), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Resultto WIP: fix(host): the display's vsync ticker starts under the table's lock, and a full table is a ResultBack to WIP for one box: this head's merge base is
344deb6c, andmainhas since moved toa2dc5385with #2171 (9e10f6f7) fixing the game-free checks (~199 test files). The suite numbers here were measured against the oldmain(813/116/18 there, now 911/22/18), so 'mise run test' is unticked until a rebase ontoa2dc5385and a re-run oftests/run_all.py --strict,test_vsync_eventsincluded.The in-game smoke stands: its record (
5bc9f83a, 1816 frames, 90.8 fps, 0 cold frames) matches, and the changed lines ofhost/nn_vi.care identical to the head's.The Ready to merge boxes stay unticked, each with its reason beside it: Windows (fixture is Linux-only) is with the Test Farm, waiting for a BigBean; no review yet; CI's build/test jobs are still pending.
936b3437286dd681bef0Rebased onto
a2dc5385: head is now6dd681be. The rebase was clean — one commit replayed with no conflicts.Full game-free suite, run in the same shape as a clean
a2dc5385baseline (tests/run_all.py --strict --jobs 3,systemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0, the pinned headers):a2dc5385: 911 passed / 23 failed / 18 skipped in 635 s6dd681be: 912 / 23 / 18 in 618 sFailing names identical, compared name by name (23); the extra pass is the new
tests/test_vsync_events.py. The one name new ona2dc5385since9e10f6f7istests/test_sim_turf_pools.py: #2174 changed the simulated-turf floor while that old check still asserts a zero floor, so it is stale onmainand red identically here.In-game evidence (Jev: 0.77, likely valid): the smoked
5bc9f83arecord matches, the changed lines inhost/nn_vi.care identical to this head (#2159 touches the same file elsewhere), and no commit in344deb6c..a2dc5385touches it. No new in-game run was made.WIP: fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Resultto fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Result@Beanstalk Windows: start the game on this branch and confirm
GetDisplayVsyncEventstill runs and the game presents normally — vsync events still delivered, no stall on start. Its fixture is Linux-only, so only the start is asked.Head:
6dd681be(rebased ontoa2dc5385).@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for6dd681b, and the PR has changed since (9cd4714), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.9cd4714fdef00baf93a7Description updated for head
f00baf93: the CreateThread NULL path now covers the vsync ticker and nn_audio.c's renderer (event/handle cleared, 0x2C01, retry), with tests/audio_renderer_start_test.c + test_vsync_events' new case; the vsync fixture's InterlockedDecrement stub is in this head. The suite numbers at a2dc5385/6dd681be are not evidence forf00baf93: the targeted fixtures and suite atf00baf93are queued, results to follow.fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Resultto WIP: fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Resultf00baf93a75db210a3e1Marked WIP and unticked the boxes the new head invalidates (in-game test, suite, fix-fails-on-main: reasons beside each). Head is now
5db210a3: the ticker logs its start once ("vi: the vsync ticker started") so the in-game smoke can read it out of the log; that is the only change sincef00baf93. One queued job will run, in order: the two branch fixtures, the POSIX fixture (separate branch), the audio fixture against origin/main (it must fail there for the reason), the full suite at this head (jobs 5, MemoryMax=12G), then dev.py rt and a shared-mode game smoke (kokiri-start save, title to play, 30 s, quit) checking the ticker line, "audio: renderer opened" and no startup hang. Boxes stay unticked until that output is in Tested.Added the host-build checklist row the diff suggests (host/nn_audio.c and host/nn_vi.c): unticked until the queued Linux build and the Windows item land. No code change in this update.
WIP: fix(host): the display's vsync ticker starts under the table's lock, and a full table is a Resultto WIP: fix(host): the vsync ticker starts once; a failed ticker or audio renderer leaves no waiterRe-queued without blocking timing runs: the POSIX fixture, the audio fixture against origin/main and the full suite at
5db210a3now run as one light job in the job queue (dev.py queue run --mode light), outside the machine lock; only dev.py rt and the 30 s game smoke take the lock, after the timing jobs ahead of them (#2154's keys, finalized-2). The description's "queued" wording is corrected accordingly (the lock poller is not a queue job). Title widened to name the nn_audio.c half. Already green at this head: run_all --strict test_vsync_events test_audio_renderer_start, 2 passed.Results at
5db210a3, light job outside the machine lock: POSIX fixture PASS (reported failure, event not set, one attempt); audio fixture against origin/main fails for the reason (FAIL:56 result == 0x2C01, result 0, event 0x5000 still registered) and passes here; full suite 913 passed / 23 failed / 18 skipped in 815 s with --jobs 5 under MemoryMax=12G, the 23 names identical to main's. Ticked the suite and fix-fails-on-main boxes from that output. Still unticked: in-game smoke (running under the machine lock after the timing jobs, including #2154) and the host-build box's Windows half. Title and wording already correct.The first in-game smoke at
5db210a3did not reach the title: the system OOM killer killed the shared queue job during first-start shader preparation (start-up 36499/38809, 38809 programs, 6.2G peak + 3.8G swap) while another shared game ran. That is machine pressure, not a code result; the run's log shows the host up to device init only, so nothing is ticked. Retrying alone in the queue's gpu mode with a 900 s readiness timeout, under the machine lock after the timing jobs (#2154 is ahead).Correction: the smoke retry is now a real queue ticket, not a lock poller — job 2151-smoke-gpu, mode gpu (no other game beside it), readiness timeout 900 s, waiting for the GPU behind #2154's shared probe; queue status shows it. The 913/23/18 suite output is saved at /home/daze/.local/share/longshot-dev/2151-light-job-5db210a3.log and the body names it. The Windows COFF check for host/nn_vi.c and host/nn_audio.c is job 2151-wincoff (light), waiting on the queue's memory admission; the host-build box stays unticked until it compiles.
Windows half of the host-build box done: host/nn_vi.c and host/nn_audio.c compile as x86_64-w64-mingw32 COFF objects (machine 0x8664, 33 KB and 170 KB) with llvm-mingw 20261104's clang 23.1.5. The first attempt used #2180's shortened flag list and failed on nn_vi.c's early rx_option call (implicit declaration); the real host flags from nx2/build.py add -Wno-everything, and both compile with them. Objects at /home/daze/.local/share/longshot-dev/2151-wincoff/. Box ticked. Smoke 2151-smoke-gpu still waits for the GPU.
In-game smoke passed at
5db210a3(job 2151-smoke-gpu, gpu mode alone): title to play after 8 presses, 30 s of play, screenshot at frame 3515, quit with exit 0. Log line 224 'vi: the vsync ticker started', line 279 'audio: renderer opened'; no could-not-start line and no startup hang. Ticked the in-game box; the earlier OOM was the shared-mode first-start shader preparation with another game beside it, not the change. With the suite, the fixtures and the Windows COFF objects, every Ready-for-review and When-it-applies box is ticked.WIP: fix(host): the vsync ticker starts once; a failed ticker or audio renderer leaves no waiterto fix(host): the vsync ticker starts once; a failed ticker or audio renderer leaves no waiterView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.