test(libkernel): check clock_getres for the wall, monotonic and uptime clocks #9658

Merged
DavidSamir merged 1 commit from upstream-pr/9658 into main 2026-11-01 21:13:55 +00:00
DavidSamir commented 2026-10-22 06:44:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T06:44:42Z.


What

guest_freebsd_clocks checked clock_getres values only for the virtual and profiling clocks, through its ResolutionNanos helper. Line coverage of the Windows build showed that the Windows branches of clock_getres (Time.cpp:551-566) never ran with a result pointer:

  • the fixed 100 ns resolution of CLOCK_REALTIME/CLOCK_REALTIME_PRECISE;
  • the QueryPerformanceFrequency resolution of the monotonic, uptime and fast clocks.

How:

  • tests/GuestFreebsdClocks.cpp: names the FreeBSD clock ids 5, 7, 8, 10, 11 and 12. A new check runs the existing ResolutionNanos helper on CLOCK_REALTIME, _PRECISE, _FAST, CLOCK_MONOTONIC, _PRECISE, _FAST, CLOCK_UPTIME, _PRECISE and _FAST. For each it requires success, tv_sec == 0, 0 < tv_nsec < 1 s, and the same value from sceKernelClockGetres.

Tested

  • Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, no GPU involved: guest_freebsd_clocks passes.
  • Negative controls, each one breaking one Windows branch:
    • the QPC branch reporting tv_nsec = 0: the test fails;
    • the 100 ns branch reporting 0: the test fails.
    • With both restored, it passes.
  • The non-Windows branch maps every one of these ids to a host clock (CLOCK_REALTIME_COARSE where available). Its resolution is below a second there too, but Linux was not run locally; CI runs it.
  • tools/check_conventions.py passes.

Overlap (tools/pr_overlap.py --branch plus git merge-tree):

  • #9501 changes Time.cpp and GuestThreadCpuClock.cpp for the process and thread CPU clocks. This test leaves those clocks out, and git merge-tree adds no conflict.
  • #6044 already conflicts with main in this file; it gets no new hunk.

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:4963268322 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9658). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T06:44:42Z. --- ### What `guest_freebsd_clocks` checked `clock_getres` values only for the virtual and profiling clocks, through its `ResolutionNanos` helper. Line coverage of the Windows build showed that the Windows branches of `clock_getres` (Time.cpp:551-566) never ran with a result pointer: - the fixed 100 ns resolution of `CLOCK_REALTIME`/`CLOCK_REALTIME_PRECISE`; - the `QueryPerformanceFrequency` resolution of the monotonic, uptime and fast clocks. How: - `tests/GuestFreebsdClocks.cpp`: names the FreeBSD clock ids 5, 7, 8, 10, 11 and 12. A new check runs the existing `ResolutionNanos` helper on `CLOCK_REALTIME`, `_PRECISE`, `_FAST`, `CLOCK_MONOTONIC`, `_PRECISE`, `_FAST`, `CLOCK_UPTIME`, `_PRECISE` and `_FAST`. For each it requires success, `tv_sec == 0`, `0 < tv_nsec < 1 s`, and the same value from `sceKernelClockGetres`. ### Tested - Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, no GPU involved: `guest_freebsd_clocks` passes. - Negative controls, each one breaking one Windows branch: - the QPC branch reporting `tv_nsec = 0`: the test fails; - the 100 ns branch reporting `0`: the test fails. - With both restored, it passes. - The non-Windows branch maps every one of these ids to a host clock (`CLOCK_REALTIME_COARSE` where available). Its resolution is below a second there too, but Linux was not run locally; CI runs it. - `tools/check_conventions.py` passes. Overlap (`tools/pr_overlap.py --branch` plus `git merge-tree`): - #9501 changes `Time.cpp` and `GuestThreadCpuClock.cpp` for the process and thread CPU clocks. This test leaves those clocks out, and `git merge-tree` adds no conflict. - #6044 already conflicts with `main` in this file; it gets no new hunk. ### 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
MarcZX10 commented 2026-10-22 09:11:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:11:22Z.

Review: CHANGES_REQUESTED


The added clock IDs match the FreeBSD values used by the Windows implementation, and ResolutionNanos checks both APIs return the same valid subsecond value. The author reports Windows 11 runs with negative controls for both resolution branches. Exact-head diff-check and conventions pass; hosted conventions, eligibility, intake and labels pass, while platform test jobs are skipped.

