Kernel: Prevent lost wakeups in the idle loop #26443
Merged
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.


In the old idle loop implementation, lost wakeups can happen when the processor receives an interrupt immediately before wait_for_interrupt(). In that situation, we still go to sleep, even if the interrupt caused a thread to be runnable or we got notified of a runnable thread.
This new idle loop implementation instead runs with interrupts disabled. The only place in this new idle loop where we can get interrupts is during Processor::idle(). After that, we will only go to sleep if there are still no runnable threads.
With this new idle loop, boot time is reduced from 4 seconds down to 3 seconds on my x86-64 system when running in KVM. If I remove this busy wait, boot time is reduced down to 2 seconds (#26444):
serenity/Userland/Services/SystemServer/main.cpp
Line 135 in cef72c7