fix(libkernel): count process time from library load #3368

Merged
reyani-dev merged 1 commit from upstream-pr/3368 into main 2026-10-11 09:19:49 +00:00
reyani-dev commented 2026-10-11 09:13:52 +00:00 (Migrated from github.com)

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).

sceKernelGetProcessTime and sceKernelGetProcessTimeCounter measured from a start that GetStartNanos captures 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 makes guest_ampr_markers fail intermittently at GuestAmpr.cpp:381 (time=0). On the console these count from process start.

Time.cpp now 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 its first call and requires the first reading to include it, scaled by APS5_TIME_SCALE for the _scaled variants.

Closes #3366.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main ac2c5c08:

  • With only the new test on main, all four guest_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_markers failed twice for me today in full parallel runs on main (0xc0000409) and passed when run alone, which matches the timing-dependent time=0 the issue describes.
  • check_conventions.py passes, and pr_overlap.py reports no overlap.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817977015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3368). Originally posted by [reyani-dev](https://github.com/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`). `sceKernelGetProcessTime` and `sceKernelGetProcessTimeCounter` measured from a start that `GetStartNanos` captures 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 makes `guest_ampr_markers` fail intermittently at `GuestAmpr.cpp:381` (`time=0`). On the console these count from process start. `Time.cpp` now 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 its first call and requires the first reading to include it, scaled by `APS5_TIME_SCALE` for the `_scaled` variants. Closes #3366. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on `main` `ac2c5c08`: - With only the new test on `main`, all four `guest_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_markers` failed twice for me today in full parallel runs on `main` (`0xc0000409`) and passed when run alone, which matches the timing-dependent `time=0` the issue describes. - `check_conventions.py` passes, and `pr_overlap.py` reports no overlap. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 09:19:45 +00:00 (Migrated from github.com)

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 the Time.cpp change, so they pin the fix. The function-local static in GetStartNanos is kept, so early calls during static init stay valid. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107523368 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3368#issuecomment-6107523368). Originally posted by [adriadam10](https://github.com/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 the `Time.cpp` change, so they pin the fix. The function-local static in `GetStartNanos` is kept, so early calls during static init stay valid. Merging.
orishamir commented 2026-10-11 09:39:23 +00:00 (Migrated from github.com)

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, main 09bd4aa1 + #1482): in a full ctest --parallel 4 run, guest_process_time_counter aborted with

first process time counter does not include the time before the first call

and 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107669978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3368#issuecomment-6107669978). Originally posted by [orishamir](https://github.com/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, `main` 09bd4aa1 + #1482): in a full `ctest --parallel 4` run, `guest_process_time_counter` aborted with ``` first process time counter does not include the time before the first call ``` and 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)
reyani-dev commented 2026-10-11 09:52:57 +00:00 (Migrated from github.com)

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_for can return a little early against the QPC the guest clock reads. #3414 makes the test wait until steady_clock shows 50 ms; with it, all four pass 60 rounds under -j8.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107770268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3368#issuecomment-6107770268). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T09:52:57Z. --- Thanks @orishamir. Reproduced here under `-j8` (two of the four tests failed within 60 rounds). `sleep_for` can return a little early against the QPC the guest clock reads. #3414 makes the test wait until `steady_clock` shows 50 ms; with it, all four pass 60 rounds under `-j8`.
Sign in to join this conversation.
No reviewers
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!3368
No description provided.