Repository navigation
fix(libkernel): wait for alarm and setitimer expiries with the precise timed wait on Windows - #11851
Merged
oneandonlydean merged 1 commit intoNov 2, 2026
Conversation
…e timed wait on Windows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
Contributor
|
Linux run: Ubuntu 22.04 on WSL2 (kernel 6.18), GCC 11.4, Release, AMD Ryzen 7 7800X3D (16 threads). I built head
So the slow expiry you measured on Windows (median about 15.9 ms) doesn't happen on this Linux host, and AI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Windows,
setitimerandalarmexpiries land on the host's coarse tick. A 2 ms one-shotITIMER_REALtimer deliversSIGALRMafter 15.9 ms (median of 31). The alarm thread (RunAlarmsincore/libs/prx/libkernel/System/src/Signals.cpp) waits on astd::condition_variable, and MinGW'swait_untilgoes through winpthreads and itsGetTickCount64-based timeout. This is another call site of #1471. #11167 left it out of thesigtimedwaitchange as a separate site, and this PR does it the same way.The change:
AlarmState::changedis aTimedWait::Condition, the waitersigtimedwait, event flags, equeues and semaphores already use.alarmandsetitimerwake it withNotifyAll.RunAlarmskeeps thesteady_clockdeadline thatalarm,setitimerandgetitimershare. When the deadline is still ahead, it waits withWaitUntilfor the remaining time, converted to aTimedWait::NowNanos()deadline, then loops. It expires the timer only oncesteady_clockhas reached the deadline, so a wake from a re-arm, or the two clocks disagreeing by a few microseconds, never fires it early.now < deadlinebranch of the old period count can no longer be reached, so it is gone.Tested
Windows 11, Intel Core i5-10600K, WinLibs GCC 15.2.0 r7, Release, full build:
guest_itimer_short_expiry(guest_itimer_tests short-expiry): withSIGALRMblocked, it arms a 2 ms one-shotITIMER_REALtimer 31 times and takes each expiry withsigtimedwait. No expiry may come earlier than 2 ms after arming, and the median must stay under 12 ms, as in fix(libkernel): wait for sigtimedwait timeouts with the precise timed wait on Windows #11167'ssigtimedwaittest.main'sSignals.cppit fails: median15858000 ns.--repeat until-fail:10), with medians between2008700and2017400 ns.sig|signal|pause|alarm|itimer|pselect|exception|raisepass with--repeat until-fail:3.Linux and macOS: not run. There
TimedWait::Conditionuses itscondition_variable_anypath, which waits the same way the old code did.Tested on
main5bc84038c4, then rebased onto801d5b9bc1, which doesn't touch these files. Overlaps are textual only: #9389, #10749 and #11002 edit other parts ofSignals.cpp, and none touches the alarm code.The other guest-visible waits #1471 still lists are AIO (#11416) and
libSceUsbd(#9339), both in their own PRs.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)Refs #1471