feat(ult): implement blocking queues and shared data pools #613

Merged
nicolasabosch merged 2 commits from upstream-pr/613 into main 2026-10-05 05:06:20 +00:00
nicolasabosch commented 2026-10-05 03:52:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-05T03:52:33Z.


What

sceUltQueuePush previously returned success when a queue was full and discarded the new item. It now waits for a free slot, and sceUltQueuePop waits for data. Add sceUltQueueTryPush, sceUltQueueDestroy, and sceUltQueueDataResourcePoolDestroy; retain nonblocking empty-queue errors through sceUltQueueTryPop.

Queues share a preallocated pool of payload slots instead of each receiving the pool's entire capacity. Enforce the queue-object limit, validate sizes and duplicate creation, check work-area size arithmetic for overflow, reclaim slots on destruction, and wake blocked callers during finalization. Separate notifications for queue data and pool capacity avoid waking unrelated consumers.

Non-null queue and data-pool option parameters throw rather than being silently ignored. TechnicalDebt records the remaining limits: storage is host-backed, guest work-area/object layouts and inferred PS5 signatures/error/teardown behavior are unverified, and waiting-pool thread limits and waiter priority ordering are not implemented.

Tested

Windows, MinGW-w64 GCC 15.2.0:

  • Full build and libs target, including PRX NID patching, passed.
  • Full CTest suite: 247/247 passed.
  • Six queue tests passed three consecutive runs after the final test/linking changes: validation and unsupported options, FIFO and copy bounds, blocking producer/consumer wakeups, shared-pool exhaustion and slot reclamation, finalization and recreation, and four producers/four consumers delivering 8,000 distinct items exactly once.
  • A separate reproducer built against origin/main confirmed the full-queue push returned success immediately; with this implementation it blocks and finalization wakes it with ULT_ERROR_STATE.
  • git diff --check passed. No game title, PS5 hardware, or Linux runtime was tested.

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); remaining queue limitations are recorded in TechnicalDebt
  • No investigation notes, logs, images, or reports added to the repository
  • No new third-party code
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4739965979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/613). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-05T03:52:33Z. --- ### What `sceUltQueuePush` previously returned success when a queue was full and discarded the new item. It now waits for a free slot, and `sceUltQueuePop` waits for data. Add `sceUltQueueTryPush`, `sceUltQueueDestroy`, and `sceUltQueueDataResourcePoolDestroy`; retain nonblocking empty-queue errors through `sceUltQueueTryPop`. Queues share a preallocated pool of payload slots instead of each receiving the pool's entire capacity. Enforce the queue-object limit, validate sizes and duplicate creation, check work-area size arithmetic for overflow, reclaim slots on destruction, and wake blocked callers during finalization. Separate notifications for queue data and pool capacity avoid waking unrelated consumers. Non-null queue and data-pool option parameters throw rather than being silently ignored. TechnicalDebt records the remaining limits: storage is host-backed, guest work-area/object layouts and inferred PS5 signatures/error/teardown behavior are unverified, and waiting-pool thread limits and waiter priority ordering are not implemented. ### Tested Windows, MinGW-w64 GCC 15.2.0: - Full build and `libs` target, including PRX NID patching, passed. - Full CTest suite: 247/247 passed. - Six queue tests passed three consecutive runs after the final test/linking changes: validation and unsupported options, FIFO and copy bounds, blocking producer/consumer wakeups, shared-pool exhaustion and slot reclamation, finalization and recreation, and four producers/four consumers delivering 8,000 distinct items exactly once. - A separate reproducer built against `origin/main` confirmed the full-queue push returned success immediately; with this implementation it blocks and finalization wakes it with `ULT_ERROR_STATE`. - `git diff --check` passed. No game title, PS5 hardware, or Linux runtime was tested. ### 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 (`NotImplemented_nid_no_patch`); remaining queue limitations are recorded in TechnicalDebt - [x] No investigation notes, logs, images, or reports added to the repository - [x] No new third-party code - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-05 03:52:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T03:52:56Z.


Progress report (4dac9d6 → 043332b)

📉 System libraries: 79.01% (-0.03%, +4 implemented, -2 reverted functions)

✅ 4 implemented
Library Name
libSceUlt sceUltQueueDataResourcePoolDestroy
libSceUlt sceUltQueueDestroy
libSceUlt sceUltQueuePop
libSceUlt sceUltQueueTryPush
⚠️ 2 went back to stubs
Library Name
libSceUlt sceUltQueueCreate
libSceUlt sceUltQueueDataResourcePoolCreate
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5987793895 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/613#issuecomment-5987793895). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T03:52:56Z. --- <!-- progress-report --> ### Progress report (4dac9d6 → 043332b) 📉 **System libraries**: 79.01% (-0.03%, +4 implemented, -2 reverted functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libSceUlt | `sceUltQueueDataResourcePoolDestroy` | | libSceUlt | `sceUltQueueDestroy` | | libSceUlt | `sceUltQueuePop` | | libSceUlt | `sceUltQueueTryPush` | </details> <details> <summary>⚠️ 2 went back to stubs</summary> | Library | Name | | - | - | | libSceUlt | `sceUltQueueCreate` | | libSceUlt | `sceUltQueueDataResourcePoolCreate` | </details>
oneandonlydean commented 2026-10-05 05:03:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:03:56Z.


Thanks, this fixes a real problem: a full queue used to drop the item and still report success. I read it through with the threading in mind:

  • Ulthreads here are host threads (scePthreadCreate), so blocking on a condition variable is right.
  • The lock order is always gMutex first, then the pool mutex.
  • _waiters is only changed under the pool mutex, and a queue destroyed or finalized while a caller is between queueGetState and the lock is caught by the _alive check.
  • The shared pointers keep the pool and the queue alive for a waiter woken by sceUltFinalize.
  • Push waiters of any queue share the pool's _spaceAvailable, which is right because any free slot will do, and destroying a queue wakes them all.
  • The free list and the per-queue lists look right, and copies use the queue's own dataSize inside the pool's stride.

sceUltQueuePop, sceUltQueueTryPush, sceUltQueueDestroy and sceUltQueueDataResourcePoolDestroy are real libSceUlt exports (all four names are in the usual NID lists). Their argument lists and error rules are inferred, and the TechnicalDebt lines say so.

The six guest_ult_queue_* tests pass here on Linux (GCC, Release). I also ran them 25 times in a row with --repeat until-fail and -j6, with no failures. The full ctest passes with this merged. On main, guest_ult_queue_tests doesn't link, since the three new functions are missing. I also checked the second commit: it only moves the TechnicalDebt line to the end of its section, and the code is unchanged.

PPSA21564 doesn't import libSceUlt, so this doesn't need my PPSA21564 check. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988441345 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/613#issuecomment-5988441345). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:03:56Z. --- Thanks, this fixes a real problem: a full queue used to drop the item and still report success. I read it through with the threading in mind: - Ulthreads here are host threads (`scePthreadCreate`), so blocking on a condition variable is right. - The lock order is always `gMutex` first, then the pool mutex. - `_waiters` is only changed under the pool mutex, and a queue destroyed or finalized while a caller is between `queueGetState` and the lock is caught by the `_alive` check. - The shared pointers keep the pool and the queue alive for a waiter woken by `sceUltFinalize`. - Push waiters of any queue share the pool's `_spaceAvailable`, which is right because any free slot will do, and destroying a queue wakes them all. - The free list and the per-queue lists look right, and copies use the queue's own `dataSize` inside the pool's stride. `sceUltQueuePop`, `sceUltQueueTryPush`, `sceUltQueueDestroy` and `sceUltQueueDataResourcePoolDestroy` are real libSceUlt exports (all four names are in the usual NID lists). Their argument lists and error rules are inferred, and the TechnicalDebt lines say so. The six `guest_ult_queue_*` tests pass here on Linux (GCC, Release). I also ran them 25 times in a row with `--repeat until-fail` and `-j6`, with no failures. The full ctest passes with this merged. On main, `guest_ult_queue_tests` doesn't link, since the three new functions are missing. I also checked the second commit: it only moves the TechnicalDebt line to the end of its section, and the code is unchanged. PPSA21564 doesn't import libSceUlt, so this doesn't need my PPSA21564 check. Ready to merge from my side.
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!613
No description provided.