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

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

@⁠titoreinaldo on GitHub · 2026-11-24 20:41 UTC · original
titoreinaldo:contrib/r2-pacer → main · +43 −1 · 2 files · 1 commits · open

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.

**@⁠titoreinaldo** on GitHub · 2026-11-24 20:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1237) `titoreinaldo:contrib/r2-pacer` → `main` · +43 −1 · 2 files · 1 commits · open Claimed in the coordination issue as: RT-PACER-SUSPEND-EPOCH [Claim in #14](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:44:01 +00:00
Author
Owner

@⁠Snooozs on GitHub · 2026-11-24 20:58 UTC · original

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).

**@⁠Snooozs** on GitHub · 2026-11-24 20:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1237#issuecomment-7144296051) 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).
Author
Owner

@⁠titoreinaldo on GitHub · 2026-11-25 00:16 UTC · original

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.

**@⁠titoreinaldo** on GitHub · 2026-11-25 00:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1237#issuecomment-7148334908) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1237/head:github-bot/gh-1237'
git switch 'github-bot/gh-1237'

Merge

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