feat(posix): implement times accounting #24190

Merged
DonRyuzaki merged 1 commit from upstream-pr/24190 into main 2026-11-20 20:48:31 +00:00
DonRyuzaki commented 2026-11-20 09:51:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DonRyuzaki on 2026-11-20T09:51:23Z.


What

Provide the exact times import listed for Azahar in RetroArch PPSA99169 in #5927's grouped inventory. FreeBSD 11.4 reports process user and system CPU time plus a monotonic return value in 128 ticks per second. Its x86-64 clock_t is signed 32-bit, making the four-field tms layout 16 bytes. This implementation converts host process CPU accounting to those ticks, uses AnyPS5's existing guest monotonic nanosecond source for the return, and writes the result through checked guest access. Terminated-child counters remain zero, consistent with the current guest getrusage(RUSAGE_CHILDREN) behavior. The debt fragment records the unverified guest child accounting and console provider.

Tested

Windows 11, WinLibs GCC 15.2, Release: the focused test failed to link on times_nid_postfix before implementation. With the implementation, guest_posix_times_tests built and ctest -R ^guest_posix_times$ passed (1/1). It checks the 16-byte layout, nondecreasing process CPU counters, advancing 128 Hz monotonic ticks, zero guest child counters, null and unwritable outputs, and preserved errno. The compiled PE export table contains times_nid_postfix.

Linux WSL2, GCC 13.3, Release: guest_posix_times_tests built and ctest -R ^guest_posix_times$ passed (1/1). The exact-name scan found no times declaration on main or 2,029 open PRs. The final branch scan compared 2,040 open PRs: all eight shared-file branches merged cleanly into the base. It could not merge older #22903's Api.hpp patch, which was manually checked and contains no times declaration. Conventions, debt fold, and diff checks passed on the final head. No Azahar or console run.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: PPSA99169 #5927 (times import; other imports remain)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5411295308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24190). Originally posted by [DonRyuzaki](https://github.com/DonRyuzaki) on 2026-11-20T09:51:23Z. --- ### What Provide the exact `times` import listed for Azahar in RetroArch PPSA99169 in [#5927's grouped inventory](https://github.com/boykopovar/AnyPS5/issues/5927#issuecomment-7022427172). [FreeBSD 11.4](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libc/gen/times.c) reports process user and system CPU time plus a monotonic return value in 128 ticks per second. Its [x86-64 `clock_t` is signed 32-bit](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/x86/include/_types.h), making the four-field [`tms` layout](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/sys/times.h) 16 bytes. This implementation converts host process CPU accounting to those ticks, uses AnyPS5's existing guest monotonic nanosecond source for the return, and writes the result through checked guest access. Terminated-child counters remain zero, consistent with the current guest `getrusage(RUSAGE_CHILDREN)` behavior. The debt fragment records the unverified guest child accounting and console provider. ### 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 11, WinLibs GCC 15.2, Release: the focused test failed to link on `times_nid_postfix` before implementation. With the implementation, `guest_posix_times_tests` built and `ctest -R ^guest_posix_times$` passed (1/1). It checks the 16-byte layout, nondecreasing process CPU counters, advancing 128 Hz monotonic ticks, zero guest child counters, null and unwritable outputs, and preserved errno. The compiled PE export table contains `times_nid_postfix`. Linux WSL2, GCC 13.3, Release: `guest_posix_times_tests` built and `ctest -R ^guest_posix_times$` passed (1/1). The exact-name scan found no `times` declaration on main or 2,029 open PRs. The final branch scan compared 2,040 open PRs: all eight shared-file branches merged cleanly into the base. It could not merge older #22903's `Api.hpp` patch, which was manually checked and contains no `times` declaration. Conventions, debt fold, and diff checks passed on the final head. No Azahar or console run. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 - [x] Fixes: none - [x] Unblocks: PPSA99169 #5927 (`times` import; other imports remain) - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-20 09:54:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T09:54:54Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_posix_times_tests built cleanly.
  • CTest (guest_posix_times):
    1/1 Test #5100: guest_posix_times ................   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libScePosixForWebKit/include/Api.hpp, core/libs/prx/libScePosixForWebKit/Times.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified GuestTimes.hpp defines PosixForWebKitTms with 4 signed 32-bit fields matching FreeBSD 11.4 sys/times.h and static_assert(sizeof(...) == 16).
    • Verified Times.cpp process CPU tick conversion: Windows GetProcessTimes (100ns units / (10000000 / 128)) and POSIX getrusage (seconds * 128 + micros * 128 / 1000000) correctly compute 128 Hz ticks.
    • Verified monotonic clock return computation (nowNanos / 7812500) where 1e9 / 128 = 7812500 ns/tick, truncated to int32_t via bit_cast in Tick32.
    • Verified guest memory safety and error handling: null pointer check throws std::invalid_argument, unwritable guest pointer check via GuestCopyOut_nid_no_patch throws std::invalid_argument, preserving errno.
    • Verified AGENTS.md rules: no prohibited comments, Conventional Commit title, debt fragment present under docs/dev/debt/changes/feat-posix-webkit-times.md, no unpermitted files.
    • Verified unit test GuestPosixTimes.cpp tests counter monotonicity, zero terminated-child counters, errno preservation, and null/unwritable guest pointer validation paths.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990771422 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24190#pullrequestreview-5990771422). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T09:54:54Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `2ee9d589d0`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_posix_times_tests` built cleanly. - **CTest** (`guest_posix_times`): ``` 1/1 Test #5100: guest_posix_times ................ Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libScePosixForWebKit/include/Api.hpp`, `core/libs/prx/libScePosixForWebKit/Times.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified GuestTimes.hpp defines PosixForWebKitTms with 4 signed 32-bit fields matching FreeBSD 11.4 sys/times.h and static_assert(sizeof(...) == 16). - Verified Times.cpp process CPU tick conversion: Windows GetProcessTimes (100ns units / (10000000 / 128)) and POSIX getrusage (seconds * 128 + micros * 128 / 1000000) correctly compute 128 Hz ticks. - Verified monotonic clock return computation (nowNanos / 7812500) where 1e9 / 128 = 7812500 ns/tick, truncated to int32_t via bit_cast in Tick32. - Verified guest memory safety and error handling: null pointer check throws std::invalid_argument, unwritable guest pointer check via GuestCopyOut_nid_no_patch throws std::invalid_argument, preserving errno. - Verified AGENTS.md rules: no prohibited comments, Conventional Commit title, debt fragment present under docs/dev/debt/changes/feat-posix-webkit-times.md, no unpermitted files. - Verified unit test GuestPosixTimes.cpp tests counter monotonicity, zero terminated-child counters, errno preservation, and null/unwritable guest pointer validation paths. Looks Good To Me
