macos: implement host->guest time sync #124
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.
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