Skip to content

test(libkernel): give the positioned close test a real 300 us head start - #7669

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:test/positioned-close-head-start
Oct 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:test/positioned-close-head-start

Conversation

@thuanquang

Copy link
Copy Markdown
Contributor

What

guest_positioned_close (from #5938) gives the reader thread a 300 us head start before sceKernelClose, so that close lands while the 32 MiB sceKernelPread holds the positioned-transfer lock, and it requires at least one of its 60 rounds to overlap that way. On Windows the head start is not there: with the WinLibs toolchain, std::this_thread::sleep_for of anything below 1 ms returns at once. libstdc++ calls winpthreads' nanosleep, which converts the request to whole milliseconds, so 300 us becomes 0 and no wait happens (#1471 tracks the same thing for production code). Close then races the reader's first instructions in every round, and a run where all 60 rounds lose the race aborts with Positioned close check failed at line 69. That is the intermittent failure on main reported in #7532 (5 of 30 runs on a VM) and #6972.

The test now waits with PreciseSleepUs(300), the sub-millisecond wait production code uses since #1551.

Tested

Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main 48d61f53b.

  • The wait itself, a probe built with the same toolchain: sleep_for of 50, 300 and 999 us took 0.0 us (median of 200 calls each); 1000 us took 15.6 ms.
  • Rounds that overlap, from a local build that prints overlapped (not part of this PR), 30 runs each on an idle machine: main 56 to 60 of 60 per run (median 59), this change 60 of 60 in every run. With 24 busy threads both overlapped 60 of 60 in 10 runs each: on this machine a loaded main thread is slow to close, so the reader wins. The failing runs in fix(linux): enter the guest entry on a main stack at the console's address #7532 come from a host where close wins every round, which the real 300 us head start rules out.
  • guest_positioned_close passes with the change. I did not reproduce the abort on this machine: 45 runs of main under load passed.
  • python tools/check_conventions.py --base origin/main with this title and body passes.

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 (Claude Code)

🤖 Generated with Claude Code

With WinLibs, std::this_thread::sleep_for under 1 ms returns at once, so
close raced the reader in every round and a run where all 60 rounds lost
the race aborted. The test now waits with PreciseSleepUs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@karimibrahim07 karimibrahim07 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.

Windows check of head 2c75b6c5b, merged onto main ccbd40240 together with #7670, #7709, #7717 and #7680 (each merge clean, built once). Windows 11 Pro (26300), Ryzen 5 3600, WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON.

  • The wait, same toolchain (a standalone probe, not part of the PR, 100 calls each): std::this_thread::sleep_for of 50, 300 and 999 us took a median of 0.1 us (max 2.2 us), and 1000 us took 15.6 ms. That matches your numbers, so on main the test's 300 us head start isn't there. PreciseSleepUs(300) from PreciseWait.hpp, 200 calls on a loaded machine: 368 to 634 us, median 500 us. It always waits at least what was asked, so the head start is real now.
  • guest_positioned_close passes, --repeat until-fail:3.
  • Under load (8 copies at once plus 12 busy processes, 80 runs each), main's test and this one both passed. Like you, I didn't reproduce the #7532 abort on this machine. There was one abort, in this PR's binary, at line 35 (create_directory). That one comes from my harness: 8 copies in the same working directory, two of which picked the same steady_clock directory name. It isn't the overlap check, and ctest never runs two copies at once.

Code: PreciseSleepUs is what production code uses for sub-millisecond waits since #1551, and on Windows it takes the PreciseSleepHundredNanos path, not winpthreads' nanosleep. The include is the only other change. I have no requests.

AI-assisted: yes. I ran the build, the probe and the runs above.

@oneandonlydean oneandonlydean self-assigned this Oct 19, 2026
@oneandonlydean
oneandonlydean merged commit 42b7174 into boykopovar:main Oct 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants