feat(libkernel): implement _umtx_op UMTX_OP_SEM_WAIT and UMTX_OP_SEM_WAKE #8304

Merged
Aryansh1520 merged 1 commit from upstream-pr/8304 into main 2026-10-20 22:50:35 +00:00
Aryansh1520 commented 2026-10-20 09:36:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-20T09:36:37Z.


What

Implements _umtx_op UMTX_OP_SEM_WAIT (19) and UMTX_OP_SEM_WAKE (20) as FreeBSD 11's do_sem_wait and do_sem_wake (built under COMPAT_FREEBSD9/10, as the console answers them) on struct _usem { _has_waiters, _count, _flags }. A wait sets _has_waiters to 1 when it is 0, returns at once while _count is non-zero, and otherwise sleeps on the semaphore's queue with the timeout read as for UMTX_OP_WAIT. A wake clears _has_waiters when one waiter is left and releases one waiter. The waiter queue now takes a readiness check, so a semaphore wait uses the same queue as sceKernelSyncOnAddressWait. UMTX_OP_SEM2_WAIT and UMTX_OP_SEM2_WAKE still throw.

Overlap: #2528 ("shard SyncOnAddress waiters across hashed buckets", by nahshongraham97) changes the same waiter queue in SyncOnAddress.cpp. Its sharding is ported onto current main in a separate PR, so this PR does not carry it. Whichever of the two merges second rebases onto the other.

The debt entry for _umtx_op is updated to list only what is still open.

Credit: the semaphore behaviour follows FreeBSD 11's kern_umtx.c.

Tested

Linux x86-64 (CachyOS, kernel 7.2.10): the focused guest_umtx_op test passes on the rebased branch (ctest -R '^guest_umtx_op$', 4 new cases for the semaphore operations); tools/check_conventions.py --base origin/main passes. Not tested on a title: no title reached UMTX_OP_SEM_WAIT or UMTX_OP_SEM_WAKE in the runs done here (Sonic Superstars, PPSA06888, stops before it), so this change has no title log yet.

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:4933875646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8304). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T09:36:37Z. --- ### What Implements `_umtx_op` `UMTX_OP_SEM_WAIT` (19) and `UMTX_OP_SEM_WAKE` (20) as FreeBSD 11's `do_sem_wait` and `do_sem_wake` (built under `COMPAT_FREEBSD9`/`10`, as the console answers them) on `struct _usem { _has_waiters, _count, _flags }`. A wait sets `_has_waiters` to 1 when it is 0, returns at once while `_count` is non-zero, and otherwise sleeps on the semaphore's queue with the timeout read as for `UMTX_OP_WAIT`. A wake clears `_has_waiters` when one waiter is left and releases one waiter. The waiter queue now takes a readiness check, so a semaphore wait uses the same queue as `sceKernelSyncOnAddressWait`. `UMTX_OP_SEM2_WAIT` and `UMTX_OP_SEM2_WAKE` still throw. Overlap: #2528 ("shard SyncOnAddress waiters across hashed buckets", by nahshongraham97) changes the same waiter queue in `SyncOnAddress.cpp`. Its sharding is ported onto current `main` in a separate PR, so this PR does not carry it. Whichever of the two merges second rebases onto the other. The debt entry for `_umtx_op` is updated to list only what is still open. Credit: the semaphore behaviour follows FreeBSD 11's `kern_umtx.c`. ### Tested Linux x86-64 (CachyOS, kernel 7.2.10): the focused `guest_umtx_op` test passes on the rebased branch (`ctest -R '^guest_umtx_op$'`, 4 new cases for the semaphore operations); `tools/check_conventions.py --base origin/main` passes. Not tested on a title: no title reached `UMTX_OP_SEM_WAIT` or `UMTX_OP_SEM_WAKE` in the runs done here (Sonic Superstars, PPSA06888, stops before it), so this change has no title log yet. ### 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)
Aryansh1520 commented 2026-10-20 09:36:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-20T09:36:57Z.


This overlaps #2528 ("shard SyncOnAddress waiters across hashed buckets", @FitzVB). Both change the waiter queue in SyncOnAddress.cpp. This PR keeps the single queue and adds the semaphore operations on top of it; #2528 shards that queue. Whichever merges second rebases onto the other. Credit to @FitzVB for the bucket design; the comment on #2528 lists what this PR's queue calls need from a sharded version.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287999160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8304#issuecomment-6287999160). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T09:36:57Z. --- This overlaps #2528 ("shard SyncOnAddress waiters across hashed buckets", @FitzVB). Both change the waiter queue in `SyncOnAddress.cpp`. This PR keeps the single queue and adds the semaphore operations on top of it; #2528 shards that queue. Whichever merges second rebases onto the other. Credit to @FitzVB for the bucket design; the comment on #2528 lists what this PR's queue calls need from a sharded version.
github-actions[bot] commented 2026-10-20 09:45:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T09:45:47Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8725 core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp L75-77, L79-80, L106-107, L110
docs/dev/debt/libkernel.md L56-58

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 2528 core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp
PR 4630 docs/dev/debt/libkernel.md
PR 5021 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestUmtxOp.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6879 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7530 docs/dev/debt/libkernel.md
PR 7532 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8520 docs/dev/debt/libkernel.md
PR 8523 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288148717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8304#issuecomment-6288148717). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T09:45:47Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 8725](https://www.github.com/boykopovar/AnyPS5/pull/8725) | `core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp` [L75-77](https://github.com/boykopovar/AnyPS5/blob/c8301bbca50875f6e939cdb6a971395f6bc13aff/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L75-L77), [L79-80](https://github.com/boykopovar/AnyPS5/blob/c8301bbca50875f6e939cdb6a971395f6bc13aff/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L79-L80), [L106-107](https://github.com/boykopovar/AnyPS5/blob/c8301bbca50875f6e939cdb6a971395f6bc13aff/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L106-L107), [L110](https://github.com/boykopovar/AnyPS5/blob/c8301bbca50875f6e939cdb6a971395f6bc13aff/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L110)<br>`docs/dev/debt/libkernel.md` [L56-58](https://github.com/boykopovar/AnyPS5/blob/c8301bbca50875f6e939cdb6a971395f6bc13aff/docs/dev/debt/libkernel.md#L56-L58) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 2528](https://www.github.com/boykopovar/AnyPS5/pull/2528) | `core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp` | | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestUmtxOp.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `docs/dev/debt/libkernel.md` | | [PR 7532](https://www.github.com/boykopovar/AnyPS5/pull/7532) | `docs/dev/debt/libkernel.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `docs/dev/debt/libkernel.md` | | [PR 8523](https://www.github.com/boykopovar/AnyPS5/pull/8523) | `docs/dev/debt/libkernel.md` |
Aryansh1520 commented 2026-10-20 10:00:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-20T10:00:10Z.


This PR now includes the sharding commit from #2528 (e3eb745c9, credited to @nahshongraham97), ported onto the semaphore queue. That makes it two topics; the PR body says so. The semaphore operations and the sharding touch the same queue, so landing them together avoids a second rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288388037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8304#issuecomment-6288388037). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T10:00:10Z. --- This PR now includes the sharding commit from #2528 (`e3eb745c9`, credited to @nahshongraham97), ported onto the semaphore queue. That makes it two topics; the PR body says so. The semaphore operations and the sharding touch the same queue, so landing them together avoids a second rebase.
Aryansh1520 commented 2026-10-20 10:05:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-20T10:05:42Z.


Correction: the sharding commit was moved out of this PR to #8323 (one topic per PR, per CONTRIBUTING). This PR is the semaphore operations only, and its body is updated to match.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288479449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8304#issuecomment-6288479449). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T10:05:42Z. --- Correction: the sharding commit was moved out of this PR to #8323 (one topic per PR, per CONTRIBUTING). This PR is the semaphore operations only, and its body is updated to match.
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!8304
No description provided.