fix(libkernel): spin and yield when a condition variable wait relocks its mutex #13725
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13725"
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 cocoa55 on 2026-10-31T02:49:05Z.
What
A woken
scePthreadCondWait/scePthreadCondTimedwait(and thepthread_cond_*calls that use them) now takes its mutex back through the same path asscePthreadMutexLock: it tries once, spins and yields by the mutex's spin and yield counts, then blocks. Before this change,WakingLock::lock()inCond.cppcalled the native lock directly. FreeBSD 11.4 re-locks through_mutex_cv_lock, which callsmutex_lock_common, so a woken waiter spins and yields like any other lock. This is a follow-up to #13544.MutexOperations::SpinAcquire(PthreadMutex, std::timed_mutex&)and itsstd::recursive_timed_mutex&overload exposeMutex.cpp's existing spin path. The re-lock of a recursive mutex's outer level spins; the inner levels the owner takes back don't. The condition variable clause is removed from thelibkernel.mddebt entry.This fixes behaviour only and makes no speed claim.
Tested
Linux (CachyOS, kernel 7.3, GCC, Release, i5-9400F).
guest_pthread_mutex_spinadds a token ring: 4 guest threads take 300 turns each through one condition variable, broadcasting after every turn, so every wake re-locks the mutex under contention. It runs for all four mutex types with 2000 spins and 4 yields, and with neither; withscePthreadCondWaitandscePthreadCondTimedwait; and at recursive depth 2 for the recursive type. It checks that no two threads are ever inside together and that the turn and total counts are exact.These pass: all 56
^guest_pthreadtests,guest_cond_timedwait,guest_cond_recursive_mutex,guest_cond_unowned_mutex, bothguest_libc_cnd_*tests and all 29guest_job_manager_*tests.tools/check_conventions.pypasses.tools/pr_overlap.pyfinds no shared lines: #9326 and #12642 change other functions inMutex.cpp. Not run on Windows or with a title.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-31T03:03:31Z.
Review: COMMENTED
Re-checked — new head, test evidence needed
I reviewed head
16375634e31e44e35ff62a7ab513811d5249b292and found no source-level blocker, but the new condition-wait test has not been verified by the hosted run.The Windows job passed its build, but its log says
No guest core/libs test sources changed; the changed-test runner therefore did not executeguest_pthread_mutex_spin. Linux and specialized jobs were skipped. The PR description reports Linux test results but does not identify the tested commit SHA, so I cannot tie those results to this head.Please provide the exact tested SHA and output for
guest_pthread_mutex_spinand the focused condition/mutex tests, or arrange for CI to select and run the changed test. I will recheck the same evidence on the updated head.