frame_pacer: cancel a wait that spans suspend and re-registration #1237

Merged
titoreinaldo merged 1 commit from upstream-pr/1237 into main 2026-11-28 20:19:06 +00:00
titoreinaldo commented 2026-11-24 20:41:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by titoreinaldo on 2026-11-24T20:41:09Z.


Claimed in the coordination issue as: RT-PACER-SUSPEND-EPOCH
Claim in #14

What and why

A wait could enter before suspend, wake after resume and re-registration, then consume the first tick of the new registration. A pre-suspend origin wait could even issue the resumed frame’s token. The pacer now records each suspend under its existing mutex. When a waiter regains the lock it can tell that its registration ended, even if the new one is already armed.

The regression drives that ordering through the existing injected clock. It checks origin, vblank and flip events, verifies the old wait returns invalid_state without changing the caller’s token, and verifies a fresh wait can still take the first resumed tick. This concerns the project’s modeled pacing contract. #1042 touches the same header for a different wakeup case. The two commits merge cleanly.

Tested

  • Built and ran the existing native frame_pacer_test first. It passed. Adding the new ordering against the pre-fix header failed at the expected old-wait assertion.
  • After the fix, the complete standalone test passed eight consecutive times on Windows. The registered Release CMake target also passed ten consecutive runs with ctest --test-dir <build> -R frame_pacer --repeat until-fail:10 --output-on-failure.
  • On the shared base 58be9cdf, 6,168 translator tests in 470 files had zero failing files. Verified a clean merge with main at 705ea091 and the head of #1042.

GPUs tested: CPU-only frame pacing, Windows 11 Pro 26H2 build 26300.9974, LLVM-MinGW 23.1.6.

AI-assisted: yes, OpenAI Codex. Synthetic clock and inputs.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479979121 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1237). Originally posted by [titoreinaldo](https://github.com/titoreinaldo) on 2026-11-24T20:41:09Z. --- Claimed in the coordination issue as: RT-PACER-SUSPEND-EPOCH [Claim in #14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143476751) ### What and why A wait could enter before suspend, wake after resume and re-registration, then consume the first tick of the new registration. A pre-suspend origin wait could even issue the resumed frame’s token. The pacer now records each suspend under its existing mutex. When a waiter regains the lock it can tell that its registration ended, even if the new one is already armed. The regression drives that ordering through the existing injected clock. It checks origin, vblank and flip events, verifies the old wait returns `invalid_state` without changing the caller’s token, and verifies a fresh wait can still take the first resumed tick. This concerns the project’s modeled pacing contract. #1042 touches the same header for a different wakeup case. The two commits merge cleanly. ### Tested - Built and ran the existing native `frame_pacer_test` first. It passed. Adding the new ordering against the pre-fix header failed at the expected old-wait assertion. - After the fix, the complete standalone test passed eight consecutive times on Windows. The registered Release CMake target also passed ten consecutive runs with `ctest --test-dir <build> -R frame_pacer --repeat until-fail:10 --output-on-failure`. - On the shared base `58be9cdf`, 6,168 translator tests in 470 files had zero failing files. Verified a clean merge with `main` at `705ea091` and the head of #1042. GPUs tested: CPU-only frame pacing, Windows 11 Pro 26H2 build 26300.9974, LLVM-MinGW 23.1.6. AI-assisted: yes, OpenAI Codex. Synthetic clock and inputs.
Snooozs commented 2026-11-24 20:58:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-24T20:58:02Z.


Read the whole diff and tested 9a5ba38d8 merged on main 66d4f5aa3 (clean), Windows 10 Pro 19045, VS 2022 RelWithDebInfo (MSVC), CPU only:

  • the new test with main's frame_pacer.h: 3 of 3 runs fail at line 389 (the old wait's invalid_state)
  • with the PR: 10 of 10 runs pass

The generation is read and written only under the pacer mutex, and it is taken at the start of wait_locked, so a wait entered after resume sees the new value. Nothing to change from my side. The retail title was not run.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144296051 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1237#issuecomment-7144296051). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-24T20:58:02Z. --- Read the whole diff and tested `9a5ba38d8` merged on main `66d4f5aa3` (clean), Windows 10 Pro 19045, VS 2022 RelWithDebInfo (MSVC), CPU only: - the new test with main's `frame_pacer.h`: 3 of 3 runs fail at line 389 (the old wait's `invalid_state`) - with the PR: 10 of 10 runs pass The generation is read and written only under the pacer mutex, and it is taken at the start of `wait_locked`, so a wait entered after `resume` sees the new value. Nothing to change from my side. The retail title was not run. AI-assisted (Claude Code, Claude Opus 5.5).
titoreinaldo commented 2026-11-25 00:16:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by titoreinaldo on 2026-11-25T00:16:21Z.


Linux cross-check on x86-64 with g++ 14.2 (-O2 -std=c++20 -pthread, CPU-only). I merged 9a5ba38d locally with main 1154976d without conflicts and built the standalone frame_pacer_test from the merged tree. The regression with the same test and the main-only header failed 4/4 at line 389 (pre-suspend wait returned something other than invalid_state); the patched tree passed 4/4. No game files; AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7148334908 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1237#issuecomment-7148334908). Originally posted by [titoreinaldo](https://github.com/titoreinaldo) on 2026-11-25T00:16:21Z. --- Linux cross-check on x86-64 with g++ 14.2 (`-O2 -std=c++20 -pthread`, CPU-only). I merged `9a5ba38d` locally with main `1154976d` without conflicts and built the standalone `frame_pacer_test` from the merged tree. The regression with the same test and the main-only header failed 4/4 at line 389 (pre-suspend wait returned something other than `invalid_state`); the patched tree passed 4/4. No game files; AI-assisted.
MoonEyes commented 2026-11-28 20:19:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:19:03Z.


Red/green: On main frame_pacer_test fails at line 536 (a wait that spans suspend and re-registration does not return invalid_state), and with the PR ctest -R ^frame_pacer$ passes on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245197096 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1237#issuecomment-7245197096). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T20:19:03Z. --- Red/green: On main frame_pacer_test fails at line 536 (a wait that spans suspend and re-registration does not return invalid_state), and with the PR ctest -R ^frame_pacer$ passes on Windows 11 at OreoFR's (RTX 4070). Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:48:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:48:00Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 9a5ba38d8; green run in a merge package of 2 PRs, no new ctest failure vs main
  • Test: ctest -R ^frame_pacer$
  • Red on main: failure line 536 (wait_frame_event(...) == pacer_hr::invalid_state)
  • Green with the PR: OK
  • Verdict: READY (frame_pacer.h is also touched by #1263 and #1198)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246281703 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1237#issuecomment-7246281703). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:48:00Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `9a5ba38d8`; green run in a merge package of 2 PRs, no new ctest failure vs main - Test: `ctest -R ^frame_pacer$` - Red on main: failure line 536 (wait_frame_event(...) == pacer_hr::invalid_state) - Green with the PR: OK - Verdict: READY (frame_pacer.h is also touched by #1263 and #1198) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1237
No description provided.