Skip to content

fix(fontft): preserve format query lock backoff on Windows - #14225

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
harry-z-kang:codex/fix-fontft-windows-backoff
Nov 6, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
harry-z-kang:codex/fix-fontft-windows-backoff

Conversation

@harry-z-kang

@harry-z-kang harry-z-kang commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Restore the Windows backoff in FontFt::SupportFormats using the existing PreciseSleepUs(30) helper under #ifdef _WIN32. WinLibs' sub-millisecond std::this_thread::sleep_for returns immediately, so a format query spins while another thread holds the font-library lock. The helper include is also Windows-only; Linux/macOS retain the original std::this_thread::sleep_for(30us), avoiding the precise helper's POSIX spin tail and Linux timer-slack changes. Refs #1471.

Add guest_font_ft_backoff: hold the library lock while a real sceFontFtSupportTrueType query runs on another thread, verify it remains blocked, release it, then check the result, lock restoration and library cleanup. Enforce the existing timed-wait tests' 40% calling-thread CPU budget on Windows and POSIX, using GetThreadTimes or host clock_gettime(CLOCK_THREAD_CPUTIME_ID) respectively. The timing test runs serially on every platform.

Tested

Rebased 2026-11-05: head c8855b8027, independently based on main 1be4c77a8d. git range-diff confirms the topic commits are unchanged by the rebase.

Windows 11 10.0.26300, AMD Ryzen 7 9800X3D, Release, BUILD_TESTING=ON.

Toolchain Build Focused CTests
WinLibs GCC 15.2.0 UCRT POSIX SEH r7 Selected test targets and required runtime libraries 9/9 passed
MSYS2 UCRT64 GCC 16.2.0 Selected test targets and required runtime libraries 9/9 passed

The focused set covers guest_font_ft_backoff, guest_font, guest_font_scissor, guest_font_renderer_lifecycle, guest_system_font, guest_font_metrics, guest_font_style_information, guest_font_outline_profile and guest_font_rebind_renderer.

Original negative control: on main cc26ab4438 with only the new test and registration added, WinLibs fails the CPU-budget assertion (101.6% reported over the held-lock interval). MSYS2 passes that control. With the production fix, the same test passes on both toolchains and reports 0.0% calling-thread CPU on both toolchains in the final runs. These are synthetic lock-wait checks, with no title or frame-rate measurement.

Additional POSIX validation on Ubuntu 24.04 WSL2 / GCC 13.3.0: the updated GuestFontFtBackoff.cpp passes -fsyntax-only. An isolated harness reusing that file's actual ThreadCpuNanos and RequireCpuBudget functions passes a sleeping control (6.6% CPU) and rejects a busy-spin negative control (100.0%). This validates the new CPU counter and assertion; the full Linux font CTest was not run. The WSL full-build prerequisites lack XRandR development headers.

tools/check_conventions.py --base origin/main, git diff --check and the public-header declaration audit pass. The original 2026-10-31 scan, tools/pr_overlap.py --branch codex/fix-fontft-windows-backoff, found no overlap across 1,695 open PRs. Both fixes are based independently on main; this PR does not require the separate ksem fix.

MSYS2 uses the existing local CMAKE_SKIP_INSTALL_RULES=ON workaround for #12994; installation was not tested. macOS runtime and titles were not run; Linux validation is limited to the compile check and CPU-counter controls above.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

At head 1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e, the production change restores a real 30 μs lock backoff using the shared precise-wait helper, and the added test covers contention, result, lock restoration, and cleanup.

What I ran

Reviewed head 1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e against base cae3edaf11db8c6c1694c2d772d07c079755a71f (main); the current-base preview merged cleanly. Environment: Linux x86_64, glibc 2.36, Python 3.11.2, GCC 12.2.0.

git diff --check cae3edaf11db8c6c1694c2d772d07c079755a71f...1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e
python3 tools/check_conventions.py --base cae3edaf11db8c6c1694c2d772d07c079755a71f --head 1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e --title 'fix(fontft): preserve format query lock backoff on Windows' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14225-1bbd927c4bbc/pr-body.md
python3 tools/pr_stack_check.py 14225 --repo boykopovar/AnyPS5
mkdir -p /tmp/anyps5-pr14225-quality/core/libs/prx/libSceFontFt /tmp/anyps5-pr14225-quality/core/libs/tests
git show 1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e:core/libs/prx/libSceFontFt/CMakeLists.txt > /tmp/anyps5-pr14225-quality/core/libs/prx/libSceFontFt/CMakeLists.txt
git show 1bbd927c4bbc678415fe8b7bebd0d8af2cacea2e:core/libs/tests/GuestFontFtBackoff.cpp > /tmp/anyps5-pr14225-quality/core/libs/tests/GuestFontFtBackoff.cpp
python3 tools/pr_test_quality.py --root /tmp/anyps5-pr14225-quality core/libs/tests/GuestFontFtBackoff.cpp
gh pr checks 14225 -R boykopovar/AnyPS5

