libkernel: guest_raise_exception exceeds its 30 s budget on Windows; 14.8 s of it is raises on a thread looping in sceKernelSyncOnAddressWake #9610

Closed
opened 2026-10-22 04:15:52 +00:00 by JJenkx · 1 comment
JJenkx commented 2026-10-22 04:15:52 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:15:52Z.


Observed

On main at d9c99c9ba4, guest_raise_exception times out at its 30 s TIMEOUT in most runs on this Windows machine:

  • Ryzen 9 5950X, Windows 11 22621, WinLibs GCC 15.2.0 UCRT r7, Release.
  • Under ctest it timed out in 5 of 6 runs alone and in 2 of 3 runs alongside five other tests. The one ctest pass also took 30 s.
  • Run outside ctest it passes, in 35.6 s and 37.4 s.

So the test doesn't hang. It needs more than its budget here, even after cd2fd50f0c halved its rounds.

Where the time goes

I timestamped the test's RunThread lines and mapped each thread entry to its function with nm. The run took 34.9 s:

Scenario Threads Time
HandlerLeavesAddressLock(AddressWaking, …) 1 14.8 s (50 rounds, ~300 ms per raise)
Starting 50 5.3 s (round gap: median 62 ms, p90 262 ms, max 726 ms)
Continuing 1 3.0 s
Selfing 1 2.8 s
Leaving 1 1.6 s
LockBlocked (3 lock kinds) 3 1.4 s
WaitSemaOnce 3 1.3 s
Looping 1 1.0 s
HostBlocked, Waiting, Vectors, Busy 1 each 0.9, 0.8, 0.8, 0.6 s
HandlerLeavesAddressLock(AddressWaiting, …) 1 0.55 s (50 rounds)

AddressWaking loops on sceKernelSyncOnAddressWake, so nearly every time sceKernelRaiseException samples it, the thread is inside a system call. In the Windows delivery loop (System/src/Exception.cpp), each such sample moves hostDeadline to now + HostCodeLimit (50 ms), up to RetryLimit (1 s):

if (running == CodeKind::Host && InSystemCall(delivery.context.Rip, image) && now < retryDeadline) hostDeadline = std::max(hostDeadline, std::min(retryDeadline, now + HostCodeLimit));

So delivery waits until a sample happens to land in the thread's short stretch of guest code between two wakes, or until the 1 s limit. That costs about 300 ms per raise here. AddressWaiting spends its time in a 20 µs timed wait and costs about 11 ms per round. I assume that is because a waiting thread takes the waitCount APC path, but I haven't traced it.

Open question

Two readings are possible, and the choice belongs to the owners of 681926e085 and #8512:

  • This wait is intended: then AddressRounds (50) or the 30 s budget doesn't fit a scenario that costs up to 1 s per round by design.
  • It isn't: then a raise on a thread that keeps re-entering a system call waits longer than intended.

I haven't changed anything, and I can rerun with any proposed change on this machine.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5972946042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9610). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:15:52Z. --- ### Observed On `main` at d9c99c9ba4, `guest_raise_exception` times out at its 30 s `TIMEOUT` in most runs on this Windows machine: - Ryzen 9 5950X, Windows 11 22621, WinLibs GCC 15.2.0 UCRT r7, Release. - Under ctest it timed out in 5 of 6 runs alone and in 2 of 3 runs alongside five other tests. The one ctest pass also took 30 s. - Run outside ctest it passes, in 35.6 s and 37.4 s. So the test doesn't hang. It needs more than its budget here, even after cd2fd50f0c halved its rounds. ### Where the time goes I timestamped the test's `RunThread` lines and mapped each thread entry to its function with `nm`. The run took 34.9 s: | Scenario | Threads | Time | |---|---|---| | `HandlerLeavesAddressLock(AddressWaking, …)` | 1 | **14.8 s** (50 rounds, ~300 ms per raise) | | `Starting` | 50 | 5.3 s (round gap: median 62 ms, p90 262 ms, max 726 ms) | | `Continuing` | 1 | 3.0 s | | `Selfing` | 1 | 2.8 s | | `Leaving` | 1 | 1.6 s | | `LockBlocked` (3 lock kinds) | 3 | 1.4 s | | `WaitSemaOnce` | 3 | 1.3 s | | `Looping` | 1 | 1.0 s | | `HostBlocked`, `Waiting`, `Vectors`, `Busy` | 1 each | 0.9, 0.8, 0.8, 0.6 s | | `HandlerLeavesAddressLock(AddressWaiting, …)` | 1 | 0.55 s (50 rounds) | `AddressWaking` loops on `sceKernelSyncOnAddressWake`, so nearly every time `sceKernelRaiseException` samples it, the thread is inside a system call. In the Windows delivery loop (`System/src/Exception.cpp`), each such sample moves `hostDeadline` to `now + HostCodeLimit` (50 ms), up to `RetryLimit` (1 s): ```cpp if (running == CodeKind::Host && InSystemCall(delivery.context.Rip, image) && now < retryDeadline) hostDeadline = std::max(hostDeadline, std::min(retryDeadline, now + HostCodeLimit)); ``` So delivery waits until a sample happens to land in the thread's short stretch of guest code between two wakes, or until the 1 s limit. That costs about 300 ms per raise here. `AddressWaiting` spends its time in a 20 µs timed wait and costs about 11 ms per round. I assume that is because a waiting thread takes the `waitCount` APC path, but I haven't traced it. ### Open question Two readings are possible, and the choice belongs to the owners of 681926e085 and #8512: - **This wait is intended:** then `AddressRounds` (50) or the 30 s budget doesn't fit a scenario that costs up to 1 s per round by design. - **It isn't:** then a raise on a thread that keeps re-entering a system call waits longer than intended. I haven't changed anything, and I can rerun with any proposed change on this machine. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 13:16:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:16:34Z.


I checked the current main implementation (3ca07d086d5f44fbe3c00370e7f03953ab46ca1b). The merged #8512 HostCodeLimit does not cap this AddressWaking path at 50 ms: when the sampled host RIP is inside a system call, RaiseOn extends hostDeadline by another 50 ms, up to the 1 s retryDeadline (the condition at Exception.cpp around line 444). That matches the distinction in #8512 between ordinary host code and system-call/throw paths, and is consistent with your measured per-raise delay. The test timeout is still objectively flaky on the reported Windows host. I would keep this open for the named owners to decide whether the wait is required; if it is, the timeout/round count needs to account for that path, while a behavior change needs a Windows regression showing the raise remains safe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341705716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9610#issuecomment-6341705716). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T13:16:34Z. --- I checked the current `main` implementation (`3ca07d086d5f44fbe3c00370e7f03953ab46ca1b`). The merged #8512 `HostCodeLimit` does not cap this `AddressWaking` path at 50 ms: when the sampled host RIP is inside a system call, `RaiseOn` extends `hostDeadline` by another 50 ms, up to the 1 s `retryDeadline` (the condition at `Exception.cpp` around line 444). That matches the distinction in #8512 between ordinary host code and system-call/throw paths, and is consistent with your measured per-raise delay. The test timeout is still objectively flaky on the reported Windows host. I would keep this open for the named owners to decide whether the wait is required; if it is, the timeout/round count needs to account for that path, while a behavior change needs a Windows regression showing the raise remains safe.
Sign in to join this conversation.
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#9610
No description provided.