fix(libkernel): report elapsed process time for clock id 15 #18471

Merged
THEMANnt merged 1 commit from upstream-pr/18471 into main 2026-11-21 16:44:55 +00:00
THEMANnt commented 2026-11-11 17:23:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-11T17:23:06Z.


What

Return elapsed time since libkernel initialization from clock ID 15. On a PS5 payload running firmware 13.590.001, clock 15 advanced with wall time during sleep and CPU load. The encoded process CPU clock retains its existing CPU accounting. The console's exact process start boundary and retail export behavior remain unverified. Console measurements

The separate resolution query is covered by #17958. #18466 and #18470 edit the same debt entry, so their merge order may require a small rebase.

Tested

  • Windows x64, WinLibs GCC 15.2. Built libkernel and passed guest_freebsd_clocks, guest_cpu_time_clocks, guest_thread_cpu_clock, and public_headers.
  • The regression compares clock 15's progress during a guest sleep to the monotonic clock. CPU-accounting tests continue to exercise the process CPU clocks. Repository conventions passed.
  • No title run. This change is based on the console payload measurements.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5263826221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18471). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-11-11T17:23:06Z. --- ### What Return elapsed time since libkernel initialization from clock ID 15. On a PS5 payload running firmware 13.590.001, clock 15 advanced with wall time during sleep and CPU load. The encoded process CPU clock retains its existing CPU accounting. The console's exact process start boundary and retail export behavior remain unverified. [Console measurements](https://github.com/boykopovar/AnyPS5/issues/15725) The separate resolution query is covered by #17958. #18466 and #18470 edit the same debt entry, so their merge order may require a small rebase. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows x64, WinLibs GCC 15.2. Built libkernel and passed `guest_freebsd_clocks`, `guest_cpu_time_clocks`, `guest_thread_cpu_clock`, and `public_headers`. - The regression compares clock 15's progress during a guest sleep to the monotonic clock. CPU-accounting tests continue to exercise the process CPU clocks. Repository conventions passed. - No title run. This change is based on the console payload measurements. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-11 17:33:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T17:33:29Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 2dba45641a:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_cpu_time_clocks_tests, guest_freebsd_clocks_tests, guest_thread_cpu_clock_tests built cleanly.
  • CTest (guest_cpu_time_clocks, guest_freebsd_clocks, guest_thread_cpu_clock):
    1/3 Test #4383: guest_freebsd_clocks .............   Passed    1.01 sec
    2/3 Test #4381: guest_cpu_time_clocks ............   Passed    1.05 sec
    3/3 Test #4384: guest_thread_cpu_clock ...........   Passed    1.63 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libkernel/Time/Time.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #4381: guest_cpu_time_clocks ............   Passed    1.09 sec
    2/3 Test #4383: guest_freebsd_clocks .............Subprocess aborted***Exception:   0.54 sec
    3/3 Test #4384: guest_thread_cpu_clock ...........   Passed    1.82 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Time/Time.cpp: Verified clock_gettime_nid_postfix computes elapsed monotonic time for GUEST_CLOCK_PROCESS_CPUTIME_ID (15) using GetMonotonicNanos() - GetStartNanos() and correctly sets value.tv_sec and value.tv_nsec.
    • core/libs/prx/libkernel/Time/Time.cpp: Verified clock ID validation (range checks and MeasuredIoErrorClock) precedes calculation, and tp == nullptr correctly sets *__error_nid_postfix() = GUEST_EFAULT (14) and returns -1 before dereference.
    • core/libs/prx/libkernel/Time/Time.cpp: Verified encoded process CPU clocks (IsCpuClock with CPU_CLOCK_PROCESS_BIT) continue delegating to ReadClock(GUEST_CLOCK_PROCESS_CPUTIME_ID, tp) for host CPU time accounting without regression.
    • core/libs/tests/GuestFreebsdClocks.cpp: Verified ProcessElapsedClockAdvancesWhileSleeping checks clock 15 advancement during a 100 ms sleep against monotonic clock bounds with correct sandwiching assertions.
    • core/libs/tests/GuestCpuTimeClocks.cpp and core/libs/tests/GuestThreadCpuClock.cpp: Verified process CPU tests update reference clock checks to GUEST_CLOCK_PROF (2) to prevent false failures while preserving CPU accounting coverage.
    • docs/dev/debt/libkernel.md & AGENTS.md: Verified technical debt entry accurately describes console payload measurements for clock ID 15, PR checklist is complete, and zero code comments were added.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5862868417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18471#pullrequestreview-5862868417). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T17:33:29Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `2dba45641a`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_cpu_time_clocks_tests`, `guest_freebsd_clocks_tests`, `guest_thread_cpu_clock_tests` built cleanly. - **CTest** (`guest_cpu_time_clocks`, `guest_freebsd_clocks`, `guest_thread_cpu_clock`): ``` 1/3 Test #4383: guest_freebsd_clocks ............. Passed 1.01 sec 2/3 Test #4381: guest_cpu_time_clocks ............ Passed 1.05 sec 3/3 Test #4384: guest_thread_cpu_clock ........... Passed 1.63 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libkernel/Time/Time.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #4381: guest_cpu_time_clocks ............ Passed 1.09 sec 2/3 Test #4383: guest_freebsd_clocks .............Subprocess aborted***Exception: 0.54 sec 3/3 Test #4384: guest_thread_cpu_clock ........... Passed 1.82 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Time/Time.cpp: Verified clock_gettime_nid_postfix computes elapsed monotonic time for GUEST_CLOCK_PROCESS_CPUTIME_ID (15) using GetMonotonicNanos() - GetStartNanos() and correctly sets value.tv_sec and value.tv_nsec. - core/libs/prx/libkernel/Time/Time.cpp: Verified clock ID validation (range checks and MeasuredIoErrorClock) precedes calculation, and tp == nullptr correctly sets *__error_nid_postfix() = GUEST_EFAULT (14) and returns -1 before dereference. - core/libs/prx/libkernel/Time/Time.cpp: Verified encoded process CPU clocks (IsCpuClock with CPU_CLOCK_PROCESS_BIT) continue delegating to ReadClock(GUEST_CLOCK_PROCESS_CPUTIME_ID, tp) for host CPU time accounting without regression. - core/libs/tests/GuestFreebsdClocks.cpp: Verified ProcessElapsedClockAdvancesWhileSleeping checks clock 15 advancement during a 100 ms sleep against monotonic clock bounds with correct sandwiching assertions. - core/libs/tests/GuestCpuTimeClocks.cpp and core/libs/tests/GuestThreadCpuClock.cpp: Verified process CPU tests update reference clock checks to GUEST_CLOCK_PROF (2) to prevent false failures while preserving CPU accounting coverage. - docs/dev/debt/libkernel.md & AGENTS.md: Verified technical debt entry accurately describes console payload measurements for clock ID 15, PR checklist is complete, and zero code comments were added. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!18471
No description provided.