When using Apple Virtualization notify guest OS of wake up events #7031
+82
−1
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.
Open a Virtio Socket for the guest OS to receive a wakeup command if it connects to the host CID. This could be the basis for more of a command structure, like the QEMU guest agent. We are only using this to send a wakeup command, however.
This is predominantly useful for the guest OS to resync time against the hardware clock. Otherwise, using network time syncs relies on a timer, which can take between 5 - 30 minutes before its next scheduled sync. Also, network time syncs can sometimes fail with too much drift to resync the local system clock. Yet, while ntp has a skew of 1000s before failing, modern systemd Linux distros have switched to system-timesyncd.service, so the author is unsure what max drift is with this package.
-- Additional Notes --
Note, this caused problems with my VM, as occasionally TLS certs failed when they had been renewed (they had a future validity date). It also caused problems with SSH connections being slow to resync, and not responsive when waking up. Once, I witnessed the VM spinning at 100% CPU after sleeping for 2 weeks, but I'm uncertain if this is related without more debugging.
For this PR to function, it required me to run on port 43218. I couldn't get other ports to call the listener delegate when the client attempted to connect. I got this port number from the vz project, as it has a test that worked. That explains some of the oddity with this PR where I tried really hard to store strong references to the delegate, as I thought it was a scoping issue preventing the delegate from being called.
For other users of UTM, here is the Go program I am using on the client to resync the HW clock on wakeup. I modified this from the host-timesync-daemon in LinuxKit. I modified their program to connect and read from the socket, as well as matching hwclock's method for reading the rtc clock until it is modified (note, I didn't add a timeout to gracefully exit if there was a delay reading the rtc).
Also, this program either needs to run as root, have a setuid bit set, or the user needs proper permissions to read/write /dev/rtc0. If anyone is very interested, we could package this somewhere as an Apple/UTM virtualization agent.