fix(libc): count clock() as the process time, like the console #9677
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9677"
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 JJenkx on 2026-10-22T07:49:18Z.
What
clock()now returnssceKernelGetProcessTime(), the microseconds since the process started. Onmainit returned the host process CPU time (GetProcessTimeson Windows,std::clockelsewhere).The
libc.prxthat titles ship implementsclock(QZP6I9ZZxpE) as an 11-byte tail call tosceKernelGetProcessTime(4J2sUJmuHZQ), through the PLT. This was read from disassembly of the decrypted copies of PPSA13934 (0x6ba20), PPSA07923 (0x71790) and PPSA05916 (0x73ba0), not measured on a console. All three resolve the same PLT slot 0x50 to that NID.CPU time is a different clock:
guest_process_timeonmain,clock()is 0 after about 60 ms of process time.So a title that times frames or animations with
clock()saw time pass at the wrong rate.clockis imported by PPSA13934, PPSA05916, PPSA20423 and PPSA33655 among the titles converted here.How
libc can't link libkernel, because libkernel already links libc. Instead, libkernel installs
sceKernelGetProcessTimeas libc's process time source in a static initialiser, throughLibcSetProcessTimeSource_nid_no_patch, which followsLibcSetEndFlush_nid_no_patch.clock()returns that source's value, so it also followsAPS5_TIME_SCALE. Until a source is installed, as in a test that links only libc,clock()counts host monotonic time from the load of libc. Thelibc.mdentry records that path and the disassembly.Tested
Current-main integration — 2026-11-09 UTC. Head
c6d755c1f9c68cd2edd88dada51cec3e5e509ad2preserves public head6ac7ce9e401899294b07fd56eea0ec72a6fb0980and integrates pinned main7259cce11195f360698772da8c0b3af756bf7c8f. Conflict resolution retains both the topic and main's newer source/test/debt changes; maintainer commits and attribution remain intact.Linux x86-64, GCC 16.2.1, Ninja Release: actual libc/libkernel and focused fixture owners rebuilt. 30/30 CPU executions pass, zero skips (10 groups × three repetitions):
guest_process_time,guest_process_time_counter,guest_process_time_scaled,guest_process_time_counter_scaled,guest_process_time_tsc,guest_process_time_tsc_scaled,guest_process_time_rdtsc,guest_process_time_rdtsc_scaled,guest_freebsd_clocks,guest_kernel_sys.public_headers, conventions and whitespace checks pass. The matching plain-main control passed 102 selected CPU executions and its header audit. CPU fixtures execute unpatched production libraries; this is not a full SDK or patched-title runtime qualification.No new Windows/macOS, console, GPU, title or performance result is claimed. Source checks preserve the existing production topic; historical reports below retain their original pins.
Build/test logs, exact heads, source/ancestry checks and provider pins, SHA-256
52727be6594b9c15bf9a5535fef374b985e9526aabe5f3ef5cf5857dfeeb1a0d. The public archive and all 178 manifest files were download/hash verified.Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head
d72983464a9548932465743e5f485e4537ae64aeon tested main3fea2a937ba9fbab2f06c51691fe0c5763659aa3. The topic production/test edits and current main's includes and checked-pointer behavior are preserved.Linux Release focused rebuild: Four process-time registrations, FreeBSD clocks, kernel sys and public headers each pass three times: 21 passes, zero skips. Conventions, whitespace and merge checks pass. Every refreshed head's submodule pointers match the pinned main; the private dependency checkouts used for the gates are aligned. No new negative-control, Windows, console, title, GPU, full-suite or performance run is claimed. Earlier measurements below retain their original exact pins. Fulfilled merge-order dependencies have been cleared from the checklist; open prerequisites remain.
Exact source/dependency pins, patch-preservation and gitlink proofs, builds, verbose tests, JUnit and lease-push receipts. SHA-256:
702c4110ee9dde421c2dd5e057ed53a2df05e0cf7b01f67e8fb9cb779e332f7c; downloaded copy verified.Conflict refresh, 2026-10-27 UTC: exact head
a53a9ce4517f360c31a4fd14e7e9333dc8c15bf8on tested main74acfad65b3f0fd4eab653f3a3989d298fba1157. Preserved current main's API/header layout and pointer-checking code; removed a stale duplicate clock declaration from the test in favor of the API header. The branch remains one clock-policy topic and contains no private #11402/#11042 integration commits. The declared #11402 merge-order dependency remains.Linux Release focused libraries/executables rebuilt. Seven groups (four process-time registrations, FreeBSD clocks, kernel sys, public headers) each pass three times: 21 initial and 21 restored passes. A clock-function-only main-production control fails the normal and scaled process-time fixtures while retaining the hook needed to link the test; restored libc is byte-identical. Zero skips; conventions and whitespace pass. This is focused Linux evidence, without new Windows, console, title, GPU or full-suite validation. Earlier measurements retain their original exact pins.
Source/dependency pins, production preservation, verbose build/test/control/restoration logs, JUnit, hashes and lease-push receipts. SHA-256:
594bf1dd3a57728c23dd0752926f501f34a8be8e31c8d924e6bec3723d029a82; downloaded copy verified.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 r7 (UCRT), Ninja, Release,
-DBUILD_TESTING=ON, onmaind6eafa54d0.guest_process_timeandguest_process_time_scaled(APS5_TIME_SCALE=0.5) now also requireclock()to fall between twosceKernelGetProcessTime()calls made around it.mainboth fail withclock() is not the process time. A local print showed the process time at 60135..60137 µs withclock()0, and at 25616..25617 µs withclock()0 when scaled.guest_process_time*tests pass in three runs out of three.VK_ICD_FILENAMESpointed at nothing),ctest -j16 --timeout 120: 1887 of 1890 pass. The failures areguest_raise_in_system_callandguest_raise_in_host_code, which time out onmainhere too (#9610), andpatched_libraries, which passes once the toolchain'sbinis onPATH, as onmain(outside itLoadLibraryExpicks up anotherlibstdc++).python tools/check_conventions.py --base origin/main: passes.tools/pr_overlap.py --branch: no direct overlap. #4627, #5021, #6879 and #7201 share files but don't touchclock.main7e2ba73e4):guest_process_time*andpatched_librariespass 5/5. With the oldclock()the two new checks abort; the 26guest_*time*/*clock*tests andguest_kqueuepass.Current-main refresh (2026-10-24)
Head
15ba05f6e0c0198205b4c31f632c1ae8398513admerges main6cd36e651724f42b7b564544640187948e80c8cbinto the existing branch. Onlydocs/dev/debt/libc.mdconflicted: the resolution keeps the exact latest-main file, including its newly measured random-generator entry, plus this PR's single clock entry. The production and test added/removed lines are identical to the prior topic; main's TSC-frequency/conversion checks and this PR's clock bracketing remain together.Fresh Linux 7.2.9 / Ryzen 9 7950X / GCC 16.2.1 Release: rebuilt the relevant libc/libkernel libraries and
guest_process_time_tests. The normal process-time, counter, scaled-time and scaled-counter tests each pass three consecutive executions (12/12, no skips). Conventions and topic whitespace checks pass. This is a focused Linux refresh; earlier negative-control and Windows results remain at their original pins. No fresh Windows/macOS, full application, title or performance result is claimed. Windows remains user-paused.Fresh build/test logs, JUnit, exact topic patch and scope review, SHA256
8f1769edab604b7a740ad296f2346138f385ee984b6511d13f84edaa948d1be0.Integration with #6044
At #6044 head
5fa62e5960372f7caf378ce5e13912f1e0d3d514,GuestProcessTime.cppmoves fromcore/libs/tests/tocore/libs/tests/time/. This change does not require that reorganization; there is no dependency on #6044.If #6044 lands first, I will rebase this PR, apply its libc include/declaration and bounded
clock()assertions at the new path, and rerun all fourguest_process_time*tests pluspatched_libraries. If this PR lands first, the subsequent #6044 rebase must carry those assertions into the moved file. Keep the target's libc linkage and the normal/scaled test registrations in either order.The moved file at that #6044 head also predates current main
4777caca343bf09a3fe245830acd9e9f433e8e18: it still assumes a fixed counter frequency. Conflict resolution must retain main'ssceKernelGetProcessTimeCounterFrequency()/TSC-frequency check, frequency-based conversion and monotonic counter assertion as well as this PR's newclock()check. Accepting either older file wholesale would lose coverage. This is a source comparison and integration plan; no combined #6044 build/test is claimed.Integration with #11402
Agreed order: #11402 first, then this PR rebases while retaining both
GuestArena.hpp(checked reads) andGuestTime.hpp(process-time source). The exact-head conflict is in that include block. Keep #11402's checked copies: unreadable pointers returnEFAULTbefore value validation; readable invalid requests returnEINVAL. #11042 separately replaces the validclock_settimedescriptive throw withNotImplemented_nid_no_patch, after those checks. This PR's current head does not itself change that tail. Private integration previews preserve all three topics. Linux GCC16.2.1 Release builds of the exact two-topic merge1284d9706f3cf2d3516dc7ff960a02cf7ad1a3faand three-topic merge0553b4cae9c7b29f48be88e389fba338da0990d5each pass all fourguest_process_time*registrations plusguest_freebsd_clocksandguest_kernel_systhree times (18 passes per preview, no skips). These contain main4b1a9a3b2f51efe6fcde289ba0788f3cfffe2f32; they verify integration at those pins, without claiming a newest-main rebase of this public branch.Current rebase qualification (2026-10-28)
Refreshed onto
main2227f1366188cda5699dd20e2e756a18006a5d4bas6ac7ce9e401899294b07fd56eea0ec72a6fb0980. The topic production and test additions/removals are preserved; the include/debt conflicts retain both sides. #11402 is now merged: its checked time-pointer reads, EFAULT-before-EINVAL validation and valid-request diagnostic guard are retained unchanged; this topic no longer changesclock_settime.Linux Release: libc/libkernel and three clock test executables build. Seven focused groups, including scaled and counter clock variants, FreeBSD clock validation, kernel syscalls and public headers, pass three repetitions (21 executions), zero skips. Conventions and whitespace pass. Existing Windows/reference evidence remains pinned to its original heads; no new title/GPU/performance result. AI-assisted: yes.
Source-preservation proofs, builds, controls, logs and JUnit, SHA-256
17fa7113ae7732ef2704bcb76e11ef6528c6fd74684037c27fb1a5b516ce9988. Existing historical platform and title measurements retain their original source pins.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repository7f02cb180227; present in audited main3fea2a937ba)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:52:49Z.
Review: APPROVED
Reviewed the
clock()implementation, linkage path, test addition, and reported CI/test results. The change follows the console libc behavior documented from three title library disassemblies, routes through the existing process-time source, and adds a bounded regression assertion in both normal and scaled process-time cases. I found no conflicting behavior in the flagged clock-related PRs: #9447 adds a differentsteady_clock::now_v1_compatexport; #9501 handles process CPU clock IDs; #4627 only adjusts Appletm_zone; #5021/#6879/#7201 concern unrelated native/AOT/WebAssembly timing paths. #6044 moves the test intotests/time/and conflicts with main, so it will need rebase/coordination before merge; it does not change the test logic. #8979 edits a different libc debt entry, and merge-tree combines both documentation edits without conflict. The PR is two commits behind current main, but currently mergeable.Checks: the author reports
guest_process_time*passing 3/3 runs on Windows 11 with this change and 1,887/1,890 full-suite tests passing (the same three failures were reproduced on main); the currently reported CI jobs pass for conventions, eligibility, intake, labels, report, relinker across Ubuntu/Windows/macOS, ASan, and register-context/write-watch on Ubuntu/macOS. Linux and Windows product build jobs are skipped, and no Linux/macOS or title run is reported. I did not run a local build in this review environment. The PR names four affected title IDs and explains the observed incorrect timing behavior; retain the disassembly-versus-console-measurement qualification in the documentation.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T09:01:43Z.
Review: COMMENTED
First run on Linux (the PR lists Linux as not tested; the non-Windows
std::clockbranch is the one replaced here). Ubuntu 26.04, glibc 2.43, x86_64 i7-8700, GCC 15.2.0, Release, head 280ae69a4 merged--no-commitontoorigin/main7e2ba73e4.guest_process_time*(4) +patched_libraries: 5/5 pass.GuestTime.hpp, libcTime.cppand libkernelTime.cppfrommain, test from the PR):guest_process_timeandguest_process_time_scaledabort withclock() is not the process time; the two_countertests still pass.^guest_.*(time|clock)tests andguest_kqueue(which times itself with the hoststd::clock) pass.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:28:38Z.
Review: CHANGES_REQUESTED
The earlier code review remains favorable, and the author-reported Windows and Linux focused test results are noted. This PR is still marked ready, but its checklist says Unblocks: none. Current-main git diff --check is clean; product build/test jobs are skipped by the repository workflow for this PR.
I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:28:44Z.
Review: COMMENTED
Correction to my preceding review: I fetched the exact PR head after composing the comment. It is current with upstream/main (0 commits behind, 1 ahead), and git diff --check passes. Please disregard the sentence saying it is 13 commits behind and the request to refresh the branch.
I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T12:29:44Z.
Rebased onto
main8b3a6ba88d(head 3e75fe94d2, no other changes). On Windows (UCRT GCC 15.2, Release),guest_process_time,guest_process_time_counter,guest_process_time_scaled,guest_process_time_counter_scaledand the other libc and time tests (17 tests) pass in three runs out of three.tools/check_conventions.pypasses.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T12:30:00Z.
@MarcZX10 thanks for the correction. I've converted this to a draft under the #5239 hold. It will be marked ready once a title is shown stopping on, or visibly affected by,
clock()timing on currentmain, with that run linked here.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:28:48Z.
Marked ready for review. This was a draft only because of the #5239 intake hold, which @MarcZX10 has withdrawn (https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6337453028 and on #9596).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:34:38Z.
Review: APPROVED
Correction: my earlier changes-requested review was based on an inaccurate intake and stale-base note. I have verified that note was corrected, and my review found no remaining code blocker. PRs may continue to be submitted and will be handled in due course.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:59:08Z.
Review: APPROVED
Re-reviewed — approved
The latest refresh preserves the process-time change and the checked pointer behavior from the already-merged #11402 integration. The author reports the Linux focused matrix rebuilt on exact head
6ac7ce9e401899294b07fd56eea0ec72a6fb0980: seven groups, three runs each, 21 passes and no skips. The PR also retains its earlier Windows and title/reference evidence at their original stated pins; no new Windows, console, title, GPU or full-suite run is claimed.I checked exact head
6ac7ce9e401899294b07fd56eea0ec72a6fb0980against currentmainf7e84c4cf1609cc10bac95a44cd431805e5ebc8a:tools/check_conventions.py: passed.git diff --check: passed.Time.cppand the process-time tests have no intervening main changes.The Linux runs are author-reported; I did not execute them locally. No blocking issue remains in this exact head.