fix(libkernel): deliver raises at the spin that ends a sleep on Windows #12135
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12135"
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 Oscar45397 on 2026-10-27T23:18:35Z.
What
On Windows,
sceKernelRaiseExceptionat a thread that loops on short sleeps is lost (#12131). A sleep shorter thanTimedWait's 0.5 msLEAD_NANOS, and the last 0.5 ms of a longer one, ends in aYieldProcessorspin in host code with no wait counted. A raise that finds the target there takes the host-code path (return-address breakpoint or sampling), and for a thread looping onsceKernelUsleep(200)that path never delivered it.SleepUntilandSleepNanosUnlessChangednow run that spin under aDeliveryDeferraland drain APCs afterwards, the patternBeginPark,UnparkandDeferringDeliveryalready use. A raise that finds the target spinning is queued as an APC and runs when the sleep ends, at most 0.5 ms later.SleepWake, a timed mutex or rwlock lock on a lock the caller already owns, the TSC frequency probe) hold nothing across the spin that the alertable part of the same sleep does not already hold.Tested
Windows 11 Home 26200, AMD Ryzen 9 5900X, WinLibs GCC 15.2.0 r7, Release, on
mainf759e165d9. Since rebased ontomainbb04a4f1eawithout conflicts (the patch is unchanged). There,guest_raise_short_sleepandguest_raise_short_sleep_without_wakepass 5 of 5, the otherguest_raise_*tests pass 3 of 3 (includingguest_raise_exception), and withTimedWait.cppput back tomain's version both new tests fail in 2 of 2 runs (raise N at a thread sleeping 100 us in a loop was not delivered within 3 s).sceKernelUsleep(200), 200 raises, 3 s allowed per raise):mainloses the first raise in 5 of 5 runs; with this change all 200 arrive in 5 of 5 runs (about 0.12 s). Loops on 100 and 400 µs sleeps behave the same. Loops on 10 µs and 1 ms sleeps already deliver onmainand are unchanged.guest_raise_short_sleepandguest_raise_short_sleep_without_wake: 100 raises each at threads looping on 100, 200 and 400 µs sleeps, with sleep wakes on (SleepNanosUnlessChanged) and withAPS5_NO_SLEEP_WAKE=1(SleepUntil). 30 of 30 runs pass in each mode; with theTimedWait.cppchange reverted, both fail at the first or second raise.ctest --test-dir build -E 'agc|shader|recomp|video_?out|gnm|vulkan|spirv|gpu|pm4' -j 8): all 1524 pass exceptguest_fopen_errors, skipped as onmain, andguest_raise_exception(address waking round N: the handler did not run within 5 s), which fails the same way onmain(#11813). The otherguest_raise_*tests pass.mainwithout this change still loses the first raise in 5 of 5 runs: its mailbox is emptied inDrainApcs, which a sleep under 0.5 ms never reaches. The two compose: the drain after the spin also empties that mailbox.1cf6f482c0) now only lowersLEAD_NANOSto 20 µs, which shortens these spins but does not change how they run. The two merge cleanly in either order; with both onmainbb04a4f1ea,guest_raise_short_sleep,guest_raise_short_sleep_without_wakeand #11725'sguest_timed_wait_cpupass 3 of 3. Landing order: proposed to its author in #11725 (this PR first, as #11725 is on hold).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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T04:34:40Z.
Review: CHANGES_REQUESTED
The Windows short-sleep repro and registered coverage are strong: the report includes repeated failure on main and repeated success with the fix, including the
APS5_NO_SLEEP_WAKE=1path. The code also keeps APC delivery deferred through the spin and drains afterward. The remaining blocker is that this branch is based on6e9b9134, while currentmainis82d5f01f(314 commits ahead). CONTRIBUTING requires branches to be based on currentmain; please rebase/update and rerun the focused short-sleep tests and conventions check. Since #11725 remains open and edits the same two spin loops, please also verify the updated result against that current overlap.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:58:41Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
What I checked
5ef2cc48d03c4ae2b8c02e7115cc823c3c939e96against fetchedmain2960e9a6e7.git diff --checkpasses. Hosted Windows, conventions, and eligibility checks pass; Linux and specialized jobs were skipped.Test evidence
The author reports repeated Windows repro/control runs and focused tests on the earlier rebased head
106fa85477, with the failure reproduced on main and fixed by the change. I did not run the Windows runtime tests locally. The current head's report is based on main319621ba2e, which is 176 commits behind fetchedmain2960e9a6e7; please refresh and rerun the focused test and control against the current integration head.Blocking repository coordination
Open #11725 also changes the same
SleepUntilandSleepNanosUnlessChangedloops. The PR body says whichever lands second needs a rebase, but neither PR records an agreed order orDepends onrelationship.CONTRIBUTING.mdrequires the authors to agree which goes first and record that order. Please coordinate with #11725’s author and update the checklist before merge.I am requesting changes for current-head validation and the unresolved overlap order, not for a confirmed defect in the APC deferral logic.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T01:57:38Z.
Review: APPROVED
Re-checked — new evidence, looks good
The authors have now recorded the agreed landing order: #12135 remains independent and #11725 depends on it.
What I ran
Reviewed exact head
3d3fba812c77c083fb422085cf12fcec44a2b750against recorded PR basebb04a4f1ea0175e9e4f149f0359a764d62ff3296and currentmain99b571f879cd1ef3de7b8af21261675826d75943. The current-main merge preview is clean (f1f4f3c153974b24b37513079a72d449b2bc291c). The changedTimedWait.cppandGuestRaiseShortSleep.cppare unchanged onmainsince the reported test base; current-main changes to shared CMake/test/debt files merge cleanly. Environment: Linux workspace; no local build or test was run.Results
Unedited command output
Sources
Not verified
I did not run the focused tests locally. The PR's test reports are on the recorded base and are not physical-console tests.
To get this to a good state
Proceed with #12135 before #11725 as documented. I will re-check the same source and checks if the head changes.