Skip to content

kernel: park Timekeeper when idle#13667

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl945368458
Open

kernel: park Timekeeper when idle#13667
copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl945368458

Conversation

@copybara-service

Copy link
Copy Markdown

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

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
@copybara-service copybara-service Bot added the exported Issue was exported automatically label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant