fix(libkernel): give a raise target time to run between host-code samples #10076
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10076"
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?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T08:36:13Z.
What
On Windows,
sceKernelRaiseException(RaiseOn) suspends the target and reads its context. While the target is in host code, it resumes the target and samples again right afterSwitchToThread(#7652), until the target is back in guest code or the 50 ms host-code limit (#8512) runs out.On this machine the resample came so fast that the target barely ran between samples.
guest_raise_in_host_codethen timed out at 30 s on every run ofmain, including on its own (3 of 3,ctest -R ^guest_raise_in_host_code$).With a local
fprintfat the delivery decision (not part of this PR), in the raise that hung:ucrtbase;fwrite;fputcneeds.In a raise that did get through, the target sat at one RIP for 14,695 of 14,703 samples and the raise took 145 ms. The writer is not mostly in host code: run alone, its loop spends 39–40% of its time in
fwrite/fseekand the rest in its own spin. It was the sampling that kept it from leaving.RaiseOnnow spins for 20 µs (YieldProcessor) before each new host-code sample, so the target gets to run. Other retries keepSwitchToThread. The 50 ms limit, the system-call extension and the wait andNtContinue/winpthreads handling are unchanged. The libkernel debt entry for the Windows raise records the spin and that 20 µs is a measured choice.Tested
Windows 11 Enterprise 22H2 (10.0.22621), AMD Ryzen 9 5950X (16 cores / 32 threads), MinGW-w64 GCC 15.2 UCRT r7, Release.
guest_raise_in_host_codemain21554447d0/72fe76ff89fcc01c57a6On this PR,
guest_raise_exception,guest_raise_nested_sleep,guest_raise_in_system_callandguest_raise_in_host_codeall passed in 3 of 3 runs.guest_raise_exceptiontook 14.2 s here, run alone. In the fullmainsuite (ctest -j 8) it passed in 20.1 s, but that is not a matched comparison, so I make no timing claim.tools/check_conventions.pypasses.Not tested: other CPUs and Windows builds. #7652's author saw the test pass, so whether
SwitchToThreadalone is fast enough probably depends on the machine. Linux and macOS do not use this path.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)