frame_pacer: wake blocked waiters on set_uncapped and guard shutdown entry #1042
Open
github-bot
wants to merge 4 commits from
github-bot/gh-1042 into main
AGit
pull from: github-bot/gh-1042
merge into: github:main
github:main
github:docs/animation-merge-remnants
github:docs/story-dedup-and-cli
github:docs/restofworld-merge-remnants
github:docs/gamedata-dedup-tables
github:docs/textures-bcpack-tables-and-cli
github:docs/exe-fail-fast-shims-sync
github:fix/address-guard-wraparound-parity
github:fix/cvt-f16-denorm-and-clamp
github:docs/pso-cache-scope-note
github:docs/viewer-readme
github:docs/textures-arrays-dds-preview
github:docs/conformance-readme-status
github:fix/docs-validators-fences-urls
github:claude/loop-total
github:claude/pops-collision-seed
github:claude/dstorage-hold-page-reads
github:claude/host-image-copy-switch
github:feat/gdk-lifecycle-window-hook
github:claude/d16s8-uav-nvidia-fallback
github:feat/mfplat-offline-shim
github:claude/gameinput-slow-reader
github:fix/rt-null-barrier-clear
github:claude/depth-resolve-sample-positions
github:integration/palmetto-parity
github:claude/valu-literal-sext
github:claude/slot74-pool-handle
github:claude/rgb9e5-uint-alias-view
github:claude/fssm-root-layout-tables
github:feat/gdk-speech-display-lifecycle
github:asset-audio-skip-current
github:qemmhd/old-9940-rectangle-quad-lists
github:feat/ws2-offline-shim
github:qemmhd/rt-d16-unorm-uav
github:feat/xs-device-stops-7-9
github:qemmhd/rt-depth-same-base-shapes
github:qemmhd/rt-lazy-attachment-variant
github:feat/acphal-xma2-decoder
github:asset-audio-skip
github:codex/coord-claim-check-20261124-7e48
github:feat/xs-frame-pacing-presentx
github:feat/xs-device-vm-options
github:old-pr/9844
github:old-pr/9978
github:old-pr/9815
github:old-pr/10057
github:old-pr/9874
github:old-pr/9965
github:old-pr/9863
github:old-pr/10068
github:old-pr/10066
github:old-pr/10067
github:old-pr/10007
github:old-pr/10061
github:old-pr/10065
github:old-pr/10059
github:old-pr/10063
github:old-pr/10055
github:old-pr/10062
github:old-pr/10042
github:old-pr/10041
github:old-pr/10049
github:old-pr/10047
github:old-pr/10046
github:old-pr/10045
github:old-pr/10056
github:old-pr/10043
github:old-pr/10036
github:old-pr/10034
github:old-pr/9984
github:old-pr/10052
github:old-pr/10038
github:old-pr/10033
github:old-pr/10028
github:old-pr/10050
github:old-pr/9891
github:old-pr/9889
github:old-pr/10051
github:old-pr/10019
github:old-pr/10027
github:old-pr/10029
github:old-pr/10031
github:old-pr/10026
github:old-pr/9941
github:old-pr/10030
github:old-pr/10040
github:old-pr/9990
github:old-pr/10021
github:old-pr/9962
github:old-pr/10022
github:old-pr/10020
github:old-pr/10015
github:old-pr/10025
github:old-pr/9886
github:old-pr/10048
github:old-pr/10014
github:old-pr/10011
github:old-pr/9861
github:old-pr/10010
github:old-pr/10008
github:old-pr/9860
github:old-pr/10006
github:old-pr/9920
github:old-pr/9995
github:old-pr/10000
github:old-pr/10016
github:old-pr/10004
github:old-pr/10023
github:old-pr/9982
github:old-pr/9981
github:old-pr/9983
github:old-pr/9970
github:old-pr/9969
github:old-pr/9968
github:old-pr/9971
github:old-pr/9972
github:old-pr/9942
github:old-pr/9963
github:old-pr/9960
github:old-pr/9964
github:old-pr/9985
github:old-pr/9973
github:old-pr/9862
github:old-pr/9953
github:old-pr/10017
github:old-pr/9952
github:old-pr/9955
github:old-pr/9946
github:old-pr/9954
github:old-pr/9938
github:old-pr/9956
github:old-pr/9856
github:old-pr/9947
github:old-pr/9924
github:old-pr/9961
github:old-pr/9927
github:old-pr/9979
github:old-pr/10032
github:old-pr/9926
github:old-pr/5237
github:old-pr/9951
github:old-pr/9931
github:old-pr/9902
github:old-pr/9921
github:old-pr/9994
github:old-pr/9775
github:old-pr/9768
github:old-pr/9905
github:old-pr/9936
github:old-pr/9901
github:old-pr/9904
github:old-pr/9906
github:old-pr/9988
github:old-pr/9908
github:old-pr/9909
github:old-pr/9911
github:old-pr/9912
github:old-pr/9913
github:old-pr/9887
github:old-pr/9916
github:old-pr/9919
github:old-pr/9925
github:old-pr/9933
github:old-pr/9935
github:old-pr/9918
github:old-pr/9879
github:old-pr/9880
github:old-pr/9881
github:old-pr/9996
github:old-pr/9876
github:old-pr/9892
github:old-pr/9899
github:old-pr/9915
github:old-pr/9914
github:old-pr/9872
github:old-pr/9869
github:old-pr/9866
github:old-pr/9819
github:old-pr/10012
github:old-pr/9857
github:old-pr/9893
github:old-pr/9897
github:old-pr/9928
github:old-pr/9868
github:old-pr/9917
github:old-pr/9940
github:old-pr/9873
github:old-pr/9816
github:old-pr/10009
github:old-pr/9900
github:old-pr/9966
github:old-pr/9859
github:old-pr/9843
github:old-pr/9991
github:old-pr/10058
github:old-pr/9883
github:old-pr/9838
github:old-pr/9835
github:old-pr/9959
github:old-pr/9895
github:old-pr/9837
github:old-pr/9858
github:old-pr/9865
github:old-pr/9864
github:old-pr/9840
github:old-pr/9820
github:old-pr/4669
github:old-pr/9848
github:old-pr/9850
github:old-pr/9810
github:old-pr/9799
github:old-pr/9853
github:old-pr/9875
github:old-pr/9831
github:old-pr/9796
github:old-pr/9801
github:old-pr/9813
github:old-pr/9794
github:old-pr/7417
github:old-pr/9781
github:old-pr/9806
github:old-pr/9958
github:old-pr/9809
github:old-pr/9791
github:old-pr/9792
github:old-pr/10053
github:old-pr/9784
github:old-pr/9789
github:old-pr/9849
github:old-pr/9846
github:old-pr/9773
github:old-pr/9785
github:old-pr/9803
github:old-pr/9826
github:old-pr/9839
github:old-pr/9922
github:old-pr/9948
github:old-pr/7189
github:old-pr/9957
github:old-pr/9823
github:old-pr/9807
github:old-pr/9851
github:old-pr/9774
github:old-pr/9830
github:old-pr/9836
github:old-pr/9822
github:old-pr/9783
github:old-pr/9833
github:old-pr/9890
github:old-pr/9770
github:old-pr/9769
github:old-pr/9772
github:old-pr/9787
github:old-pr/9852
github:old-pr/9834
github:old-pr/9845
github:old-pr/9871
github:old-pr/9771
github:old-pr/9776
github:old-pr/10005
github:old-pr/9949
github:old-pr/9923
github:old-pr/9805
github:old-pr/9829
github:old-pr/9790
github:old-pr/9827
github:old-pr/9929
github:old-pr/9855
github:old-pr/9934
github:old-pr/9907
github:old-pr/9910
github:old-pr/9779
github:old-pr/9780
github:old-pr/9885
github:old-pr/9882
github:old-pr/9877
github:old-pr/9998
github:old-pr/4251
github:old-pr/9987
github:old-pr/9989
github:old-pr/9950
github:old-pr/9777
github:old-pr/10044
github:old-pr/9884
github:old-pr/2906
github:old-pr/5076
github:old-pr/9937
github:old-pr/9986
github:old-pr/3014
github:old-pr/9943
github:old-pr/9939
github:old-pr/4682
github:old-pr/4765
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
bug
Something isn't working
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
question
Further information is requested
wontfix
This will not be worked on
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1042
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1042"
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?
@madhyn on GitHub · 2026-11-24 17:07 UTC · original
madhyn:fix/frame-pacer-shutdown-wakeup→main· +152 −9 · 2 files · 4 commits · openWhat and why
Addresses the
runtime/src/frame_pacer.hwakeup/shutdown races reported in #14 by @akimfomin:set_uncapped):set_uncapped(bool)updateduncapped_undermutex_without notifyingcv_, so a waiter already blocked on the vblank grid missed the mode switch. It now callscv_.notify_all()after releasingmutex_.~FramePacer/wait_frame_event):~FramePacer()now holdsmutex_across settingshutdown_ = true, callingcv_.notify_all(), and enteringcv_.wait(lock, ...)(eliminating the unlocked window betweenshutdown_ = trueandcv_.wait), andwait_frame_eventreturnspacer_hr::invalid_stateimmediately ifshutdown_is already set before incrementingwaiters_.Testing
runtime/test/frame_pacer_test.cppcovering:FramePacerwith multiple blocked waiters (origin,vblank,flip).set_uncapped(true)while a waiter is blocked onManualFrameClock.ctest -R frame_pacer --output-on-failure(Wine 11.22,clang-cl+xwin): 1/1 passed (6.69 s).AI-assisted: yes
@morodirule on GitHub · 2026-11-24 17:08 UTC · original
Independent Linux check (native g++, ManualFrameClock, no game/GPU): my earlier finding repro now passes on head 5496f79f9 — flipping set_uncapped(true) wakes a tick-blocked waiter with rc=0 (was stuck till timeout), shutdown with a blocked waiter still 0 ms. Full frame_pacer_test: all cases pass, exit 0. The new uncapped-wakeup test in the PR covers the fixed path. This confirms the finding I reported on #14. Not claiming; review evidence.
@KernelSmoker on GitHub · 2026-11-24 17:20 UTC · original · approved these changes
Verified on exact head 5496f79f93c41f1134ce4c9e1d2674aa00c6bb55. I built
runtime/test/frame_pacer_test.cppon Linux with GCC 16.2 (-std=c++20 -pthread) and ran it successfully:frame_pacer_test: all cases pass, including blocked waiter release onset_uncapped(true)and destruction with three waiters. Changed-file no-game-data andgit diff --checkpass; merge-tree onto current main is clean. This independently validates the new threading regressions on Linux in addition to the PR-reported Windows/Wine run.@akimfomin on GitHub · 2026-11-24 17:21 UTC · original
Native Windows CPU check for
5496f79f93c41f1134ce4c9e1d2674aa00c6bb55(Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, C++20). The registeredframe_pacerCTest passed 3/3 (1.19–1.20 s).As a control, I used the unchanged PR tests with the header from the PR commit's parent
fce586c6. All three runs failed the two-second uncapped-wakeup assertion before the six-second process timeout. The parent’s original suite and the new shutdown test in isolation each passed 3/3 on the parent header. This A/B reproduced the missed wakeup.PortBridge linked the original Reforge tests to this Continued finding (PB-0020). Synthetic CPU target, runtime disabled, no game files or GPU. AI-assisted.
@fin-github on GitHub · 2026-11-24 18:00 UTC · original · reviewed
Built
frame_pacer_teststandalone withcl /std:c++20 /W4 /permissive- /utf-8 /O2:frame_pacer_test: all cases pass, 5 of 5 runs.main(32950551e) header with this PR's test file: fails at line 661 (waiter.wait_for(2 s) == ready), so theset_uncappedcase catches the missed wakeup.One gap: the new destructor case also passes with
main's header, so nothing tests the shutdown half of the change(setting
shutdown_under the same lock as the wait, and the earlyinvalid_statereturn inwait_frame_event).Could you add a case for a waiter that arrives after shutdown has started? For example, hold the pacer in
~FramePacer'scv_.waitwith one blocked waiter, then callwait_frame_eventfrom another thread and expectinvalid_statewith no hang. Without that case, a later edit could undo the guard without failing anything.Tested on Windows 11 Pro 26200, CPython 3.14.4, MSVC from VS 18 Community, applied on main
32950551e. No GPU or game files used. AI-assisted (Claude Code).@akimfomin on GitHub · 2026-11-24 18:06 UTC · original
Follow-up to fin-github’s Windows review: a check of the return code alone passes before and after the guard. I tried a live-object test seam that sets
shutdown_under the pacer’s mutex, plus a countingFrameClock. The active control succeeds and returns a token before stopping. After stopping, a separate thread callswait_frame_eventwhile the object remains alive.Across five runs per variant, exact head
5496f79f, that head with only the early guard removed, and parentfce586c6all returnedinvalid_statewith a zero token. The exact head made zero late clock reads. Removing the guard or using the parent made one late clock read in every run, because the call reachedwait_lockedbefore its shutdown check.This gives a deterministic regression for rejecting new work before entering the wait path. The scope is the early gate on a live object. Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, CPU only. PortBridge linked the review to the prior Windows A/B. AI-assisted.
@madhyn on GitHub · 2026-11-24 18:11 UTC · original
Added the late-waiter-during-shutdown regression test in
runtime/test/frame_pacer_test.cpp(thank you @fin-github and @akimfomin for the review and A/B clock-read suggestion):HoldingClockholds the first waiter out of returning while~FramePacer()is parked incv_.wait(lock, waiters_ == 0), then a second thread callswait_frame_eventwhile shutdown is in progress.pacer_hr::invalid_statewithtoken == 0, no hang, and zero additionalnow_us()clock reads (proving the earlyif (shutdown_)gate inwait_frame_eventrejects before enteringwait_locked).ctest -R frame_pacer --output-on-failure(Wine 11.22,clang-cl+xwin): 1/1 passed (1.69 s).AI-assisted: yes
@akimfomin on GitHub · 2026-11-24 18:19 UTC · original
Thanks for adding the clock check. I ran the registered test source at exact head
79a8f595on native Windows with LLVM-MinGW Clang 23.1.6, CPU only. It passed 5/5. Removing only the early shutdown guard made the clock assertion print in 5/5 runs, but each process then hung until the 6.5 s watchdog. The failingEXPECTreturns before the still-blocked waiter is released, so cleanup waits on a future.A test-only change fixed that failure path locally. Save
const int reads_after_late = clock.now_calls.load();immediately afterlate.get()and before releasing the clock. Move the late result assertion and the comparison ofreads_after_latetoreads_before_lateto just afterdtor.get(). The snapshot still measures the late caller. With that change the stock guard passed 5/5, and the guard-off control exited with the clock assertion and code 1 in 5/5 runs (~1.3 s). The production header is unchanged in the candidate. PortBridge case PB-0020. AI-assisted.@madhyn on GitHub · 2026-11-24 18:30 UTC · original
Updated
runtime/test/frame_pacer_test.cppper @akimfomin's note: snapshotreads_after_lateright afterlate.get(), releaseHoldingClockand joindtor/firstbefore checking the late-waiterEXPECTassertions so even a regression failure exits cleanly without blocking on cleanup.ctest -R frame_pacer --output-on-failure(Wine 11.22,clang-cl+xwin): 1/1 passed (1.8 s).AI-assisted: yes
@akimfomin on GitHub · 2026-11-24 19:49 UTC · original
Follow-up to the separate waiter-accounting check in the PortBridge pilot. On exact
0b65330e, the ordinary control completed 3/3 on Windows. When a synthetic clock threw fromnow_us()orwait()while the pacer mutex was held, the exception propagated and a later ordinary wait succeeded. Teardown then stopped in both runs of each exception case. A 2 s watchdog stopped those isolated test processes.A local change releases the registration as it goes out of scope, before the mutex unlocks. I tested this replacement after
++waiters_inwait_frame_event:The candidate finished all 9 ordinary and exception checks and all 10 shutdown checks where an existing waiter threw with shutdown underway. The registered
frame_pacer_testpassed 3/3 on each version. The candidate documents that an injected clock must retain or reacquire the same mutex before it returns or throws. The controls use that contract. This is a separate candidate for review on the public Continued code. PortBridge PB-0020. AI-assisted.@madhyn on GitHub · 2026-11-24 20:24 UTC · original
Applied @akimfomin's
WaiterRegistrationRAII guard inwait_frame_event(33195f846) so--waiters_andcv_.notify_all()still run beforelockunlocks if an injected clock throws fromnow_us()orwait(), and added both exception-unwind cases toruntime/test/frame_pacer_test.cpp.Verified after the final edit:
ctest --test-dir runtime/build/linux -R "^frame_pacer$" --output-on-failure: 1/1 passed (1.25 s)ctest --test-dir runtime/build/win -R "^frame_pacer$" --output-on-failure(Wine 11.22,clang-cl+xwin): 1/1 passed (6.56 s)AI-assisted: yes
@titoreinaldo on GitHub · 2026-11-24 20:44 UTC · original
The late-waiter regression assumes the asynchronous destructor has set
shutdown_after a 50 ms sleep. If that worker is delayed, the supposedly late waiter can register while the pacer is still running, so this test can fail even with the production guard working correctly. On exact head33195f846with GCC 14.2 on Linux, the unchanged fixture passed 3/3. Adding a 250 ms delay beforepacer.reset()in the test’s destructor lambda, with production code unchanged, made it fail 3/3 atEXPECT(late_ready). Could the fixture wait for an explicit shutdown acknowledgement rather than elapsed time, or use a live-object shutdown test seam? CPU-only; AI-assisted.@akimfomin on GitHub · 2026-11-24 21:04 UTC · original
I followed up on titoreinaldo’s fixture review at
33195f846. A deterministic fixture setsshutdown_under the mutex through a private friendFramePacerTestAccess, with the pacer alive throughout the call. It uses a counting clock and a synchronous zero-timeout wait. The separate existing test still covers destruction with already registered waiters.The essential assertions after
setup(pacer, 1)are:The standalone registered test passed 3/3 on
33195f846and 3/3 with the fixture on its parent0b65330e, on Windows with LLVM-MinGW Clang 23.1.6. In the isolated control with only the early check omitted, the test reported one clock read and exited on the expected assertion in all three runs. The only header change isfriend struct FramePacerTestAccess;. That helper acquirespacer.mutex_and setspacer.shutdown_ = true.PortBridge connected the reviewer’s finding with the existing waiter checks in PB-0020. AI-assisted with OpenAI Codex.
@madhyn on GitHub · 2026-11-24 21:20 UTC · original
@titoreinaldo Good catch — replaced the 50 ms sleep in
runtime/test/frame_pacer_test.cppwith an explicit condition-variable signal (HoldingClock::woke_from_cv) set right aftercv.wait(lock)returns in~FramePacer(), so the late-waiter check only runs onceshutdown_is set and the teardown wakeup has fired.Verified with
frame_pacer_test(g++ -std=c++20 -O2 -pthread):frame_pacer_test: all cases pass.AI-assisted: yes
@madhyn on GitHub · 2026-11-25 04:52 UTC · original
Rebased onto current
main(c7e82e26e), keeping theshutdown_guard ahead of thecurrent_origin_poll_fast path inwait_frame_event. Re-ranframe_pacer_teston both host Linux (g++ -std=c++20) and Windows cross-build (clang-cl /W4under Wine 11.22): all cases pass.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.