fix(libkernel): return timeout on zero usec in AIO wait #13224

Closed
fogydes wants to merge 1 commit from upstream-pr/13224 into main
fogydes commented 2026-10-30 07:05:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-30T07:05:47Z.


What

In sceKernelAioWaitRequests and sceKernelAioWaitRequest (core/libs/prx/libkernel/Aio/src/Aio.cpp:383,414), evaluate the elapsed timeout whenever usec != nullptr, checking elapsed >= static_cast<std::int64_t>(*usec).

Previously, timeout handling was guarded by if (usec != nullptr && *usec != 0). While shadPS4 skips its timeout check when *usec == 0 (treating zero like an indefinite wait), AnyPS5 distinguishes a null timeout pointer (usec == nullptr, indefinite wait) from a pointer to zero (*usec == 0, immediate poll returning SCE_KERNEL_ERROR_ETIMEDOUT when requests remain in AioProcessing, without entering PreciseSleepUs). This is adopted as an intentional host policy pending PS5 console measurement or library disassembly, and is documented in docs/dev/debt/libkernel.md. The positive-timeout boundary check also changes from > to >= static_cast<std::int64_t>(*usec), expiring immediately once the elapsed deadline is reached rather than waiting through an additional iteration at exact equality.

Test coverage in core/libs/tests/GuestAioRegistry.cpp is extended to verify:

  • Zero-timeout wait on pending requests returns SCE_KERNEL_ERROR_ETIMEDOUT and reports state 2 (AioProcessing).
  • Zero-timeout wait on completed requests returns 0 (success) and reports completion state, verifying that completion is checked before timeout evaluation.
  • Mixed pending and completed requests at zero timeout: mode AioWaitAnd returns SCE_KERNEL_ERROR_ETIMEDOUT, while mode AioWaitOr returns 0 (success) upon finding an already completed request.
  • The existing null-pointer indefinite-wait thread test is retained without duration assertions.

Tested

Windows 11, ctest --test-dir build -R "guest_aio" -V passed 100% (8/8 tests passed, 5/5 repetitions clean). python tools/check_conventions.py --base origin/main passed with 0 findings. python tools/pr_overlap.py --branch fix/libkernel-aio-zero-timeout passed cleanly across all 1518 open pull requests (1 expected overlap with PR #7121 on Aio.cpp).

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:5080769532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13224). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-30T07:05:47Z. --- ### What In `sceKernelAioWaitRequests` and `sceKernelAioWaitRequest` (`core/libs/prx/libkernel/Aio/src/Aio.cpp:383,414`), evaluate the elapsed timeout whenever `usec != nullptr`, checking `elapsed >= static_cast<std::int64_t>(*usec)`. Previously, timeout handling was guarded by `if (usec != nullptr && *usec != 0)`. While shadPS4 skips its timeout check when `*usec == 0` (treating zero like an indefinite wait), AnyPS5 distinguishes a null timeout pointer (`usec == nullptr`, indefinite wait) from a pointer to zero (`*usec == 0`, immediate poll returning `SCE_KERNEL_ERROR_ETIMEDOUT` when requests remain in `AioProcessing`, without entering `PreciseSleepUs`). This is adopted as an intentional host policy pending PS5 console measurement or library disassembly, and is documented in `docs/dev/debt/libkernel.md`. The positive-timeout boundary check also changes from `>` to `>= static_cast<std::int64_t>(*usec)`, expiring immediately once the elapsed deadline is reached rather than waiting through an additional iteration at exact equality. Test coverage in `core/libs/tests/GuestAioRegistry.cpp` is extended to verify: - Zero-timeout wait on pending requests returns `SCE_KERNEL_ERROR_ETIMEDOUT` and reports state `2` (`AioProcessing`). - Zero-timeout wait on completed requests returns `0` (success) and reports completion state, verifying that completion is checked before timeout evaluation. - Mixed pending and completed requests at zero timeout: mode `AioWaitAnd` returns `SCE_KERNEL_ERROR_ETIMEDOUT`, while mode `AioWaitOr` returns `0` (success) upon finding an already completed request. - The existing null-pointer indefinite-wait thread test is retained without duration assertions. ### 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, `ctest --test-dir build -R "guest_aio" -V` passed 100% (8/8 tests passed, 5/5 repetitions clean). `python tools/check_conventions.py --base origin/main` passed with 0 findings. `python tools/pr_overlap.py --branch fix/libkernel-aio-zero-timeout` passed cleanly across all 1518 open pull requests (1 expected overlap with PR #7121 on `Aio.cpp`). ### 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
CnRJay commented 2026-11-01 19:49:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:42Z.

Review: COMMENTED


Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.

  1. No title ID or log line. "Unblocks: none", and nothing shows a title calling sceKernelAioWaitRequest(s) with a pointer to a zero timeout on main. Please add the title and the log line that reaches it.

  2. This is a guess recorded as policy. The body says a zero timeout returning ETIMEDOUT immediately is "adopted as an intentional host policy pending PS5 console measurement or library disassembly", and the > to >= change has no stated source at all. Before this PR a pointer to zero waited indefinitely; after it, the same call returns a timeout. Both cannot be right for a guest that passes 0, and neither is backed by firmware behaviour. If the general behaviour is unknown the project rule is to throw and record it in docs/dev/debt/libkernel.md, not to pick the opposite behaviour and note it as debt. Please cite the firmware disassembly of sceKernelAioWaitRequests (what it does with *usec == 0), or drop the zero-timeout change.

  3. The >= change is not tied to anything. At exact equality the old code loops once more and the new code returns; no input in the tests distinguishes the two (the new tests all use 0). Either show a test where elapsed == *usec is observable, or leave the comparison alone.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729923118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13224#pullrequestreview-5729923118). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:42Z. **Review:** COMMENTED --- **Correction (2026-11-01):** the title-ID/log demand below is not a CONTRIBUTING requirement; `Unblocks: none` is allowed. The technical points below are unaffected. 1. **No title ID or log line.** "Unblocks: none", and nothing shows a title calling `sceKernelAioWaitRequest(s)` with a pointer to a zero timeout on main. Please add the title and the log line that reaches it. 2. **This is a guess recorded as policy.** The body says a zero timeout returning `ETIMEDOUT` immediately is "adopted as an intentional host policy pending PS5 console measurement or library disassembly", and the `>` to `>=` change has no stated source at all. Before this PR a pointer to zero waited indefinitely; after it, the same call returns a timeout. Both cannot be right for a guest that passes 0, and neither is backed by firmware behaviour. If the general behaviour is unknown the project rule is to throw and record it in `docs/dev/debt/libkernel.md`, not to pick the opposite behaviour and note it as debt. Please cite the firmware disassembly of `sceKernelAioWaitRequests` (what it does with `*usec == 0`), or drop the zero-timeout change. 3. **The `>=` change is not tied to anything.** At exact equality the old code loops once more and the new code returns; no input in the tests distinguishes the two (the new tests all use 0). Either show a test where `elapsed == *usec` is observable, or leave the comparison alone.

Pull request closed

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!13224
No description provided.