test(libkernel): compare Windows thread CPU clocks with the process cycle time #23756
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23756"
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 ShootanoJumper on 2026-11-19T15:58:54Z.
What
guest_thread_cpu_clockfails intermittently on Windows onmain(ed1def4dd4). The failing check is the lower bound inDistinctReadingsWhileBurning:Since #23238, the thread CPU clocks read
QueryThreadCycleTimewhen the TSC is invariant.processstill comes from clock 2, though, which readsGetProcessTimes. That clock is sampled at the scheduler tick, and on a busy machine it over-counts by far more than two ticks. In a standalone program running the test's 200 ms burn 150 times on a Ryzen 7 5700X while a build was running:GetProcessTimesread ahead of wall time in 106 of 150 burns. The thread cycle clock never did.GetProcessTimesread up to 144 ms more than the thread cycle clock, and the test's check failed in 20–38 of 150 burns.On Windows with an invariant TSC, the test now takes the reference from
QueryProcessCycleTime, converted with the sameHostTscFrequency_nid_no_patch. Elsewhere it still uses clock 2. The tolerances are unchanged, and no product code changes.The second commit fixes the same mismatch in reverse, found by 4le22io.
ProcessClocksNameOnlyTheGuestburned 200 ms on the thread clock and then required the tick-sampled process clock to have advanced at least 150 ms, which it can fall short of under load. It now burns on the process clock itself.Changing clock 2 itself to cycle time doesn't work:
GuestFreebsdClocksrequires VIRTUAL ≤ PROF ≤ PROCESS_CPUTIME, and VIRTUAL (user time only) can only come fromGetProcessTimes.The
fix-libkernel-windows-cpu-clockdebt note says a thread clock and the process clocks "can differ by about one step". Under load I measured up to about 9 steps. I left the note alone because it's still a pending fragment.Tested
Windows 11 23H2 (22631), AMD Ryzen 7 5700X, WinLibs GCC 15.2.0 r7, Release,
mained1def4dd4, with a parallel build running on the machine:guest_thread_cpu_clockon mainUnder a 16-thread spinning load, each variant run alone 100 times: main 16 failures, first commit 2, both commits 0.
The full ctest run on
main(--parallel 6) also failedguest_thread_cpu_clockwith0xc0000409(abort()). Not tested on Linux or macOS, where the changed path doesn't apply (#ifdef _WIN32).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T16:11:22Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
41f216c425:tools/check_conventions.pypassed.guest_thread_cpu_clock_testsbuilt cleanly.guest_thread_cpu_clock):Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T16:17:48Z.
Review: COMMENTED
Reviewed — comments
The source file and author’s rationale were reviewed at head
41f216c425630a126ec6b688d7116e8f76a34467; the prepared diff contains no hunks, so I could not verify which lines changed.What I ran
Inspected the prepared description, commit list, manifest, and diff, then read
core/libs/tests/GuestThreadCpuClock.cppand targeted Windows clock implementation context through the repository reader. No tests or builds were run.Results
Negative control
Not run; this review did not execute tests.
Findings
Blocking
None identified in the source inspected.
Non-blocking
The changed-file manifest is empty and the prepared diff has no hunks, despite the description naming
core/libs/tests/GuestThreadCpuClock.cpp. The code’s changed lines and exact patch therefore could not be verified.Sources
Not verified
The patch itself and changed-line numbers were not available in the prepared diff or manifest. No builds, tests, or platform behavior were independently verified. Read:
description.md,commits.md,manifest.json,diff.patch,README.md,core/libs/tests/GuestThreadCpuClock.cpp, and targeted ranges incore/libs/prx/libkernel/Time/Time.cpp. Excluded from the bundle by rule:core/libs/tests/GuestThreadCpuClock.cpp(as stated in the description); its head text was read through the reader.To get this to a good state
Nothing is required. Optional: include the changed-file entry and patch hunks in the prepared review bundle so the changed lines can be checked.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T23:12:02Z.
Review: COMMENTED
Reviewed — no blocking findings
The prepared manifest and diff contain no changed-file entries, so this review could not verify the submitted code or justify a formal approval.
What I ran
core/libs/tests/GuestThreadCpuClock.cppat the pinned head to inspect the described test logic.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The changed-file inventory is empty and
diff.patchcontains no hunks, so the PR changes and their changed lines could not be inspected. The available repository reader showed the described test file at head, but that does not establish the PR's diff. The excluded-files inventory was not available in the bundle.To get this to a good state
Nothing is required.