Repository navigation
fix(libkernel): deliver raises at the spin that ends a sleep on Windows - #12135
Conversation
|
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.
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.
|
|
Independent Windows result on a second AMD machine. Setup: Windows 11 Pro 26300, AMD Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7, Ninja Release, New tests:
Neighbouring raise tests (head merged onto Not tested: Linux and macOS (the change is inside the Windows branch of AI-assisted (Claude Code). Causal-qualification correction by Codex; no new execution claimed. |
|
Tested the repro from #12131 on this PR's head c19a382 (Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, Intel i5-10500H), with
On the same machine |
MarcZX10
left a comment
There was a problem hiding this comment.
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=1 path. The code also keeps APC delivery deferred through the spin and drains afterward. The remaining blocker is that this branch is based on 6e9b9134, while current main is 82d5f01f (314 commits ahead). CONTRIBUTING requires branches to be based on current main; 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.
|
A Windows data point, for context rather than as a verdict on this PR: Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Release. Head
This PR's own tests for #12131, AI-assisted: yes (Claude Code). |
c19a382 to
d06c7bb
Compare
|
@MarcZX10 Thanks for the review. @adriadam10 has since rebased this onto Setup: Windows 11 Home 26200, Ryzen 9 5900X, WinLibs GCC 15.2.0 r7, Release,
With #11725: its AI-assisted: yes |
d06c7bb to
106fa85
Compare
|
@MarcZX10 could you take another look when you have time? The rebase and reruns your review asked for are in my comment above, and the branch has since been rebased again onto |
106fa85 to
5ef2cc4
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
What I checked
- Reviewed exact head
5ef2cc48d03c4ae2b8c02e7115cc823c3c939e96against fetchedmain2960e9a6e7. - The change defers APC delivery across both Windows spin loops and drains afterwards; the new test exercises 100, 200, and 400 microsecond sleeps with sleep wakes enabled and disabled.
- The current-main merge preview is clean and
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 main 319621ba2e, which is 176 commits behind fetched main 2960e9a6e7; please refresh and rerun the focused test and control against the current integration head.
Blocking repository coordination
Open #11725 also changes the same SleepUntil and SleepNanosUnlessChanged loops. The PR body says whichever lands second needs a rebase, but neither PR records an agreed order or Depends on relationship. CONTRIBUTING.md requires 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.
|
Windows run of this head (
AI-assisted: yes (Claude Code). |
|
Thanks, this is useful current-head evidence: the focused Windows tests and negative control now cover |
5ef2cc4 to
3d3fba8
Compare
|
@MarcZX10 refreshed onto
On #11725: its current head only lowers AI-assisted: yes (Claude Code). |
|
@Oscar45397 Following your proposal on #11725, can we agree that #12135 lands first and #11725 follows with |
|
A run on an Intel host with GCC 16: Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0, Release,
AI-assisted: yes (Claude Code) |
Re-checked — Windows evidence updated; order pendingThe exact head The author reports GitHub currently reports the PR mergeable. Current The remaining review item is coordination: #11725's author proposed #12135 first and asked for confirmation, while both PR descriptions still say |
|
@MarcZX10 Thanks for the update. I agree with the order Oscar proposed: #12135 first, then #11725. I have updated #11725's checklist to record @Oscar45397 I checked #12135's current checklist and it already says |
MarcZX10
left a comment
There was a problem hiding this comment.
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 3d3fba812c77c083fb422085cf12fcec44a2b750 against recorded PR base bb04a4f1ea0175e9e4f149f0359a764d62ff3296 and current main 99b571f879cd1ef3de7b8af21261675826d75943. The current-main merge preview is clean (f1f4f3c153974b24b37513079a72d449b2bc291c). The changed TimedWait.cpp and GuestRaiseShortSleep.cpp are unchanged on main since 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.
git merge-tree --write-tree refs/review/session-main refs/review/session-pr-12135
git diff --check refs/review/session-main...refs/review/session-pr-12135
python3 tools/check_conventions.py --base refs/review/session-main --head refs/review/session-pr-12135
gh pr checks 12135 --repo boykopovar/AnyPS5Results
| Check | Result |
|---|---|
| Current-main merge preview | Clean |
| Diff check | Passed; no output |
| Conventions | Passed |
| Hosted Windows | Passed |
| Hosted conventions, labels, eligibility, report | Passed |
| Hosted Linux and specialized jobs | Skipped |
| Focused Windows tests and main-source negative controls | Reported by the PR author and an independent tester; not rerun locally |
Unedited command output
$ git merge-tree --write-tree refs/review/session-main refs/review/session-pr-12135
f1f4f3c153974b24b37513079a72d449b2bc291c
$ git diff --check refs/review/session-main...refs/review/session-pr-12135
[no output; exit status 0]
$ python3 tools/check_conventions.py --base refs/review/session-main --head refs/review/session-pr-12135
All conventions checks passed.
$ gh pr checks 12135 --repo boykopovar/AnyPS5
conventions pass 16s https://github.com/boykopovar/AnyPS5/actions/runs/40930658297/job/123647882626
labels pass 6s https://github.com/boykopovar/AnyPS5/actions/runs/40930658216/job/123647883181
windows pass 9m44s https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647708141
linux skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647711738
register-context skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647711465
relinker skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647712116
relinker-asan skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647712497
write-watch skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647711015
eligibility pass 6s https://github.com/boykopovar/AnyPS5/actions/runs/40930583615/job/123647623069
report pass 40s https://github.com/boykopovar/AnyPS5/actions/runs/40930583243/job/123647621429
Sources
- Timed-wait implementation at this head
- Short-sleep regression tests at this head
- Recorded order and dependency update
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.
On Windows a sleep shorter than TimedWait's 0.5 ms lead, and the last 0.5 ms of a longer one, is a YieldProcessor spin in host code with no wait counted. A raise that found the target there could only be delivered through the return-address breakpoint or sampling, so sceKernelRaiseException at a thread looping on such sleeps was lost: a thread looping on sceKernelUsleep(200) lost the first raise in 5 of 5 runs. The spins in SleepUntil and SleepNanosUnlessChanged now run under a DeliveryDeferral and drain APCs afterwards, as BeginPark and Unpark already do. A raise that finds the target spinning is queued as an APC and runs when the sleep ends. GuestRaiseShortSleep raises 100 times each at a thread sleeping 100, 200 and 400 us in a loop, with sleep wakes on (SleepNanosUnlessChanged) and with APS5_NO_SLEEP_WAKE (SleepUntil). Both fail on main at the first or second raise. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3d3fba8 to
03722a1
Compare
|
Rebased onto current |
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
mainf759e16. Since rebased ontomainbb04a4f without 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(libkernel (Windows): guest_raise_exception slowed about 3x and sometimes aborts at "address waking" since 540364a24 (#10666) #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 onmainbb04a4f,guest_raise_short_sleep,guest_raise_short_sleep_without_wakeand fix(libkernel): prevent sub-millisecond timed wait busy-spinning on Windows #11725'sguest_timed_wait_cpupass 3 of 3. Landing order: proposed to its author in #11725 (this PR first, as fix(libkernel): prevent sub-millisecond timed wait busy-spinning on Windows #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