perf(libkernel): shard SyncOnAddress waiters across hashed buckets #2528

Merged
FitzVB merged 2 commits from upstream-pr/2528 into main 2026-10-21 14:39:41 +00:00
FitzVB commented 2026-10-10 01:48:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by FitzVB on 2026-10-10T01:48:15Z.


What

sceKernelSyncOnAddressWait / Wake currently share one mutex for every address. Unrelated waiters serialize on that lock even when they never share a key.

This keeps the existing waiter queues and wake semantics, and hashes each address into one of 64 cache-line-aligned buckets so wait and wake on different addresses can proceed in parallel.

Complementary to #1482: that change reuses this waiter queue for _umtx_op. This PR does not implement _umtx_op.

Tested

Windows 10, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON.

  • guest_sync_on_address: passed (1.17 s)
  • python3 tools/check_conventions.py --base upstream/main: passed

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4807794931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528). Originally posted by [FitzVB](https://github.com/FitzVB) on 2026-10-10T01:48:15Z. --- ### What `sceKernelSyncOnAddressWait` / `Wake` currently share one mutex for every address. Unrelated waiters serialize on that lock even when they never share a key. This keeps the existing waiter queues and wake semantics, and hashes each address into one of 64 cache-line-aligned buckets so wait and wake on different addresses can proceed in parallel. Complementary to #1482: that change reuses this waiter queue for `_umtx_op`. This PR does not implement `_umtx_op`. ### Tested Windows 10, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release, `BUILD_TESTING=ON`. - `guest_sync_on_address`: passed (1.17 s) - `python3 tools/check_conventions.py --base upstream/main`: passed ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-10 01:54:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T01:54:34Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092411287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6092411287). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T01:54:34Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
oneandonlydean commented 2026-10-17 23:57:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:57:50Z.


Thanks for reopening this. It no longer merges cleanly into current main. Could you rebase onto current main? SyncOnAddress still uses one global lock on main, so sharding the waiters is still wanted. We'll review and run full CI on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243431261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6243431261). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T23:57:50Z. --- Thanks for reopening this. It no longer merges cleanly into current main. Could you rebase onto current main? SyncOnAddress still uses one global lock on main, so sharding the waiters is still wanted. We'll review and run full CI on the new head.
Aryansh1520 commented 2026-10-20 09:36:50 +00:00 (Migrated from github.com)

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


Thanks @FitzVB for the bucket design in this PR. A new PR, #8304, adds UMTX_OP_SEM_WAIT and UMTX_OP_SEM_WAKE in SyncOnAddress.cpp, and it touches the same waiter queue this PR shards.

What #8304 needs from the queue, so the two merge cleanly:

  • WaitOnKeyLocked and WaitOnKeyUntil take a readiness callable, and WaitOnAddressUntil uses them with the value check. A semaphore wait supplies its own check on _count.
  • WakeSemaphoreLocked reads the waiter count for a key, and it clears _has_waiters when exactly one waiter is queued. That count is the bucket's queue length, so it must come from the bucket for the key.

Whichever merges second should rebase onto the other. The sharded version should keep the per-key queue and the readiness callable as they are.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287997153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6287997153). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T09:36:50Z. --- Thanks @FitzVB for the bucket design in this PR. A new PR, #8304, adds `UMTX_OP_SEM_WAIT` and `UMTX_OP_SEM_WAKE` in `SyncOnAddress.cpp`, and it touches the same waiter queue this PR shards. What #8304 needs from the queue, so the two merge cleanly: - `WaitOnKeyLocked` and `WaitOnKeyUntil` take a readiness callable, and `WaitOnAddressUntil` uses them with the value check. A semaphore wait supplies its own check on `_count`. - `WakeSemaphoreLocked` reads the waiter count for a key, and it clears `_has_waiters` when exactly one waiter is queued. That count is the bucket's queue length, so it must come from the bucket for the key. Whichever merges second should rebase onto the other. The sharded version should keep the per-key queue and the readiness callable as they are.
github-actions[bot] commented 2026-10-20 09:38:59 +00:00 (Migrated from github.com)

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


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 L135-139, L149-150
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288033545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6288033545). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T09:38:59Z. --- <!-- 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` [L135-139](https://github.com/boykopovar/AnyPS5/blob/80565c59424190cd0f660f8097945443a0017c42/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L135-L139), [L149-150](https://github.com/boykopovar/AnyPS5/blob/80565c59424190cd0f660f8097945443a0017c42/core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp#L149-L150) | | |
Aryansh1520 commented 2026-10-20 10:00:08 +00:00 (Migrated from github.com)

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


Thanks @nahshongraham97 for the sharding. Its change is now ported onto the semaphore branch in #8304 (commit e3eb745c9), with you credited as co-author, and the three queue sites are converted: the wait helper, the address wake and the semaphore wake all use BucketOf(key). guest_umtx_op passes on the port.

This leaves #2528 with nothing new to add, so the port is the one to review. Thanks again for the design.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288387397 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6288387397). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T10:00:08Z. --- Thanks @nahshongraham97 for the sharding. Its change is now ported onto the semaphore branch in #8304 (commit `e3eb745c9`), with you credited as co-author, and the three queue sites are converted: the wait helper, the address wake and the semaphore wake all use `BucketOf(key)`. `guest_umtx_op` passes on the port. This leaves #2528 with nothing new to add, so the port is the one to review. Thanks again for the design.
Aryansh1520 commented 2026-10-20 10:05:39 +00:00 (Migrated from github.com)

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


Correction to my earlier note: the sharding is not in #8304 any more. It is ported onto current main in #8323, with you credited as co-author, because CONTRIBUTING asks for one topic per PR. #2528 is left open for you, and #8323 is the one to review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288478723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6288478723). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-20T10:05:39Z. --- Correction to my earlier note: the sharding is not in #8304 any more. It is ported onto current `main` in #8323, with you credited as co-author, because CONTRIBUTING asks for one topic per PR. #2528 is left open for you, and #8323 is the one to review.
blawesom commented 2026-10-21 05:06:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-21T05:06:45Z.


Heads-up (support triage): #8323 ("refactor(libkernel): shard SyncOnAddress waiters across hashed buckets", Aryansh1520, opened 2026-10-20) changes SyncOnAddress/src/SyncOnAddress.cpp with content identical to this PR — same bucket/shard hunks, byte-for-byte. Your PR is 10 days older; the other author has been pointed here. Please agree which one lands first and declare it with Depends on on the checklist line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308522493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6308522493). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-21T05:06:45Z. --- Heads-up (support triage): #8323 ("refactor(libkernel): shard SyncOnAddress waiters across hashed buckets", Aryansh1520, opened 2026-10-20) changes `SyncOnAddress/src/SyncOnAddress.cpp` with content identical to this PR — same bucket/shard hunks, byte-for-byte. Your PR is 10 days older; the other author has been pointed here. Please agree which one lands first and declare it with `Depends on` on the checklist line.
Aryansh1520 commented 2026-10-21 09:16:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-21T09:16:31Z.


@oneandonlydean as requested, here is the rebase of this change onto current main:

The only file changed is core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp. The port maps the three queue sites (wait, address wake, semaphore wake) onto the same 64 buckets, using the key's bucket for each. ctest -R '^guest_umtx_op$' passes and tools/check_conventions.py --base origin/main is clean on that commit.

Use it however suits this PR. @FitzVB, this is for your review as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312438067 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6312438067). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-21T09:16:31Z. --- @oneandonlydean as requested, here is the rebase of this change onto current `main`: - Branch: https://github.com/Aryansh1520/AnyPS5/tree/perf/libkernel-sync-on-address-buckets - Commit: `2e35702df` (one commit on top of `f894ba69d`), with nahshongraham97 kept as co-author. The only file changed is `core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp`. The port maps the three queue sites (wait, address wake, semaphore wake) onto the same 64 buckets, using the key's bucket for each. `ctest -R '^guest_umtx_op$'` passes and `tools/check_conventions.py --base origin/main` is clean on that commit. Use it however suits this PR. @FitzVB, this is for your review as well.
oneandonlydean commented 2026-10-21 10:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T10:09:28Z.


@FitzVB @Aryansh1520 thanks. 2e35702df is a clean port. The three queue sites (wait, address wake, semaphore wake) each lock BucketOf(key) for their one key, and nothing works on two keys under one lock. The semaphore's hasWaiters flag is set in the wait's readiness check and cleared in the wake, both under the semaphore address's bucket, so they stay serialised as before. Main hasn't touched SyncOnAddress.cpp since its base.

We'll carry it here by merging current main into this branch with SyncOnAddress.cpp taken from 2e35702df. nahshongraham97 keeps the commit, and Aryan Sharma is credited with a Co-authored-by line on the merge. Full CI runs on the result before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313422005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6313422005). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T10:09:28Z. --- @FitzVB @Aryansh1520 thanks. `2e35702df` is a clean port. The three queue sites (wait, address wake, semaphore wake) each lock `BucketOf(key)` for their one key, and nothing works on two keys under one lock. The semaphore's `hasWaiters` flag is set in the wait's readiness check and cleared in the wake, both under the semaphore address's bucket, so they stay serialised as before. Main hasn't touched `SyncOnAddress.cpp` since its base. We'll carry it here by merging current `main` into this branch with `SyncOnAddress.cpp` taken from `2e35702df`. nahshongraham97 keeps the commit, and Aryan Sharma is credited with a `Co-authored-by` line on the merge. Full CI runs on the result before merge.
github-actions[bot] commented 2026-10-21 13:22:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T13:22:07Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6317144128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2528#issuecomment-6317144128). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T13:22:07Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
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!2528
No description provided.