feat(libkernel): report the clock resolutions a PS5 measured #17958

Merged
AlfaRojo merged 10 commits from upstream-pr/17958 into main 2026-11-15 20:22:13 +00:00
AlfaRojo commented 2026-11-10 01:00:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlfaRojo on 2026-11-10T01:00:09Z.


What

clock_getres and sceKernelClockGetres reported the host clock's resolution: on Windows 100 ns for the realtime clocks, the QPC tick for the monotonic ones and the clock interrupt period (15.6 ms by default) for CPU time, on Linux whatever the host's clock_getres says. On #15725, spluton measured the raw clock_getres system call on a PS5 (CFI-1216A, firmware 12.000.043, from a system process and a retail title process, identical answers; comment). On the same PR, xXPBSXx measured libc clock_getres from C in a PS5 payload process (firmware 11.60; comment): ids 3, 6, 16 to 20 and 22 to 31 return -1 with EINVAL and leave the result untouched, ids 1000 and INT_MAX also fail with EINVAL, -1 gives 1 µs and a null result returns 0 even for id 3; the values agree with #15725 where both measured. Both exports now answer as those measurements did:

Clock id Measured Now
0, 4, 5, 7 to 12 81 ns 81 ns
1, 2 1 ms 1 ms
13 1 s 1 s (as before)
14, 21 1 µs 1 µs; 21 used to throw
15 EINVAL, while clock_gettime(15) succeeds EINVAL like the ids below, clock_gettime(15) unchanged
3, 6, 16 to 20, 22 to 31 EINVAL, result untouched (11.60 libc probe; not probed on 12.00) EINVAL (0x80020016 from sceKernelClockGetres), result left unwritten
32 and above 1000 and INT_MAX: EINVAL (11.60) EINVAL, as #14557 made it on main

The host-resolution helpers (CpuTimeResolutionNanos, ProcessCpuResolutionNanos, the QPC frequency query and the POSIX clock_getres switch) are removed. Encoded CPU clocks (bit 31) still answer as id 14, as FreeBSD 11.4's kern_clock_getres does for negative ids; a null result still returns 0 before the id is checked. The null result and -1 now agree with the 11.60 probe; the libkernel export itself was not measured (the probe went through the system call; clock_gettime's export differs from the system call for id 20, per #16437). The debt entry in docs/dev/debt/libkernel.md is cut to those gaps and to the host granularity the clock values keep. #15725 stays open: what ids 20 and 21 count is still unknown.

