fix(libkernel): pause before retrying in MutexOperations::SpinAcquire #27922
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27922"
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 gurtgg on 2026-11-27T20:31:52Z.
What
MutexOperations::SpinAcquire(core/libs/prx/libkernel/Pthread/include/Mutex.hpp) so each iteration of the spin loop callspause()before retryingif (tryAcquire()) return true;, matching theyield()loop directly below it.tryAcquire()immediately after the initialtryAcquire()check and exited after the finalpause()without retrying, causing a back-to-back retry with no pause and missing unlocks occurring during the last spin pause.libkernel):MutexOperations::SpinAcquireis used by contended guest pthread mutex and condvar lock acquisitions.Tested
guest_pthread_mutex_spin(CheckSpinAcquireincore/libs/tests/GuestPthreadMutexSpin.cpp):Spin(5, 3, 4, counts)expectation frompauses == 2topauses == 3(tries == 4, yields == 0), matching pause-before-retry; fails onmain(pauses == 2) and passes with this fix.spins = 1, yields = 0) wheretryAcquire()returnstrueonly afterpause()runs once (acquired == true,paused == true,tries == 2,yields == 0), failing onmainand passing with this fix.spins = 2, yields = 1) verifying the exact sequence"T,P,T,P,T,Y,T".spins = 0, yields = 0andspins = -3, yields = -1) verifying a singletryAcquire()(tries == 1) with zero pauses or yields.Checklist
main; no other open PR implements the same functionstools/check_conventions.pypasses)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositorymainand passes after fixSummary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T20:37:39Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
613bee0af5:tools/check_conventions.pypassed.guest_pthread_mutex_spin_testsbuilt cleanly.guest_pthread_mutex_spin):core/libs/prx/libkernel/Pthread/include/Mutex.hppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T21:08:19Z.
Review: APPROVED
Reviewed — looks good
The code change moves each spin pause before its retry, and the updated regression cases cover the changed ordering and bounds at head
613bee0af5615d2c7feea4744c1775e389e80fd6.What I ran
Read the prepared diff and changed source at the pinned head. No commands or tests were run; the test outcomes in the description are author-reported.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test suite, build, or console behavior was run. No files were excluded by
manifest.json; both reviewed files were read:core/libs/prx/libkernel/Pthread/include/Mutex.hppandcore/libs/tests/GuestPthreadMutexSpin.cpp.Mutex.cppandCond.cppwere read for caller context.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:06:13Z.
Review: APPROVED
Checked head
613bee0af5. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomaina163d4b886together with #27930, #27929, #27926, #27925, #27924, #27923, #27901, #27828, #27771, #27755, #27748, #27682, #27765.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded.guest_pthread_mutex_spinpasses.guest_pthread_mutex_contentiontimed out in the loaded suite, as it does onmain. Run on its own, it takes the same time with and without this change. In the full CPU suite (5,120 tests) the only failures are unrelated:windows_read_trap_unknownfails onmaintoo (fixed in #28028).frame_capture_minimize,jpeg_external_toolchainandguest_pthread_mutex_contentionare timeouts under load; they pass when run on their own.guest_audio_in_capturepasses 20/20 onmainand with this change.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:34:52Z.
Review: COMMENTED
The Linux guest_pthread_mutex_spin CTest passed with the patch. Its instrumented retry loop checks that pauses and yields occur before the next retry, including when a phase has no retries, and checks eventual acquisition.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.