feat(libSceLibcInternal): implement the atomic wait deadline helpers #16146

Merged
Ducengarth merged 5 commits from upstream-pr/16146 into main 2026-11-08 23:16:44 +00:00
Ducengarth commented 2026-11-05 18:45:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-05T18:45:56Z.


What

Implement __std_atomic_wait_get_deadline and __std_atomic_wait_get_remaining_timeout in libSceLibcInternal, replacing their parameterless throwing placeholders in RecoveredInventory.cpp. They are the deadline helpers of the STL's timed atomic waits.

  • __std_atomic_wait_get_deadline(timeout) returns the current time in milliseconds plus timeout, wrapping as unsigned arithmetic. A timeout of 0xFFFFFFFFFFFFFFFF returns that same no-deadline value.
  • __std_atomic_wait_get_remaining_timeout(deadline) returns 0xFFFFFFFF (no timeout) for no deadline, 0 once the deadline has passed, and otherwise the milliseconds left, capped at 864000000 (ten days).

Source: Microsoft STL at e1ed302, with the no-deadline value here and the no-timeout value in xatomic_wait.h.

  • The clock is GetTickCount64 on Windows, as in that source, and CLOCK_MONOTONIC in milliseconds on POSIX; a failed POSIX clock query throws. The console's clock and epoch are unverified. This clock choice comes from #16145 and #16148.
  • One difference from that source: the remaining timeout returns 64 bits, because unsigned long is 64 bits in the PS5 ABI and 32 bits in that source. Every returned value fits in 32 bits, so a caller reading either width gets the same number.

Scope: this does not make timed atomic waits work in a title. __std_atomic_wait_direct_8, __std_atomic_wait_direct_16 and __std_atomic_notify_multi_direct still throw, because no source I found gives their signatures, and they are not touched here.

No title's trace or disassembly was used, and neither export was measured on a PS5. The gap is recorded in docs/dev/debt/libSceLibcInternal.md. The placeholder count there goes from 40 to 38, while the physical-module map still assigns all 40 inventory NIDs to the module. This consolidates #16145 and #16148, opened by MarrasFederico within a minute of this one, which implement one helper each; as agreed there, those two close as duplicates once this one is reconciled. pr_overlap reports no other pull request with the same exports or new files. It does report line conflicts, mainly in that count (#15460, #15577, #15581 and others) and in neighbouring placeholders (#15657), so whichever merges second has to resolve them. I will rebase this one as needed. Seven pull requests that already conflict with main could not be compared by the tool (#5021, #13486, #13778, #13782, #14212, #14664, #15899); their diffs do not mention these helpers.

Tested

