runtime: wake blocked waiters in FramePacer::set_uncapped() and prevent timeout/clock overflow #1971

Open
github-bot wants to merge 1 commit from github-bot/gh-1971 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 17:04 UTC · original
IlyassRS3:fix/rt-frame-pacer-uncap-wake-and-overflow → main · +71 −5 · 2 files · 1 commits · open

Claim: RT-FRAME-PACER-UNCAP-WAKE-AND-OVERFLOW (claim comment #7168928060 on #1608).

Fixes (runtime/src/frame_pacer.h)

  1. Wake blocked waiters in FramePacer::set_uncapped(): previously set_uncapped() only flipped uncapped_ without calling cv_.notify_all(), leaving any thread already blocked inside wait_frame_event() (e.g. with infinite_timeout_ms on the vblank grid or latency throttle) stuck until the next vblank or timeout.
  2. Saturate give_up timeout arithmetic in wait_locked(): previously start + std::uint64_t(timeout_ms) * 1000 could wrap uint64_t when start is large, setting give_up < start and causing an immediate false timeout. Now saturates cleanly at no_deadline.
  3. Prevent signed int64_t / time_point overflow in SteadyFrameClock::wait(): previously start_ + std::chrono::microseconds(deadline_us) converted an unsigned uint64_t directly to signed std::chrono::microseconds::rep (int64_t), wrapping negative for deadline_us > INT64_MAX and spinning immediately. Now computes a relative remaining duration bounded to 24 hours per cv.wait_for() call (matching the FrameClock::wait contract where callers loop on wake).

Verification

  • AI-assisted: yes.
  • GPUs tested: none (host is macOS arm64; no retail files; 0 CMakeLists.txt changes).
  • Expanded runtime/test/frame_pacer_test.cpp with three new tests: set_uncapped(true) waking a thread blocked on infinite_timeout_ms, saturating timeout near UINT64_MAX, and SteadyFrameClock::wait() with a > INT64_MAX deadline blocking cleanly until notified.
  • Ran frame_pacer_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -pthread
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -pthread
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pthread
  • Ran python3 -I scripts/check_no_game_data.py on both files and python3 -I tests/test_text_write_line_endings.py: all passed.
**@⁠IlyassRS3** on GitHub · 2026-11-25 17:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1971) `IlyassRS3:fix/rt-frame-pacer-uncap-wake-and-overflow` → `main` · +71 −5 · 2 files · 1 commits · open Claim: `RT-FRAME-PACER-UNCAP-WAKE-AND-OVERFLOW` (claim comment `#7168928060` on #1608). ### Fixes (`runtime/src/frame_pacer.h`) 1. **Wake blocked waiters in `FramePacer::set_uncapped()`**: previously `set_uncapped()` only flipped `uncapped_` without calling `cv_.notify_all()`, leaving any thread already blocked inside `wait_frame_event()` (e.g. with `infinite_timeout_ms` on the vblank grid or latency throttle) stuck until the next vblank or timeout. 2. **Saturate `give_up` timeout arithmetic in `wait_locked()`**: previously `start + std::uint64_t(timeout_ms) * 1000` could wrap `uint64_t` when `start` is large, setting `give_up < start` and causing an immediate false timeout. Now saturates cleanly at `no_deadline`. 3. **Prevent signed `int64_t` / `time_point` overflow in `SteadyFrameClock::wait()`**: previously `start_ + std::chrono::microseconds(deadline_us)` converted an unsigned `uint64_t` directly to signed `std::chrono::microseconds::rep` (`int64_t`), wrapping negative for `deadline_us > INT64_MAX` and spinning immediately. Now computes a relative remaining duration bounded to 24 hours per `cv.wait_for()` call (matching the `FrameClock::wait` contract where callers loop on wake). ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (host is macOS arm64; no retail files; 0 `CMakeLists.txt` changes). - Expanded `runtime/test/frame_pacer_test.cpp` with three new tests: `set_uncapped(true)` waking a thread blocked on `infinite_timeout_ms`, saturating timeout near `UINT64_MAX`, and `SteadyFrameClock::wait()` with a `> INT64_MAX` deadline blocking cleanly until notified. - Ran `frame_pacer_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -pthread` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -pthread` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pthread` - Ran `python3 -I scripts/check_no_game_data.py` on both files and `python3 -I tests/test_text_write_line_endings.py`: all passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:13:10 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 17:04 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 17:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1971#pullrequestreview-6061727715) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request has changes conflicting with the target branch.
  • runtime/test/frame_pacer_test.cpp
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.
git fetch -u origin '+refs/pull/1971/head:github-bot/gh-1971'
git switch 'github-bot/gh-1971'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1971'
git switch 'github-bot/gh-1971'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1971'
git switch 'github-bot/gh-1971'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1971'
git switch 'main'
git merge --squash 'github-bot/gh-1971'
git switch 'main'
git merge --ff-only 'github-bot/gh-1971'
git switch 'main'
git merge 'github-bot/gh-1971'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.