Repository navigation
fix(libkernel): preserve semaphore wakeups across cancellation - #6241
Conversation
|
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.
|
|
I ran this on Linux, since your runs were on Windows. The added Setup: head
From reading the code: the new Overlap: this PR merges cleanly with #6103 (head Not checked: Windows (including the fine-grained and coarse wait backends your coarse test targets), macOS, PS5 hardware, and a retail title. My runs only used the SCE semaphore calls in your test. The POSIX Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes |
5d8189f to
57f353d
Compare
|
Could a maintainer review this PR, especially the cancellation wake handoff in AI-assisted: yes — Codex. |
What
Two guest threads can wait on an empty semaphore while one
postselects a waiter. If that waiter is canceled after unregistering its cancellation wake but before reacquiring the semaphore mutex, it exits without consuming the token or waking its peer.scePthreadSemGetvaluereports 1 while the survivor remains blocked.I forward one notification in
ThreadCancel::WaitUntilbefore unlocking and delivering cancellation. The peer rechecks its predicate under the existing mutex and consumes the original token. Token accounting and ordinary posts are unchanged. The helper serves SCE/POSIX semaphore waits and the condition-based join path; the wake contract is described by sem_post.The regression controls the interleaving through the existing mutexes and uses the actual guest APIs. It covers timed/untimed SCE waits, disabled cancellation and cancellation without a post, accepts spurious wakes through bounded retries, and rescues the survivor after a failed handoff so both threads can be joined.
The rebase preserves the upstream
guest_pthread_timed_locksregistration and both canceled-wake registrations. The production change and fixture are identical to previous head5d8189f79e2cc284d8e7e135ac0f69b7cbb66f6e. Related #6091 addresses condition-signal ownership and #6740 addresses semaphore-object lifetime; neither changes this helper. #6103 is already merged into the base. No dependency is needed.Tested
Base:
66702f1cffd3646f2d674ed093fde0a85a70761f.Head:
57f353df3e131cd719e3df9d11639b0b29c2cc2c.Both builds use Release, Ninja and
BUILD_TESTING=ON.cmake --build build-runtime --parallel 4. All 22 selected runtime tests passed, no skips; 127 patched libraries loaded, none failed. Both Windows wait backends were confirmed in the logs. All 40 additional canceled-wake runs passed.cmake --build <build> --parallel 2. The final serial set had 21 passes, 1 timeout (precise_wait), 0 skips; 127 patched libraries loaded, none failed. All 40 additional canceled-wake runs passed. The coarse registration uses the same backend as the default registration on Linux.The initial Linux (VirtualBox) run with
-j 2had aprecise_waittimeout and oneguest_cond_timedwaitabort. Both passed on an isolated serial rerun. Restoring only the baseCancel.hppreproduced theprecise_waittimeout; the condition test passed all three baseline repetitions and the final serial set.precise_wait_testsandlibc.prxretained identical SHA-256 hashes across that comparison and do not depend onlibkernel. Its configured timeout remains 10 seconds. I did not change code, test expectations or timeouts to obtain a pass. The precise cause of the intermittent timing failures is unresolved; this is not a fully passing Linux test set.For each negative control below, I kept the final fixture, restored only
Cancel.hppfrom the base, rebuilt and ran both registrations. The fixed header was restored infinally, its SHA-256 verified, and the full build rerun.Conventions, test registration, whitespace, current-main synchronization and independent read-only patch review passed. Only the three original PR files are changed.
Focused runtime commands
Use
-j 2on Windows and-j 1for the final Linux (VirtualBox) run:The default process environment has
APS5_COARSE_TIMED_WAITSunset; CTest sets it to 1 for the coarse registrations.Limits: no retail title run. The forced cancellation-after-wakeup race is measured through SCE semaphore APIs; existing POSIX cancellation/semaphore and join tests also ran. This does not establish console scheduler ordering or fix the separate
sceKernelWaitSemaissue #6006. Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested. Full hosted platform builds require collaborator dispatch underCONTRIBUTING.md; skipped jobs are not passes.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)