MarcZX10 commented 2026-11-20 09:55:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:55:18Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 2ee9d589d0fb4f255025fe8168d2fe86a2c5280e. I inspected the prepared diff and all six changed files, plus targeted guest memory and monotonic clock helper code. No commands or tests were run.

Results

Check Result Note
Diff and changed files passed All six changed files read
Targeted helper context passed Checked memory copy and clock source
Build and tests not run No test execution in this review
Console behavior not run No console run reported by reviewer

Negative control

Not run; no tests were run during this review.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

No build, test, or console run was performed by this reviewer. The Windows and Linux test results and export scan in the PR description are author-reported, not independently confirmed. All six changed files listed in the manifest were read; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990777741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24190#pullrequestreview-5990777741). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T09:55:18Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Reviewed head `2ee9d589d0fb4f255025fe8168d2fe86a2c5280e`. I inspected the prepared diff and all six changed files, plus targeted guest memory and monotonic clock helper code. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All six changed files read | | Targeted helper context | passed | Checked memory copy and clock source | | Build and tests | not run | No test execution in this review | | Console behavior | not run | No console run reported by reviewer | ## Negative control Not run; no tests were run during this review. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Times implementation at reviewed head](https://github.com/boykopovar/AnyPS5/blob/2ee9d589d0fb4f255025fe8168d2fe86a2c5280e/core/libs/prx/libScePosixForWebKit/Times.cpp#L64-L74) - [Guest times test at reviewed head](https://github.com/boykopovar/AnyPS5/blob/2ee9d589d0fb4f255025fe8168d2fe86a2c5280e/core/libs/tests/GuestPosixTimes.cpp#L11-L35) ## Not verified No build, test, or console run was performed by this reviewer. The Windows and Linux test results and export scan in the PR description are author-reported, not independently confirmed. All six changed files listed in the manifest were read; no changed files were excluded. ## To get this to a good state Nothing is required.
Superseabas commented 2026-11-20 13:20:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-20T13:20:12Z.

Review: APPROVED


Windows check of head 2ee9d589d0 with GCC 16, merged onto main 0a025bd3c6 (clean merge).

Setup: Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. This was built together with #23341 and #21969, which touch other files.

  • POSIX-for-WebKit tests (^guest_(posix|fnmatch)): main 31 of 31, and with this PR 32 of 32 in 3 of 3 runs. The new one is guest_posix_times, which exercises the GetProcessTimes path here.
  • Red check: with the return value forced to 0 (return Tick32(... / 7812500) → return 0), guest_posix_times aborts (0xc0000409) at after > before.

One optional note: a null or unwritable tms pointer throws std::invalid_argument, where FreeBSD's times would fail with EFAULT. That's in line with throwing when the console's answer isn't measured, but the debt entry doesn't mention it yet.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5993326578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24190#pullrequestreview-5993326578). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-20T13:20:12Z. **Review:** APPROVED --- Windows check of head `2ee9d589d0` with GCC 16, merged onto `main` `0a025bd3c6` (clean merge). **Setup:** Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. This was built together with #23341 and #21969, which touch other files. - **POSIX-for-WebKit tests** (`^guest_(posix|fnmatch)`): `main` 31 of 31, and with this PR 32 of 32 in 3 of 3 runs. The new one is `guest_posix_times`, which exercises the `GetProcessTimes` path here. - **Red check:** with the return value forced to 0 (`return Tick32(... / 7812500)` → `return 0`), `guest_posix_times` aborts (`0xc0000409`) at `after > before`. One optional note: a null or unwritable `tms` pointer throws `std::invalid_argument`, where FreeBSD's `times` would fail with `EFAULT`. That's in line with throwing when the console's answer isn't measured, but the debt entry doesn't mention it yet. AI-assisted: yes (Claude Code)
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!24190
No description provided.