Skip to content

macos: implement host->guest time sync #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2023
Merged

Conversation

slp
Copy link
Collaborator

@slp slp commented Mar 1, 2023

macOS can be quite aggressive when it comes to force apps to take long naps for power saving reasons. In addition to this, CNTVCT_EL0 doesn't increase during these naps, meaning the guest is not aware that's missing ticks.

Both things combined mean that guests that run for long enough will suffer from clock skews.

To address this, we introduce here a simple and lightweight host to guest time sync. From the host side, the VMM will send DGRAM packets via vsock with the current time at regular intervals (60 seconds) and when an oversleep (host thread sleeping 3 times more than expected) is detected. On the guest side, "init" spawns a process that listens for such packets and sets the system clock if a delta bigger than 100ms is detected.

Fixes: #80

crobinso
crobinso previously approved these changes Mar 1, 2023
Copy link
Contributor

@crobinso crobinso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A brief scan looks sane to me, but that's as much as I can do :)

macOS can be quite aggressive when it comes to force apps to take long
naps for power saving reasons. In addition to this, CNTVCT_EL0 doesn't
increase during these naps, meaning the guest is not aware that's
missing ticks.

Both things combined mean that guests that run for long enough will
suffer from clock skews.

To address this, we introduce here a simple and lightweight host to
guest time sync. From the host side, the VMM will send DGRAM packets
via vsock with the current time at regular intervals (60 seconds) and
when an oversleep (host thread sleeping 3 times more than expected) is
detected. On the guest side, "init" spawns a process that listens for
such packets and sets the system clock if a delta bigger than 100ms is
detected.

Fixes: containers#80
Signed-off-by: Sergio Lopez <[email protected]>
@slp
Copy link
Collaborator Author

slp commented Mar 2, 2023

@crobinso thanks you! :-D

@slp slp merged commit b9930a7 into containers:main Mar 2, 2023
@slp slp deleted the time-sync branch March 2, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clock skew
2 participants