libkernel: implement _umtx_op #414
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!414
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/414/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MehmetCambaz on GitHub · 2026-08-30 10:01 UTC · original
<html>MehmetCambaz:feat/umtx-op→main· +129 −0 · 1 files · 1 commits · closed without mergingProblem
Sony's libkernel exports FreeBSD's
_umtx_opand nothing in the tree implements it. Every blocking pthread wait and every wake is built on this one call, so a title whose threads contend on anything at all makes no progress.PAC-MAN WORLD 2 Re-PAC (PPSA18189, reported in #411) called it around 15,000 times a second from two of its own modules and never rendered a frame: no shader translated, no draw submitted, and the graphics thread parked on flip and end-of-pipe queues that timed out forever.
This is the answer to your question on #411 — it is not the dump, and it is not AGC v13. With this implemented the title reaches its 3D scenes and holds 60 fps on
4498d75:How it was identified
Not guessed. The unresolved import stub was made to report its caller, that code page was read back out of guest memory and disassembled, and the wrapper around the call turned out to validate a timespec, pass operation 2, and return 60 on an expired timeout:
UMTX_OP_WAIT,UMTX_OP_WAKE, andETIMEDOUT— whichPOSIX_ETIMEDOUTinerrno.halready spells as 60. The name_umtx_opthen hashes to the imported NID exactly.Three decisions worth reviewing
A wake never wakes exactly one waiter. Buckets are shared between addresses, so waking one could wake a waiter on a neighbouring address and leave the intended thread asleep. A spurious wakeup costs a recheck; a missed one is a hang.
Waits are bounded even when the guest asks for an unbounded one. A wake raised before its wait began cannot be recovered, and the objects seen in practice hold their compare value at zero on both sides of a wake. Leaving the wait unbounded reproducibly hung the title before its first frame.
An unimplemented operation reports success, not an error. That is exactly what the unresolved stub did before, so a title reaching one behaves as it does today rather than meeting a new failure. The log names it once.
Risk to titles that already work
A title that never calls
_umtx_opis untouched — the only additions are one entry in the Posix table and a static array of buckets. Tetris Forever makes 0 calls to it, and its flips and draw counts are unchanged.Test plan
Windows 11 25H2, clang-cl 20.1.8, RTX 2060, on
4498d75.ctest: 35/35.AI use
Written with AI assistance (Claude). It instrumented the import stub, disassembled the guest caller, wrote the implementation, and ran the builds and measurements on my machine. I reviewed the diff and the results.
</html>ProblemSony's libkernel exports FreeBSD's _umtx_op and nothing in the tree implements it. Every blocking pthread wait and every wake is built on this one call, so a title whose threads contend on anything at all makes no progress.
PAC-MAN WORLD 2 Re-PAC (PPSA18189, reported in #411) called it around 15,000 times a second from two of its own modules and never rendered a frame: no shader translated, no draw submitted, and the graphics thread parked on flip and end-of-pipe queues that timed out forever.
This is the answer to your question on #411 — it is not the dump, and it is not AGC v13. With this implemented the title reaches its 3D scenes and holds 60 fps on
4498d75:draws (prim_type) 0 27,891
flips 0 11,161
equeue timeouts 276 20
How it was identified
Not guessed. The unresolved import stub was made to report its caller, that code page was read back out of guest memory and disassembled, and the wrapper around the call turned out to validate a timespec, pass operation 2, and return 60 on an expired timeout:
70b: cmpq $0x0,(%r8) ; validate timespec.tv_sec
718: jle 0x72c
71a: movl $0x2,%esi ; op = 2
72c: movl $0x3c,%eax ; return 60
UMTX_OP_WAIT, UMTX_OP_WAKE, and ETIMEDOUT — which POSIX_ETIMEDOUT in errno.h already spells as 60. The name _umtx_op then hashes to the imported NID exactly.
Three decisions worth reviewing
A wake never wakes exactly one waiter. Buckets are shared between addresses, so waking one could wake a waiter on a neighbouring address and leave the intended thread asleep. A spurious wakeup costs a recheck; a missed one is a hang.
Waits are bounded even when the guest asks for an unbounded one. A wake raised before its wait began cannot be recovered, and the objects seen in practice hold their compare value at zero on both sides of a wake. Leaving the wait unbounded reproducibly hung the title before its first frame.
An unimplemented operation reports success, not an error. That is exactly what the unresolved stub did before, so a title reaching one behaves as it does today rather than meeting a new failure. The log names it once.
Risk to titles that already work
A title that never calls _umtx_op is untouched — the only additions are one entry in the Posix table and a static array of buckets. Tetris Forever makes 0 calls to it, and its flips and draw counts are unchanged.
Test plan
Windows 11 25H2, clang-cl 20.1.8, RTX 2060, on
4498d75.ctest: 35/35.
PAC-MAN WORLD 2 Re-PAC: black screen → 3D scenes at 60 fps.
Tetris Forever: 0 calls, no change in behaviour, no errors.
No new test — this is a blocking primitive whose effect is only observable in a real title.
AI use
Written with AI assistance (Claude). It instrumented the import stub, disassembled the guest caller, wrote the implementation, and ran the builds and measurements on my machine. I reviewed the diff and the results.
Pull request closed