Tests: guest_freebsd_clocks (ResolutionsAreTheConsoles) checks every measured id through both exports with the exact value and an untouched errno, every id from 3 to 31 without a resolution (15 included) with EINVAL/0x80020016 and an untouched result while clock_gettime(15) still succeeds, ids 32, 100 and INT_MAX with EINVAL and an untouched result (OutOfRangeResolutionIsInvalid, formerly UnsupportedResolutionStillThrows), and adds id 21 to the null-result ids; its ResolutionNanos helper and the resolution checks that ResolutionsAreTheConsoles now covers are removed. guest_cpu_time_clocks checks id 14 at 1 µs and id 15 with EINVAL through both exports instead of accepting any sub-second value for both. guest_thread_cpu_clock (encoded CPU clocks answer as id 14) and guest_timespec_getres* (libc's timespec_getres forwards to sceKernelClockGetres(0)) are unchanged.

Tested

Windows 11 Pro (10.0.26200), WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, BUILD_TESTING=ON, on main 5a6eb85be8 (head f4460abecd).

  • guest_freebsd_clocks: 3 of 3 runs passed; with the test change alone against the previous Time.cpp it fails (clock_getres_nid_postfix: unsupported clock_id 3)
  • guest_cpu_time_clocks: 3 of 3 runs passed
  • Regression: guest_thread_cpu_clock passed; guest_timespec_getres_unsupported, guest_timespec_getres_forwarding, guest_timespec_getres_errors, guest_timespec_getres_integration passed
  • public_headers passed (70 of 70 tests of the regression run)
  • tools/check_test_registration.py: 0 built and not run as recorded, none new; every core/libs/prx source that defines an APS5_VABI function is compiled
  • tools/check_conventions.py --base upstream/main: All conventions checks passed.
  • tools/pr_overlap.py lists #12418 (moves the clock_getres body into a helper and adds EFAULT for an unwritable result; same function, other topic, whichever lands second resolves the conflict) and #14557 (EINVAL for ids 32 and above in clock_getres, merged since; its behaviour is kept, see the last entry) as touching the same lines of Time.cpp with no shared exports; of the PRs it could not compare because they conflict with main, #5021 and #12642 change other parts of Time.cpp (clock_gettime and the TSC exports; pthread suspend) and the rest, #14212 among them, only docs/dev/debt/libkernel.md; #17125 is a test-only audit in a new file. None implements the same change.

Linux and macOS not run. The resolutions are constants now, so the removed host-specific code (QueryPerformanceFrequency, POSIX clock_getres) no longer matters per platform.

  • Head 7bc8353088 (merged with upstream/main 60c460cc55, which brought #18466's clock_gettime for id 20; this PR leaves clock_gettime(20) as main has it and only makes clock_getres(20) return EINVAL, as measured): guest_freebsd_clocks, guest_cpu_time_clocks, guest_thread_cpu_clock, guest_kernel_clock, guest_kernel_clocks_nanosleep and the guest_timespec_getres tests (9 tests) pass in 3/3 runs; check_test_registration.py and check_conventions.py --base upstream/main pass. Main's WallAndUptimeClocksReportSubsecondResolutions check is replaced by ResolutionsAreTheConsoles, which pins the same nine clocks to 81 ns.
  • Head f16baf10cc (merged with upstream/main after #14557 landed): the only conflict was clock_getres_nid_postfix in Time.cpp, where #14557 had added EINVAL for ids 32 and above to the old code. The table keeps that: ids 32 and above (and any id without a measured resolution) set EINVAL and return -1, sceKernelClockGetres returns 0x80020016, so the last throw in clock_getres is gone. The debt line in docs/dev/debt/libkernel.md now says ids 32 and above fail with EINVAL. #14557's guest_kernel_sys_time test merged unchanged. guest_freebsd_clocks, guest_cpu_time_clocks, guest_kernel_sys_time, guest_thread_cpu_clock, guest_kernel_clock and guest_kernel_clocks_nanosleep pass in 3/3 runs; check_test_registration.py and check_conventions.py --base upstream/main pass.

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:5233840695 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17958). Originally posted by [AlfaRojo](https://github.com/AlfaRojo) on 2026-11-10T01:00:09Z. --- ### What `clock_getres` and `sceKernelClockGetres` reported the host clock's resolution: on Windows 100 ns for the realtime clocks, the QPC tick for the monotonic ones and the clock interrupt period (15.6 ms by default) for CPU time, on Linux whatever the host's `clock_getres` says. On #15725, spluton measured the raw `clock_getres` system call on a PS5 (CFI-1216A, firmware 12.000.043, from a system process and a retail title process, identical answers; [comment](https://github.com/boykopovar/AnyPS5/issues/15725#issuecomment-6690824148)). On the same PR, xXPBSXx measured libc `clock_getres` from C in a PS5 payload process (firmware 11.60; [comment](https://github.com/boykopovar/AnyPS5/pull/17958#issuecomment-6792739933)): ids 3, 6, 16 to 20 and 22 to 31 return -1 with `EINVAL` and leave the result untouched, ids 1000 and `INT_MAX` also fail with `EINVAL`, -1 gives 1 µs and a null result returns 0 even for id 3; the values agree with #15725 where both measured. Both exports now answer as those measurements did: | Clock id | Measured | Now | |---|---|---| | 0, 4, 5, 7 to 12 | 81 ns | 81 ns | | 1, 2 | 1 ms | 1 ms | | 13 | 1 s | 1 s (as before) | | 14, 21 | 1 µs | 1 µs; 21 used to throw | | 15 | `EINVAL`, while `clock_gettime(15)` succeeds | `EINVAL` like the ids below, `clock_gettime(15)` unchanged | | 3, 6, 16 to 20, 22 to 31 | `EINVAL`, result untouched (11.60 libc probe; not probed on 12.00) | `EINVAL` (`0x80020016` from `sceKernelClockGetres`), result left unwritten | | 32 and above | 1000 and `INT_MAX`: `EINVAL` (11.60) | `EINVAL`, as #14557 made it on `main` | The host-resolution helpers (`CpuTimeResolutionNanos`, `ProcessCpuResolutionNanos`, the QPC frequency query and the POSIX `clock_getres` switch) are removed. Encoded CPU clocks (bit 31) still answer as id 14, as FreeBSD 11.4's `kern_clock_getres` does for negative ids; a null result still returns 0 before the id is checked. The null result and -1 now agree with the 11.60 probe; the libkernel export itself was not measured (the probe went through the system call; `clock_gettime`'s export differs from the system call for id 20, per #16437). The debt entry in `docs/dev/debt/libkernel.md` is cut to those gaps and to the host granularity the clock values keep. #15725 stays open: what ids 20 and 21 count is still unknown. Tests: `guest_freebsd_clocks` (`ResolutionsAreTheConsoles`) checks every measured id through both exports with the exact value and an untouched errno, every id from 3 to 31 without a resolution (15 included) with `EINVAL`/`0x80020016` and an untouched result while `clock_gettime(15)` still succeeds, ids 32, 100 and `INT_MAX` with `EINVAL` and an untouched result (`OutOfRangeResolutionIsInvalid`, formerly `UnsupportedResolutionStillThrows`), and adds id 21 to the null-result ids; its `ResolutionNanos` helper and the resolution checks that `ResolutionsAreTheConsoles` now covers are removed. `guest_cpu_time_clocks` checks id 14 at 1 µs and id 15 with `EINVAL` through both exports instead of accepting any sub-second value for both. `guest_thread_cpu_clock` (encoded CPU clocks answer as id 14) and `guest_timespec_getres*` (libc's `timespec_getres` forwards to `sceKernelClockGetres(0)`) are unchanged. ### Tested Windows 11 Pro (10.0.26200), WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, `BUILD_TESTING=ON`, on `main` `5a6eb85be8` (head `f4460abecd`). - `guest_freebsd_clocks`: 3 of 3 runs passed; with the test change alone against the previous `Time.cpp` it fails (`clock_getres_nid_postfix: unsupported clock_id 3`) - `guest_cpu_time_clocks`: 3 of 3 runs passed - Regression: `guest_thread_cpu_clock` passed; `guest_timespec_getres_unsupported`, `guest_timespec_getres_forwarding`, `guest_timespec_getres_errors`, `guest_timespec_getres_integration` passed - `public_headers` passed (70 of 70 tests of the regression run) - `tools/check_test_registration.py`: 0 built and not run as recorded, none new; every core/libs/prx source that defines an APS5_VABI function is compiled - `tools/check_conventions.py --base upstream/main`: All conventions checks passed. - `tools/pr_overlap.py` lists #12418 (moves the `clock_getres` body into a helper and adds `EFAULT` for an unwritable result; same function, other topic, whichever lands second resolves the conflict) and #14557 (`EINVAL` for ids 32 and above in `clock_getres`, merged since; its behaviour is kept, see the last entry) as touching the same lines of `Time.cpp` with no shared exports; of the PRs it could not compare because they conflict with `main`, #5021 and #12642 change other parts of `Time.cpp` (`clock_gettime` and the TSC exports; pthread suspend) and the rest, #14212 among them, only `docs/dev/debt/libkernel.md`; #17125 is a test-only audit in a new file. None implements the same change. Linux and macOS not run. The resolutions are constants now, so the removed host-specific code (QueryPerformanceFrequency, POSIX clock_getres) no longer matters per platform. - Head `7bc8353088` (merged with upstream/main `60c460cc55`, which brought #18466's `clock_gettime` for id 20; this PR leaves `clock_gettime(20)` as main has it and only makes `clock_getres(20)` return `EINVAL`, as measured): `guest_freebsd_clocks`, `guest_cpu_time_clocks`, `guest_thread_cpu_clock`, `guest_kernel_clock`, `guest_kernel_clocks_nanosleep` and the `guest_timespec_getres` tests (9 tests) pass in 3/3 runs; `check_test_registration.py` and `check_conventions.py --base upstream/main` pass. Main's `WallAndUptimeClocksReportSubsecondResolutions` check is replaced by `ResolutionsAreTheConsoles`, which pins the same nine clocks to 81 ns. - Head `f16baf10cc` (merged with `upstream/main` after #14557 landed): the only conflict was `clock_getres_nid_postfix` in `Time.cpp`, where #14557 had added `EINVAL` for ids 32 and above to the old code. The table keeps that: ids 32 and above (and any id without a measured resolution) set `EINVAL` and return -1, `sceKernelClockGetres` returns `0x80020016`, so the last throw in `clock_getres` is gone. The debt line in `docs/dev/debt/libkernel.md` now says ids 32 and above fail with `EINVAL`. #14557's `guest_kernel_sys_time` test merged unchanged. `guest_freebsd_clocks`, `guest_cpu_time_clocks`, `guest_kernel_sys_time`, `guest_thread_cpu_clock`, `guest_kernel_clock` and `guest_kernel_clocks_nanosleep` pass in 3/3 runs; `check_test_registration.py` and `check_conventions.py --base upstream/main` pass. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!17958
No description provided.