test(libkernel): keep the raise-in-system-call writer in guest code until each raise lands #10630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10630"
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 LeandroLP23 on 2026-10-24T13:37:34Z.
What
guest_raise_in_system_call(#8637) timed out on the Windows job of 20 different pull requests between 2026-10-21 and 2026-10-24, and once on amainpush build. In the failed runs' logs where it passed, it took 0.25–0.78 s, and every failure is a 30.00 s ctest timeout with no output, so the test hangs rather than runs slowly. Six of the timeouts came after #10076 merged.Why it hangs. I printed, in a local build only, the point where
RaiseOndecides to deliver. With the test process limited to one core, the first raise is delivered after exactly 1000.0 ms with the writer still insideNtWriteFile(InSystemCalltrue). That is the 1 sRetryLimit. The handler then runs with the stream lock held, and the main thread'sfputcwaits for it: the #7652 deadlock that the test is meant to rule out. Run normally, the same raise is delivered in guest code after 252 ms.The writer could stay in the call that long for two reasons:
NtWriteFilereturned.fwrite. When few cores are free, it goes straight on into the next block within the same time slice. So the sampler only ever saw it inside a system call, until the 1 s limit ran out.The retry limit is the library's design, so this changes the test, not
RaiseOn:WriteFileinto the 4 KiB pipe. The main thread'sfputcstill waits for the stream lock thatfwriteholds.WriteFilewith more than a pipe's worth still to go. The reader then stops reading and waits until the writer thread's suspend count (NtQueryInformationThread,ThreadSuspendCount) is above zero. OnlyRaiseOnsuspends it, and only while the write is blocked. The reader then holds 100 ms more, twice the 50 ms host-code window, and checks that the write has not returned.ripfrom the context and requires it to lie in the test executable's image, so a delivery anywhere afterfwritereturned passes. The writer then spins in its own code until the raise has been delivered.guest_raise_in_system_call_delay_raisesleeps 200 ms before the raise, andguest_raise_in_system_call_delay_returnspins in guest code betweenfwritereturning and its completion flag.steady_clockdeadline. It used to count 25,000sleep_for(1ms)calls, and each lasts about 15.6 ms at the default Windows timer resolution, so it never fired before ctest's 30 s timeout. A hang now aborts at 25 s.Tested
Windows 11 26300, AMD Ryzen AI 7 350, WinLibs GCC 15.2, Release,
main6cd36e6517for themaincolumn, this branch onda6c581a02. "Load" means busy-looping processes pinned to the same cores.guest_raise_in_system_callmainThe two delay variants pass the same three rounds (
_delay_raise3.14–3.18 s,_delay_return1.45–1.46 s) and the same 18 loaded runs each.Controls (local changes, not part of this PR):
RaiseOn: all three tests fail in 3 of 3 runs, at 0.27–0.51 s.written == delivery) put back:_delay_returnfails in 3 of 3 runs, the false failure from review._delay_raisepasses in 3 of 3 runs, the false pass from review.Other checks:
ctest -R 'guest_(mutex_)?raise' -j 4passes 7 of 7.tools/check_conventions.py --base origin/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:38:28Z.
Review: APPROVED
Reviewed exact head
a604ce5effe96b2179ceb2e1d94000f4c73c2ea7. The single-file test change keeps the handler blocked while the main thread callsfputc, while it repeatedly creates a sustainedfwritesystem-call window for each raise. The explicitwriting/deliverieshandshake prevents a raise from being sent before the corresponding write starts, and the reader's bounded 100 ms drain interval reduces scheduler-sensitive repeated system calls. Thesteady_clockwatchdog is correctly below the registered 30 s CTest timeout; on Windowsabortexits without flushing stream buffers, so it can terminate even if the test is stuck behind the stream lock.git diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/main --head HEADpass on the exact PR head. The body reports useful repeated Windows affinity/load runs, including a no-fix control that fails via the watchdog; I have not independently reproduced those Windows runs. Hosted eligibility, conventions, intake, and labels pass. Hosted product test jobs were skipped, so there is no hosted runtime result to claim. I found no blocking issue in the test change.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T14:20:04Z.
Review: CHANGES_REQUESTED
I rechecked the changed synchronization in
GuestRaiseInSystemCall.cppagainst the test’s stated purpose. The writer storeswriting = raiseimmediately beforefwrite, and the main thread raises as soon as it observes that value. This only proves the writer reached the line beforefwrite; it does not prove the thread is inside the blockingNtWriteFilecall. Under scheduling delay the exception can be delivered before the call, so the new test can pass without exercising the system-call path it is meant to guard. Please arrange the pipe/reader coordination so the writer is observably blocked in the write before raising (and retain the watchdog), or otherwise add a deterministic assertion that the target is in the system call at delivery. The reported stress runs are useful, but this ordering gap limits what they prove.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T14:34:09Z.
Review: APPROVED
Re-reviewed exact head
7fd6a7d7d3466deae7ed175d627e48d8f22af6dfafter the author’s follow-up. The test now uses unbuffered 16 KiB writes into a 4 KiB pipe; the reader observes bytes from the active block, stops draining, and the main thread raises only after that handshake. The 100 ms hold checks that the write has not returned before the exception is delivered, and the handler verifies the corresponding write has returned. This closes the prior ordering gap in the test’s claim.git diff --check upstream/main...HEADand repository conventions pass on the updated head. Hosted conventions/eligibility/labels pass; hosted product jobs remain skipped. The author reports repeated Windows runs and a no-fix control, which I have not independently reproduced.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T23:11:54Z.
Review: COMMENTED
Re-reviewed
86709434faae43bb020effbdcd509ce5aec33ee5. Final approval remains pending.Reviewed the revised blocked-write handshake and the new --delay-raise/--delay-return CTest modes. The test now captures the writer handle, observes its suspension, checks the signal context's instruction pointer against the test image, and coordinates draining, delivery and release across ten iterations. These are timing/runtime-sensitive assertions that need actual target execution.
Validation: The exact current test passes GCC 15.2 C++23 syntax compilation. Retrying the established optimized compatibility build still fails inside GCC's choose_baseaddr backend pass, before an executable is produced. The prior baseline build had the same compiler failure; this does not establish an author-introduced compile defect. No current runtime pass is claimed.
Pending: Run the complete linked test and both delay modes with a working compiler and matching runtime. Approval remains pending that execution; no verified code defect justifies a request for changes here.