fix(avplayer): use precise Windows notified waits for EOF polling #1780

Merged
Roojool merged 1 commit from upstream-pr/1780 into main 2026-10-11 09:35:23 +00:00
Roojool commented 2026-10-08 19:04:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-08T19:04:10Z.


What

Windows guest-visible AvPlayer EOF EventStop was delivered up to ~15.6 ms
late (related #1471, partial: this PR covers only the Player::controllerLoop
5 ms poll; other waits named in that issue are out of scope). The loop's
wait_for goes through winpthreads GetTickCount64 steps, so EOF polling
fired late. The event wait now uses libkernel's TimedWait::Condition (precise timed waits on Windows; TimedWait.cpp is built into libSceAvPlayer); queued events and Close still wake immediately. Linux behaviour is unchanged. Adds isolated TestEofStopLatency
(9-sample median under 10 ms, exact-once EventStop, no positive floor).

Overlap: #1601 touches the same test file (GuestAvPlayer.cpp) with
different functions plus Source.cpp, which this PR does not modify; no
function is duplicated, rebase coordination is limited to test-file context.

Tested

Measured by the author on the previous revision (own HostCondition with a waitable timer; the final revision using TimedWait::Condition was not re-measured on Windows). Windows (WinLibs GCC 15.2.0, build-cycle2,
cmake --build build-cycle2 --target guest_avplayer_tests --parallel 2,
ctest --test-dir build-cycle2 -R '^guest_avplayer$'): identical final probe
FAILS on original code (median 13.083 ms, exit 8) and PASSES with the fix
(median 1.396 ms post-rebase; 3x --repeat until-fail:3 medians
1.381/0.959/1.454 ms pre-diagnostic-fix, all PASS). Precision holds with
APS5_NO_TIMER_RESOLUTION=1 (0.541 ms) and APS5_COARSE_TIMED_WAITS=1
(1.199 ms). nid_patcher libSceAvPlayer --preserve-exports on a copy of the
rebuilt unpatched PRX exits 0; all 28 guest exports hashed (spot-checked
sceAvPlayerInit/sceAvPlayerIsActive NIDs independently), 0 plain names
remain. Guest test loads the built unpatched PRX (PE imports
libSceAvPlayer.prx/libc.prx); patched-title execution not run, no
hardware run.
Linux (WSL2 Ubuntu GCC 15.2, /home/roojool/anyps5-avplayer-eof-linux):
same commands, 3x repeats PASS (medians 1.416/0.802/0.908 ms); NID patch of a
PRX copy exits 0 with matching per-symbol addresses.
check_conventions.py --base upstream/main --title ... --body ...,
check_test_registration.py (Windows 409, Linux 412 executables, 3 recorded
not-run), git diff --check: pass. High-resolution timer creation failures
throw; older Windows and Wine were not validated. The 9-sample median reduces
scheduling noise but cannot guarantee timing on an overloaded host.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791524751 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780). Originally posted by [Roojool](https://github.com/Roojool) on 2026-10-08T19:04:10Z. --- ### What Windows guest-visible AvPlayer EOF `EventStop` was delivered up to ~15.6 ms late (related #1471, partial: this PR covers only the `Player::controllerLoop` 5 ms poll; other waits named in that issue are out of scope). The loop's `wait_for` goes through winpthreads `GetTickCount64` steps, so EOF polling fired late. The event wait now uses libkernel's `TimedWait::Condition` (precise timed waits on Windows; `TimedWait.cpp` is built into libSceAvPlayer); queued events and `Close` still wake immediately. Linux behaviour is unchanged. Adds isolated `TestEofStopLatency` (9-sample median under 10 ms, exact-once `EventStop`, no positive floor). Overlap: #1601 touches the same test file (`GuestAvPlayer.cpp`) with different functions plus `Source.cpp`, which this PR does not modify; no function is duplicated, rebase coordination is limited to test-file context. ### Tested Measured by the author on the previous revision (own HostCondition with a waitable timer; the final revision using `TimedWait::Condition` was not re-measured on Windows). Windows (WinLibs GCC 15.2.0, `build-cycle2`, `cmake --build build-cycle2 --target guest_avplayer_tests --parallel 2`, `ctest --test-dir build-cycle2 -R '^guest_avplayer$'`): identical final probe FAILS on original code (median 13.083 ms, exit 8) and PASSES with the fix (median 1.396 ms post-rebase; 3x `--repeat until-fail:3` medians 1.381/0.959/1.454 ms pre-diagnostic-fix, all PASS). Precision holds with `APS5_NO_TIMER_RESOLUTION=1` (0.541 ms) and `APS5_COARSE_TIMED_WAITS=1` (1.199 ms). `nid_patcher libSceAvPlayer --preserve-exports` on a copy of the rebuilt unpatched PRX exits 0; all 28 guest exports hashed (spot-checked `sceAvPlayerInit`/`sceAvPlayerIsActive` NIDs independently), 0 plain names remain. Guest test loads the built unpatched PRX (PE imports `libSceAvPlayer.prx`/`libc.prx`); patched-title execution not run, no hardware run. Linux (WSL2 Ubuntu GCC 15.2, `/home/roojool/anyps5-avplayer-eof-linux`): same commands, 3x repeats PASS (medians 1.416/0.802/0.908 ms); NID patch of a PRX copy exits 0 with matching per-symbol addresses. `check_conventions.py --base upstream/main --title ... --body ...`, `check_test_registration.py` (Windows 409, Linux 412 executables, 3 recorded not-run), `git diff --check`: pass. High-resolution timer creation failures throw; older Windows and Wine were not validated. The 9-sample median reduces scheduling noise but cannot guarantee timing on an overloaded host. ### Checklist - [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 - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-08 19:04:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-08T19:04:16Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5461554971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780#pullrequestreview-5461554971). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-08T19:04:16Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
oneandonlydean commented 2026-10-09 09:22:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:34Z.


Please use libkernel's TimedWait::Condition (prx/libkernel/Time/include/TimedWait.hpp) for eventCondition instead of the new HostMutex/HostCondition in AvPlayer.hpp. It already gives precise timed waits on Windows; #1655 does the same for VideoOut.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078124758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780#issuecomment-6078124758). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:34Z. --- Please use libkernel's `TimedWait::Condition` (`prx/libkernel/Time/include/TimedWait.hpp`) for `eventCondition` instead of the new `HostMutex`/`HostCondition` in `AvPlayer.hpp`. It already gives precise timed waits on Windows; #1655 does the same for VideoOut.
adriadam10 commented 2026-10-10 05:57:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:57:54Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. Two things before this can land:

  • Dean's request above is still open: use libkernel's TimedWait::Condition (core/libs/prx/libkernel/Time/include/TimedWait.hpp) for eventCondition instead of the new HostMutex/HostCondition in AvPlayer.hpp:30-113. It already gives precise timed waits on Windows, and the same approach was taken for VideoOut in #1655. That would also drop the Windows-only code and the second implementation to maintain. Please keep TestEofStopLatency as the regression test for it.
  • The branch conflicts with main in core/libs/tests/GuestAvPlayer.cpp; please rebase (no merge commits) and rerun guest_avplayer.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5477875221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780#pullrequestreview-5477875221). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T05:57:54Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. Two things before this can land: - Dean's request above is still open: use libkernel's `TimedWait::Condition` (`core/libs/prx/libkernel/Time/include/TimedWait.hpp`) for `eventCondition` instead of the new `HostMutex`/`HostCondition` in `AvPlayer.hpp:30-113`. It already gives precise timed waits on Windows, and the same approach was taken for VideoOut in #1655. That would also drop the Windows-only code and the second implementation to maintain. Please keep `TestEofStopLatency` as the regression test for it. - The branch conflicts with `main` in `core/libs/tests/GuestAvPlayer.cpp`; please rebase (no merge commits) and rerun `guest_avplayer`.
adriadam10 commented 2026-10-11 09:30:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:30:25Z.

Review: APPROVED


Rebased onto main and applied the open review points on your branch:

  • eventCondition is now a TimedWait::Condition with WaitUntil(DeadlineNanos(5000), ...); HostMutex/HostCondition and the Windows-only code are gone. TimedWait.cpp is compiled into libSceAvPlayer, since libkernel is not linkable from other libraries.
  • Resolved the conflict in core/libs/tests/GuestAvPlayer.cpp (kept both sides; TestEofStopLatency is kept as the regression test).
  • PR description updated to match.

Checked: scoped build + ctest green, guest_avplayer 5/5 on Linux (Linux uses the condition_variable path, so it does not exercise the Windows timing). The Windows latency of this final revision was not re-measured; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482760781 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780#pullrequestreview-5482760781). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:30:25Z. **Review:** APPROVED --- Rebased onto `main` and applied the open review points on your branch: - `eventCondition` is now a `TimedWait::Condition` with `WaitUntil(DeadlineNanos(5000), ...)`; `HostMutex`/`HostCondition` and the Windows-only code are gone. `TimedWait.cpp` is compiled into libSceAvPlayer, since libkernel is not linkable from other libraries. - Resolved the conflict in `core/libs/tests/GuestAvPlayer.cpp` (kept both sides; `TestEofStopLatency` is kept as the regression test). - PR description updated to match. Checked: scoped build + ctest green, `guest_avplayer` 5/5 on Linux (Linux uses the `condition_variable` path, so it does not exercise the Windows timing). The Windows latency of this final revision was not re-measured; merging.
copilot-pull-request-reviewer[bot] commented 2026-10-11 09:30:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-11T09:30:30Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482761022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1780#pullrequestreview-5482761022). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-11T09:30:30Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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!1780
No description provided.