Windows: the first std::thread after libc.prx loads can cost its creator tens of ms of CPU; nkwebkit_wtfcputime fails on it #23267
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by videogamer10293 on 2026-11-18T21:33:29Z.
What happens
On Windows, with
libc.prxloaded, a process's firststd::threadcan cost the creating thread up to 34 ms of CPU time in a small probe and about 47 ms in the test process, which makesnkwebkit_wtfcputimefail under load withWTF::CPUTime check failed at line 111.Title, test or build step
ctest
nkwebkit_wtfcputime; also a standalone program, below.AnyPS5 commit
main158e669f66, no pull requests on top. The tree carries an uncommitted_putenv_sguard inUploadCacheReadOnlyFlush.cpp, without whichmaindoes not build on Windows (#19899, #22373 and #22634 fix it).mainhas moved since, to866864a5bc; the newer commits changelibc'sMathExact.cpp,libSceAudioOut,libSceFios2,libSceRtc,libSceSysmodule, tests and tools. This was not run again on them.System
Windows 10 Pro 10.0.19045, AMD Ryzen 5 7600X (12 logical CPUs), WinLibs GCC 15.2.0 r7, Release. GPU: not involved.
Host report
Not run; no title is involved.
Steps to reproduce
burner.cpp(below) asburner 12 3600: 12 threads in busy loops.ctest --test-dir build -R "^nkwebkit_wtfcputime$"20 times.Failing runs abort within about 1 s with exit code
0xc0000409.To see the cost outside the test, build
create_probe.cpp(below) withg++ -O2 -std=c++20 -static. Run it with no argument or with a library name, withbuild/core/libs/libs/unpatchedand the WinLibsbinfolder onPATH. It loads the library, then creates twostd::threads in turn and reads the creating thread'sQueryThreadCycleTime, itsGetThreadTimeskernel and user times and the wall time around each constructor.Log
What was checked
Line 111 is
Require(after - before < 0.03);inTestGuestClockCountsOnlyThisThread, added by #20139. It checks that the main thread's own CPU time stays under 30 ms while it creates the test's firststd::thread, joins it and sleeps 50 ms.The test on
158e669f66, 20 runs each:std::threadconstructor took 42.7 to 46.9 ms (44.3 to 46.3 ms in the 9 of the first run);joinand the 50 ms sleep took under 0.01 ms. In 8 of the 9 passing runs the constructor took about 0.05 ms. One passed at 43.2 ms; I did not read the test's clock there. Onmainthat clock moves in 15.6 ms steps (#23238), which may be why.std::thread([] {}).join();added beforebefore, and the 12 busy threads: 0 of 20 failed, and the measured constructor took 0.037 to 0.046 ms.mainin myctest -j 8runs for #23238 on oldermaincommits, without the busy threads but with 8 tests running at once (Tested). CI runs ctest in parallel too (CONTRIBUTING).create_probe.cpp, 30 runs per row, CPU time of the firststd::threadconstructor to the creating thread. The ms values divide the cycle count by the TSC rate the program measures over 20 ms, so they assume the count runs at that rate.libc.prxlibkernel.prxlibc.prxlibkernel.prxlibc.prxdoes not importlibkernel.prx;libkernel.prxloadslibc.prx. Loadingshell32.dll,iphlpapi.dll,advapi32.dll,libstdc++-6.dll,libwinpthread-1.dllorlibgcc_s_seh-1.dllalone, the other DLLslibc.prximports apart fromKERNEL32.dlland theapi-ms-win-crtset, does not reproduce it: at most 0.088 ms, with and without the busy threads.GetThreadTimes, which moves in 15.6 ms steps, showed kernel time and none showed user time.libc.prx; there the slow constructor took about 45 ms.Not found: what
libc.prxdoes at load that makes the first thread expensive. No kernel stack trace was taken. Not checked: other CPUs, Windows 11, Linux, macOS, and whether a title shows the cost.Creating a thread before
before, as above, made the test pass in 20 of 20 runs, but it leaves the start-up cost inlibc.prxunexplained. I can open that test change as a pull request if maintainers want it.create_probe.cpp
burner.cpp
AI-assisted: yes. Claude Code found this while checking why
nkwebkit_wtfcputimefailed during the tests for #23238, wrote the probe programs and the local test prints, ran them, and drafted this issue.