Windows 11, MinGW-w64 GCC (WinLibs), Release build. No title or homebrew, and not built on Linux.

  • guest_libc_internal_atomic_wait_deadline (new) passes 3 runs out of 3 at the current head. It covers the no-deadline and no-timeout values, a zero timeout, a deadline expiring after a sleep, unsigned wrap, and the ten-day cap above, at and below the limit. The deadline and the time left are bounded by the test's own GetTickCount64 / CLOCK_MONOTONIC readings taken before and after each call, taken from #16145 and #16148.
  • At the first head, which used std::chrono::steady_clock, removing the cap, the no-deadline check or the expiry check each made the test fail with the matching message. These mutations were not repeated after the clock change.
  • At the first head: full build, then ctest --parallel 5 -E '^guest_thermal_sensors$' (that test hard-freezes this PC, see #16061): of 4209 tests, 3316 pass, 884 skip and 9 fail. The skips include 867 AGC tests, which this build leaves out with ANYPS5_AGC_EXECUTION_TESTS. Of the 9 failures, 4 pass when re-run alone (select_tests_SelectArgumentTests, one trace_digest test, agc_graphics_profile_draw, guest_timed_wait_cpu). The other 5 are in Python tooling tests this change does not touch: test_registration and select_tests_MissingCommandTests (os.symlink needs a privilege this account lacks), debt_split (temp folder inside the repository), title_run (a window-ordering check) and one trace_digest timeout. They were not compared with main.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5176863829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16146). Originally posted by [Ducengarth](https://github.com/Ducengarth) on 2026-11-05T18:45:56Z. --- ### What Implement `__std_atomic_wait_get_deadline` and `__std_atomic_wait_get_remaining_timeout` in `libSceLibcInternal`, replacing their parameterless throwing placeholders in `RecoveredInventory.cpp`. They are the deadline helpers of the STL's timed atomic waits. - `__std_atomic_wait_get_deadline(timeout)` returns the current time in milliseconds plus `timeout`, wrapping as unsigned arithmetic. A `timeout` of `0xFFFFFFFFFFFFFFFF` returns that same no-deadline value. - `__std_atomic_wait_get_remaining_timeout(deadline)` returns `0xFFFFFFFF` (no timeout) for no deadline, 0 once the deadline has passed, and otherwise the milliseconds left, capped at 864000000 (ten days). Source: Microsoft STL at [`e1ed302`](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/src/atomic_wait.cpp#L181-L209), with the no-deadline value [here](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/src/atomic_wait.cpp#L17) and the no-timeout value in [`xatomic_wait.h`](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/inc/xatomic_wait.h#L22). - The clock is `GetTickCount64` on Windows, as in that source, and `CLOCK_MONOTONIC` in milliseconds on POSIX; a failed POSIX clock query throws. The console's clock and epoch are unverified. This clock choice comes from #16145 and #16148. - One difference from that source: the remaining timeout returns 64 bits, because `unsigned long` is 64 bits in the PS5 ABI and 32 bits in that source. Every returned value fits in 32 bits, so a caller reading either width gets the same number. Scope: this does not make timed atomic waits work in a title. `__std_atomic_wait_direct_8`, `__std_atomic_wait_direct_16` and `__std_atomic_notify_multi_direct` still throw, because no source I found gives their signatures, and they are not touched here. No title's trace or disassembly was used, and neither export was measured on a PS5. The gap is recorded in `docs/dev/debt/libSceLibcInternal.md`. The placeholder count there goes from 40 to 38, while the physical-module map still assigns all 40 inventory NIDs to the module. This consolidates #16145 and #16148, opened by MarrasFederico within a minute of this one, which implement one helper each; as agreed there, those two close as duplicates once this one is reconciled. `pr_overlap` reports no other pull request with the same exports or new files. It does report line conflicts, mainly in that count (#15460, #15577, #15581 and others) and in neighbouring placeholders (#15657), so whichever merges second has to resolve them. I will rebase this one as needed. Seven pull requests that already conflict with `main` could not be compared by the tool (#5021, #13486, #13778, #13782, #14212, #14664, #15899); their diffs do not mention these helpers. ### 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, MinGW-w64 GCC (WinLibs), Release build. No title or homebrew, and not built on Linux. - `guest_libc_internal_atomic_wait_deadline` (new) passes 3 runs out of 3 at the current head. It covers the no-deadline and no-timeout values, a zero timeout, a deadline expiring after a sleep, unsigned wrap, and the ten-day cap above, at and below the limit. The deadline and the time left are bounded by the test's own `GetTickCount64` / `CLOCK_MONOTONIC` readings taken before and after each call, taken from #16145 and #16148. - At the first head, which used `std::chrono::steady_clock`, removing the cap, the no-deadline check or the expiry check each made the test fail with the matching message. These mutations were not repeated after the clock change. - At the first head: full build, then `ctest --parallel 5 -E '^guest_thermal_sensors$'` (that test hard-freezes this PC, see #16061): of 4209 tests, 3316 pass, 884 skip and 9 fail. The skips include 867 AGC tests, which this build leaves out with `ANYPS5_AGC_EXECUTION_TESTS`. Of the 9 failures, 4 pass when re-run alone (`select_tests_SelectArgumentTests`, one `trace_digest` test, `agc_graphics_profile_draw`, `guest_timed_wait_cpu`). The other 5 are in Python tooling tests this change does not touch: `test_registration` and `select_tests_MissingCommandTests` (`os.symlink` needs a privilege this account lacks), `debt_split` (temp folder inside the repository), `title_run` (a window-ordering check) and one `trace_digest` timeout. They were not compared with `main`. ### 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 🤖 Generated with [Claude Code](https://claude.com/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!16146
No description provided.