libkernel: process time counts from the first call, not from process start, so the first reading is about 0 #3366

Closed
opened 2026-10-11 09:07:47 +00:00 by Zurisen · 1 comment
Zurisen commented 2026-10-11 09:07:47 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-11T09:07:47Z.


On main 1c75f4d2, sceKernelGetProcessTime and sceKernelGetProcessTimeCounter measure from a start that GetStartNanos captures in a function-local static, i.e. on their first call. The first reading is therefore about 0 however long the process has run, and exactly 0 when the capture and the read fall in one tick of the host clock (QueryPerformanceCounter, 100 ns on Windows here). On the console these count from process start. Not specific to one title.

Measured

Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release.

  • guest_ampr_markers fails intermittently on main: 6 of 10 runs alone, at GuestAmpr.cpp:381. Printing the values there shows result=0 single=3 pair=0x400000003 time=0 in every failing run: the WriteAddressFromTimeCounter command is the process's first sceKernelGetProcessTimeCounter call.
  • A process that sleeps 50 ms before its first call reads about 0 from both functions instead of at least 50 ms.

Fix branch

Zurisen:fix/libkernel-process-time-start (one commit on main 1c75f4d2):

  • Time.cpp 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.cpp sleeps 50 ms before the first call and requires the first reading to include it (scaled by APS5_TIME_SCALE for the _scaled variants). The four guest_process_time* tests fail on main and pass 5/5 with the change.
  • guest_ampr_markers: 19/20 with the change. The remaining failure is unrelated: fixed guest mapping 0xec00000000+0x1000000000 overlaps a host region in the guest arena, after line 381 has passed (3 of 40 runs).
  • Full ctest --repeat until-fail:3: 815/816; the failure is pr_overlap_encoding, which also fails on main here (Python 3.10). Conventions check passes.

PR intake is limited, so I have not opened a PR; anyone eligible is welcome to carry the commit.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5799669260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3366). Originally posted by [Zurisen](https://github.com/Zurisen) on 2026-10-11T09:07:47Z. --- On `main` `1c75f4d2`, `sceKernelGetProcessTime` and `sceKernelGetProcessTimeCounter` measure from a start that [`GetStartNanos`](https://github.com/boykopovar/AnyPS5/blob/1c75f4d22/core/libs/prx/libkernel/Time/Time.cpp#L80-L83) captures in a function-local static, i.e. on their first call. The first reading is therefore about 0 however long the process has run, and exactly 0 when the capture and the read fall in one tick of the host clock (`QueryPerformanceCounter`, 100 ns on Windows here). On the console these count from process start. Not specific to one title. ### Measured Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release. - `guest_ampr_markers` fails intermittently on `main`: 6 of 10 runs alone, at [`GuestAmpr.cpp:381`](https://github.com/boykopovar/AnyPS5/blob/1c75f4d22/core/libs/tests/GuestAmpr.cpp#L381). Printing the values there shows `result=0 single=3 pair=0x400000003 time=0` in every failing run: the `WriteAddressFromTimeCounter` command is the process's first `sceKernelGetProcessTimeCounter` call. - A process that sleeps 50 ms before its first call reads about 0 from both functions instead of at least 50 ms. ### Fix branch [`Zurisen:fix/libkernel-process-time-start`](https://github.com/Zurisen/AnyPS5/commit/5ac54a32e) (one commit on `main` `1c75f4d2`): - `Time.cpp` 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.cpp` sleeps 50 ms before the first call and requires the first reading to include it (scaled by `APS5_TIME_SCALE` for the `_scaled` variants). The four `guest_process_time*` tests fail on `main` and pass 5/5 with the change. - `guest_ampr_markers`: 19/20 with the change. The remaining failure is unrelated: `fixed guest mapping 0xec00000000+0x1000000000 overlaps a host region in the guest arena`, after line 381 has passed (3 of 40 runs). - Full ctest `--repeat until-fail:3`: 815/816; the failure is `pr_overlap_encoding`, which also fails on `main` here (Python 3.10). Conventions check passes. PR intake is limited, so I have not opened a PR; anyone eligible is welcome to carry the commit.
reyani-dev commented 2026-10-11 09:13:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T09:13:54Z.


Carried as #3368 with your commit unchanged. On Windows 11 / GCC 15.2, the four guest_process_time* tests fail on main with your test and pass 5/5 with the fix, and ctest -E "^agc_|video_out" passes 441/441.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107478038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3366#issuecomment-6107478038). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T09:13:54Z. --- Carried as #3368 with your commit unchanged. On Windows 11 / GCC 15.2, the four `guest_process_time*` tests fail on `main` with your test and pass 5/5 with the fix, and `ctest -E "^agc_|video_out"` passes 441/441.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3366
No description provided.