The test-quality heuristic flagged a likely registration issue because the CMake source path uses ${LIBS_INCLUDE_DIR}; I inspected the exact CMake file and confirmed that it adds the test executable and registers guest_font_ft_backoff. I did not build locally.

Results

Check Result
Diff check Passed; no whitespace errors.
Conventions and PR template Passed.
Current-base merge preview Clean; no declared dependencies.
CMake test registration Confirmed by source inspection; the CTest is registered as guest_font_ft_backoff.
Test-quality heuristic One false-positive registration warning due to the variable-expanded CMake path; no assertion-quality warning.
Hosted CI Eligibility and intake passed. Windows, conventions, labels, library-portability, and report were pending; Linux, register-context, relinker, relinker-asan, and write-watch were skipped at the final refresh.
Windows test matrix Author reports 9/9 focused CTests on WinLibs GCC 15.2.0 and MSYS2 UCRT64 GCC 16.2.0; the new test passes on both. Not run locally.
Unedited output for local checks

Diff check produced no output and exited successfully.

All conventions checks passed.
core/libs/tests/GuestFontFtBackoff.cpp:1: possible-unregistered-cpp-test: Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage.
Heuristic findings require manual interpretation.

Hosted checks:

linux	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708461897
register-context	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708461655
relinker	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708461329
relinker-asan	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708461730
write-watch	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708462332
windows	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124708460486
eligibility	pass	6s	https://github.com/boykopovar/AnyPS5/actions/runs/41258750930/job/124707437656
intake	pass	20s	https://github.com/boykopovar/AnyPS5/actions/runs/41258750895/job/124707438502
conventions	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750893/job/124707438438
labels	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258751013/job/124707438785
library-portability	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750947/job/124707437459
report	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41258750956/job/124707437547

Negative control

Assertion Change to code under test Result
The new regression test distinguishes the WinLibs busy-spin behavior Author reports running the test against baseline with only the test and registration added; production change absent. WinLibs failed the CPU-budget assertion at 101.6%; MSYS2 passed. Author-reported, not independently rerun.

Findings

Blocking

None found in the reviewed diff.

Non-blocking

The Windows builds, focused tests, and negative control are author-reported; I did not independently run them or test on a Windows host. The source change is small and calls the existing helper, which uses a Windows high-resolution waitable timer when available and falls back to std::this_thread::sleep_for if timer waiting fails.

Sources

Not verified

  • No local build or C++ tests; the initial review workflow excludes builds.
  • Windows behavior was supported by the author's reported runs but not independently reproduced here.
  • Linux/macOS title behavior was not tested; the PR reports those environments were not run.
  • Hosted CI had not completed at the final refresh.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

The Windows part looks right: PreciseSleepUs uses the high-resolution waitable timer there, so the query really sleeps.

The change also applies off Windows, though, and there it goes the other way. In PreciseWait.hpp, a 30 µs PreciseSleepUs on Linux sleeps about 15 µs and then busy-spins the remaining 15 µs (it also sets the calling thread's timer slack to 1 ns). If setting the slack fails, or on macOS, where the spin tail is 100 µs, it spins the whole 30 µs. Before, std::this_thread::sleep_for(30us) was a plain nanosleep that gave up the core. So under lock contention, Linux and macOS would use more CPU than they do now, and the new test's CPU check only runs on Windows.

Could you use PreciseSleepUs(30) only under #ifdef _WIN32 and keep sleep_for on the other platforms? Extending the CPU check to POSIX (clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...)) would guard that side too.

@harry-z-kang

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Addressed in d9a0fdfde7.

Both the helper include and PreciseSleepUs(30) call are now under _WIN32. Linux/macOS keep their original standard-library sleep.

The regression test now uses clock_gettime(CLOCK_THREAD_CPUTIME_ID) on POSIX and enforces the same 40% CPU budget there. It runs serially on all platforms and uses a plain standard-library sleep to hold the test lock.

Full libs builds and all nine focused font CTests pass on both WinLibs GCC 15.2 and MSYS2 GCC 16.2. Ubuntu WSL/GCC 13.3 compile-checks the updated POSIX test; an isolated harness using its actual CPU-counter/budget functions passes the sleeping control (6.8%) and rejects the busy-spin control (100.0%). Full Linux font CTests and macOS runtime validation remain unrun.

@bunbeans2-arch

Copy link
Copy Markdown
Contributor

A Windows run with GCC 16: Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0, Release, this PR (d9a0fdfde7) merged into main ba8dcc6.

  • ✅ With this PR: guest_font_ft_backoff passed 5 of 5.
  • ❌ Same tree with only Driver.cpp put back to main (this PR's test kept): it failed in 5 of 5 runs at line 51, with the format-query calling thread at 80.9% to 101.6% CPU against the test's limit of 40%.
  • main ba8dcc6 alone: this test does not exist there yet, so there was no main run.

Looks good on Windows 👍

AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@harry-z-kang
harry-z-kang force-pushed the codex/fix-fontft-windows-backoff branch from d9a0fdf to c8855b8 Compare November 6, 2026 06:04
@oneandonlydean
oneandonlydean merged commit ec53c30 into boykopovar:main Nov 6, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants