kernel: park Timekeeper when idle#13667
Open
copybara-service[bot] wants to merge 1 commit into
Open
Conversation
AI usage: written by Claude with a TON of back and forth and rewrites until we landed on this relatively minimal design; reviewed all the code in detail Currently the Timekeeper unconditionally wakes up every minute even when idle. This PR adds a mechanism to park it and to synchronously calibrate when the timekeeper is parked and either a task starts running or GetTime is called. This is achieved using a reference count mechanism that keeps it alive until tasks running becomes 0 and for the GetTime call duration. The parking mechanism works by first transitioning to idle if no reference are taken when the timer fires, and then if no tasks run and no GetTime calls are made for a whole interval (one second) then it transitions to parked and stops rearming the timer. This design means that there is no behavior change in the non-idle case, and makes everything much simpler. Note that I think there is a pre-existing bug in the codebase, which is that GetTime can be called while the timekeeper is stopped, because it is stopped before netstack during save. Once this is fixed, then the code in this commit can be adjust to panic if anything tries to take a reference to the Timekeeper while stopped instead of silently allowing it with miscalibrated clocks. FUTURE_COPYBARA_INTEGRATE_REVIEW=#13533 PiperOrigin-RevId: 945368458
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.
kernel: park Timekeeper when idle
AI usage: written by Claude with a TON of back and forth and rewrites until we
landed on this relatively minimal design; reviewed all the code in detail
Currently the Timekeeper unconditionally wakes up every minute even when idle.
This PR adds a mechanism to park it and to synchronously calibrate when the
timekeeper is parked and either a task starts running or GetTime is called. This
is achieved using a reference count mechanism that keeps it alive until tasks
running becomes 0 and for the GetTime call duration.
The parking mechanism works by first transitioning to idle if no reference are
taken when the timer fires, and then if no tasks run and no GetTime calls are
made for a whole interval (one second) then it transitions to parked and stops
rearming the timer. This design means that there is no behavior change in the
non-idle case, and makes everything much simpler.
Note that I think there is a pre-existing bug in the codebase, which is that
GetTime can be called while the timekeeper is stopped, because it is stopped
before netstack during save. Once this is fixed, then the code in this commit
can be adjust to panic if anything tries to take a reference to the Timekeeper
while stopped instead of silently allowing it with miscalibrated clocks.
FUTURE_COPYBARA_INTEGRATE_REVIEW=#13533