fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocate #2141
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!2141
Loading…
Reference in a new issue
No description provided.
Delete branch "dazemc/Longshot:fix/os-timer-holder-period"
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
A periodic
TimerEventlinked into a multi-wait is reported ready forever.wait_anyasksholder_ready, which answers "due" wheneverdue_nshas passed, but nothing on that path advancesdue_ns— while both single-timer paths do (WaitTimerEvent,TryWaitTimerEvent:while (t->due_ns <= now) t->due_ns += t->period_ns). So the first expiry makesWaitAny/TimedWaitAny/TryWaitAnyreturn that holder on every call, the period is ignored, and a guest wait-any loop spins.The same file has two allocation defects on the multi-wait holder array:
LinkMultiWaitHolderandMoveAllMultiWaitHolderstorerealloc's result unchecked and then writemw->links[mw->nlinks++], so a failed allocation dereferences NULL — andMoveAllMultiWaitHolder(to == from)appends to the list it iterates, doublingnlinksuntil the realloc fails and the NULL write crashes.What changed:
timer_consumed(new): advances a periodic timer'sdue_nsby whole periods, skipping any that passed meanwhile, as a hardware timer would;wait_anycalls it when it selects a timer holder as ready. The two single-timer paths use the same helper.LinkMultiWaitHolder: grow into a temporary, publish on success; a failed allocation refuses the link.MoveAllMultiWaitHolder:to == fromis a no-op; the destination is grown once for the whole move, and a failure refuses the move whole, leaving the holders with their source.Read
host/nn_os_sync.c'stimer_consumed,wait_any,LinkMultiWaitHolderandMoveAllMultiWaitHolderfirst; the test istests/test_multiwait_wake.py.Testing
Tested: Arch Linux, Hyprland (Wayland), RTX 4070 Ti (NVIDIA 620.70.06), built as a pack over
8aa74983, from this branch ata3dae742and played: Kokiri Forest (child), 20 s measured after warm-up — the game boots and plays, 1862 frames, 93.1 fps, median 10.66 ms, p99 14.48 ms, 0 cold frames (base: 1805 frames, 90.3 fps, median 11.08 ms). The fix is latent on the shipped game, so no gameplay change is expected.run_all --strict test_multiwait_wakepasses; the new cases fail onmain(TryWaitAny left the timer holder due at 1,reported the periodic timer holder again, thenSIGSEGVatmw->links[mw->nlinks++] = h; with only theLinkfix,SIGSEGVat the self-move), and all 13 checks that readhost/nn_os_sync.cpass.Game run at
a3dae742; the head805361a2is that change rebased ontoa2dc5385— this branch's own diff is identical (git diff 8aa74983 a3dae742andgit diff a2dc5385 805361a2produce the same diff) andhost/nn_os_sync.cis byte-identical, so the run covers this change's game code.Still to test:
Measurements
Nothing to measure: the fix is latent on the shipped game — no path we can observe links a periodic timer into
WaitAny— and the in-game smoke above shows no attributable difference (93.1 against 90.3 fps, one run a side).Risks
Could break: a guest that links a periodic timer into a multi-wait now sees the period honoured instead of an always-ready holder (the intended behaviour); one-shot timers are unchanged on purpose. A failed
LinkorMoveAllis now refused instead of crashing — the SDK returns void, so a refusal is silent, as a failed watch registration is. No switch; a revert is enough. Nothing changes for saves,longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Rebased ontoa2dc5385;tests/run_all.py --strict --jobs 3insidesystemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0with the pinned headers.mainat9e10f6f7was 911/22/18; ata2dc5385it is 911 passed / 23 failed / 18 skipped in 635 s — the 23rd istests/test_sim_turf_pools.py; this head805361a2: 911 / 23 / 18 in 629 s. 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.test_multiwait_wake(0.3 s) and the 13 checks that cuthost/nn_os_sync.cpass.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/that reads changed source is updated, not weakened (tests/test_multiwait_wake.pygains the timer and allocation cases; no existing assertion removed).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.pr status: Reviews: none); the Beanstalk approval is waiting for a BigBean.main, measured again or a comment says why the numbers still hold. On head805361a2after the rebase: the description check passed, 11 checks still running, every build and test jobBlocked by required conditions. The suite re-run and the re-confirmed in-game evidence are in the comment and box above; re-confirm CI when it reports.Tested in game: Kokiri Forest (child) under a pack over
8aa74983: 20 s after warm-up, 93.1 fps median 10.66 ms, 0 cold frames; game boots and plays. Arch Linux/Hyprland, RTX 4070 Ti, NVIDIA 620.70.06.Checklist: ticked the 'tests read changed source' box (test_multiwait_wake.py extended, not weakened); left the Windows build box unticked and named in Still to test.
Checklist: the Windows build/start stays named in Still to test; the duplicate 'When it applies' box is removed, as the checker asks for a box it cannot tick.
a3dae742abc459701137Rebased onto
1101b612. The commits since the run (input, renderer, tests) do not touch host/nn_os_sync.c, so the in-game run still holds; head isc4597011.c4597011375b9642d7adRebased onto
344deb6c(head5b9642d7). Commits since the run touch input/renderer/tests, not host/nn_os_sync.c; the run still holds.Note for whoever is sequencing this: siantm's WIP #2090 (
perf/mutex-guest-id) edits the sametests/test_multiwait_wake.pyallowlist —safe_external, ~line 241 on main — that this PR rewrites (~233–265), so the two touch the same hunk. Whichever lands second resolves that hunk.No action needed from reviewers today; this is just so it isn't a surprise at merge time.
@Beanstalk Windows: build and start this branch, then verify
WaitAnyon a periodic timer holder still behaves — the holder should come back once per period, not on every call, and the guest's wait-any loop must not spin. The fixture here is Linux-friendly and the change is in shared host code (host/nn_os_sync.c), so the Windows build and start are what's left.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 for5b9642d, and the PR has changed since (805361a), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateBack 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(811/109/18 there, now 911/22/18), so 'mise run test' is unticked until a rebase ontoa2dc5385and a re-run oftests/run_all.py --strict.The in-game smoke stands: I checked its record (
a3dae742, 1862 frames, 93.1 fps, 0 cold frames) andgit diffofhost/nn_os_sync.c's changed lines is identical to the head's.The Ready to merge boxes stay unticked and now say why beside them: Windows is with the Test Farm, waiting for a BigBean's approval; no review yet; CI's build/test jobs are still pending.
5b9642d7ad805361a2d7Rebased onto
a2dc5385: head is now805361a2. The rebase was clean — both branch commits 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 s805361a2: 911 / 23 / 18 in 629 sFailing names identical, compared name by name (23). The one name new on
a2dc5385since9e10f6f7istests/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. This branch'stest_multiwait_wakeand the 13 checks that cuthost/nn_os_sync.cpass.In-game evidence (Jev: 0.71, likely valid): the smoked
a3dae742record matches the branch, the changed lines inhost/nn_os_sync.care identical to this head, and no commit in344deb6c..a2dc5385touches that file. No new in-game run was made.WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocate@Beanstalk Windows: build and start this branch, then verify
WaitAnyon a periodic timer holder still behaves — the holder should come back once per period, not on every call, and the guest's wait-any loop must not spin. The fixture here is Linux-friendly and the change is in shared host code (host/nn_os_sync.c), so the Windows build and start are what's left.Head:
805361a2(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.Testing now names the run commit and what separates it from the head:
a3dae742and805361a2are the same branch diff (git diff 8aa74983 a3dae742andgit diff a2dc5385 805361a2produce the same diff) andhost/nn_os_sync.cis byte-identical, so the in-game run covers this change's game code. No code change; stays ready.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.