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

Open
opened 2026-11-26 21:19:36 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1971
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-frame-pacer-uncap-wake-and-overflow


📝 Commits (1)

  • 943e37c runtime: wake blocked waiters on set_uncapped() and avoid timeout/clock overflow in frame_pacer

📊 Changes

2 files changed (+71 additions, -5 deletions)

View changed files

📝 runtime/src/frame_pacer.h (+22 -5)
📝 runtime/test/frame_pacer_test.cpp (+49 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1971 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-frame-pacer-uncap-wake-and-overflow` --- ### 📝 Commits (1) - [`943e37c`](https://github.com/ubiquitarianism/leonida/commit/943e37c90b27a07424c66ab9be4a3c10741bc5ac) runtime: wake blocked waiters on set_uncapped() and avoid timeout/clock overflow in frame_pacer ### 📊 Changes **2 files changed** (+71 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/frame_pacer.h` (+22 -5) 📝 `runtime/test/frame_pacer_test.cpp` (+49 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#1978
No description provided.