fix(libkernel): count process time from library load #3368
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3368"
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 reyani-dev on 2026-10-11T09:13:52Z.
What
Carries @Zurisen's fix from #3366 (the author is under the intake threshold). The commit is theirs, unchanged (
5ac54a32).sceKernelGetProcessTimeandsceKernelGetProcessTimeCountermeasured from a start thatGetStartNanoscaptures in a function-local static, that is, on their first call. So the first reading was about 0 however long the process had run. It was exactly 0 when the capture and the read fell in the same host clock tick, which is what makesguest_ampr_markersfail intermittently atGuestAmpr.cpp:381(time=0). On the console these count from process start.Time.cppnow captures the start when libkernel loads (static const std::uint64_t g_processStart = GetStartNanos();). The function-local static stays, so a call during another library's static initialization still gets a valid start.GuestProcessTime.cppsleeps 50 ms before its first call and requires the first reading to include it, scaled byAPS5_TIME_SCALEfor the_scaledvariants.Closes #3366.
Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, onmainac2c5c08:main, all fourguest_process_time*tests fail. With the fix they pass 5/5 (--repeat until-fail:5).ctest -E "^agc_|video_out": 441/441. It builds without warnings.guest_ampr_markersfailed twice for me today in full parallel runs onmain(0xc0000409) and passed when run alone, which matches the timing-dependenttime=0the issue describes.check_conventions.pypasses, andpr_overlap.pyreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:19:45Z.
Checked on Linux: the PR merged onto main builds,
guest_process_time*(4 tests) pass, and all four fail without theTime.cppchange, so they pin the fix. The function-local static inGetStartNanosis kept, so early calls during static init stay valid. Merging.Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T09:39:23Z.
One flaky failure of the new assertion on Windows (Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7,
main09bd4aa1+ #1482): in a fullctest --parallel 4run,guest_process_time_counteraborted withand passed 23/23 on reruns (3 serial, 20 serial). So the first counter can read as zero elapsed on a loaded machine; a check that allows zero, or a longer wait before the first call, would make it deterministic.
AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T09:52:57Z.
Thanks @orishamir. Reproduced here under
-j8(two of the four tests failed within 60 rounds).sleep_forcan return a little early against the QPC the guest clock reads. #3414 makes the test wait untilsteady_clockshows 50 ms; with it, all four pass 60 rounds under-j8.