I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611819798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9658#pullrequestreview-5611819798). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T09:11:22Z. **Review:** CHANGES_REQUESTED --- The added clock IDs match the FreeBSD values used by the Windows implementation, and `ResolutionNanos` checks both APIs return the same valid subsecond value. The author reports Windows 11 runs with negative controls for both resolution branches. Exact-head diff-check and conventions pass; hosted conventions, eligibility, intake and labels pass, while platform test jobs are skipped. I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
DavidSamir commented 2026-10-22 09:21:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:21:06Z.


Thanks for the review, @MarcZX10.

On the intake point: this is a test-only PR, the first coverage of the Windows clock_getres branches, which a line-coverage run of the Windows build showed never ran. It has negative controls for both branches. No title is known to stop on these clocks, so Unblocks stays none. If a maintainer asks on this PR to hold it, I'll convert it to a draft right away.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337304853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9658#issuecomment-6337304853). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T09:21:06Z. --- Thanks for the review, @MarcZX10. On the intake point: this is a test-only PR, the first coverage of the Windows `clock_getres` branches, which a line-coverage run of the Windows build showed never ran. It has negative controls for both branches. No title is known to stop on these clocks, so `Unblocks` stays `none`. If a maintainer asks on this PR to hold it, I'll convert it to a draft right away. AI-assisted: yes
MarcZX10 commented 2026-10-22 12:40:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:40:38Z.

Review: CHANGES_REQUESTED


The added clock IDs and calls through ResolutionNanos are consistent with the Windows clock_getres branches described here, and the reported negative controls are useful evidence. The current PR base is d6eafa54, however, while upstream main is now 8b3a6ba (15 commits ahead). CONTRIBUTING.md requires branches to be based on and kept up to date with current main, so please rebase this test onto current main and rerun guest_freebsd_clocks on the resulting Windows build. The current hosted Linux/Windows product jobs are skipped, and the Windows results in the description are for the older base. I found no issue with the test logic itself.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5614267691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9658#pullrequestreview-5614267691). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T12:40:38Z. **Review:** CHANGES_REQUESTED --- The added clock IDs and calls through `ResolutionNanos` are consistent with the Windows `clock_getres` branches described here, and the reported negative controls are useful evidence. The current PR base is `d6eafa54`, however, while upstream `main` is now `8b3a6ba` (15 commits ahead). `CONTRIBUTING.md` requires branches to be based on and kept up to date with current `main`, so please rebase this test onto current `main` and rerun `guest_freebsd_clocks` on the resulting Windows build. The current hosted Linux/Windows product jobs are skipped, and the Windows results in the description are for the older base. I found no issue with the test logic itself.
THEMANnt commented 2026-10-25 06:59:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T06:59:04Z.

Review: APPROVED


Reviewed ff46432826c17f2156cf862c3a5ba5326a4b0df0 against author merge base 4a17c71757644170c6a0acfcc67fb17f81cff93f.

Approve. No actionable findings in this focused test-only change.

The nine added wall/monotonic/uptime clock IDs reuse ResolutionNanos, which checks a positive subsecond resolution and equality of POSIX and SCE wrappers. Reviewed their pinned Time.cpp dispatch: Windows uses its wall or performance-counter resolution for these IDs, and sceKernelClockGetres delegates to the same implementation. The existing whole-second clock test remains separate.

Validation: head/baseline GCC syntax checks passed. The exact added helper and original ResolutionNanos/Require logic were extracted with original declarations/constants, compiled, and executed successfully against the existing development libkernel/libc DLLs. This is compatibility evidence for the new calls, not a pinned production rebuild or a full clocks-suite pass; the full suite could not link to the old DLL because of unrelated missing clock_settime. Conventions, whitespace and registration passed. Hosted native jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641963425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9658#pullrequestreview-5641963425). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-25T06:59:04Z. **Review:** APPROVED --- Reviewed `ff46432826c17f2156cf862c3a5ba5326a4b0df0` against author merge base `4a17c71757644170c6a0acfcc67fb17f81cff93f`. Approve. No actionable findings in this focused test-only change. The nine added wall/monotonic/uptime clock IDs reuse ResolutionNanos, which checks a positive subsecond resolution and equality of POSIX and SCE wrappers. Reviewed their pinned Time.cpp dispatch: Windows uses its wall or performance-counter resolution for these IDs, and sceKernelClockGetres delegates to the same implementation. The existing whole-second clock test remains separate. Validation: head/baseline GCC syntax checks passed. The exact added helper and original ResolutionNanos/Require logic were extracted with original declarations/constants, compiled, and executed successfully against the existing development libkernel/libc DLLs. This is compatibility evidence for the new calls, not a pinned production rebuild or a full clocks-suite pass; the full suite could not link to the old DLL because of unrelated missing clock_settime. Conventions, whitespace and registration passed. Hosted native jobs were skipped.
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!9658
No description provided.