Skip to content

Conversation

@vyasgun
Copy link
Member

@vyasgun vyasgun commented Jan 13, 2026

Add a --timesync option which uses vsock to send host time to qemu-guest-agent running in the guest on VM suspend/resume.

Uses IOKit's power management APIs to detect system sleep/wake events. Since the official iokit-sys crate is incomplete, a custom fork is required.

This also maintains feature parity between krunkit and vfkit.

Fixes: #88

To test this, start krunkit with the --timesync <vsock-port> flag and other arguments as follows:

./target/release/krunkit --cpus 4 --memory 10752 --timesync 1234 --bootloader efi,variable-store=efistore.nvram,create --device virtio-blk,path=/Users/gvyas/Downloads/Fedora-Cloud-Base-AmazonEC2-42-1.1.aarch64.raw  --device virtio-rng --device virtio-serial,logFilePath=krunkit.log --device virtio-net,unixSocketPath=/tmp/vfkit.sock,mac=5a:94:ef:e4:0c:ee --device virtio-fs,sharedDir=/Users/gvyas,mountTag=dir0 --krun-log-level 3 

Inside the guest, qemu-guest-agent process should be running:

 /usr/bin/qemu-ga --method=vsock-listen --path=3:1234 --logfile=/var/log/qemu-ga.log -v

This is run as a systemd service on CRC which can be configured using cloud-init.

After this, put the host to sleep and check the time in the VM when it wakes up.

Copy link
Member

@tylerfanelli tylerfanelli left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @vyasgun, I've added some comments. I see this is still a draft, so apologies if I address points you were already working on.

Can you add a description of how to test?

Cargo.toml Outdated
log = "0.4.0"
env_logger = "0.11.8"
regex = "1.11.1"
IOKit-sys = { git = "https://github.com/vyasgun/iokit-sys", branch = "master" }
Copy link
Member

Choose a reason for hiding this comment

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

This would likely need to be an official release before we accept it as a dependency.

Copy link
Member Author

@vyasgun vyasgun Jan 14, 2026

Choose a reason for hiding this comment

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

An official release is going to be unlikely because this repository was last updated in 2018 😓 I opened a PR there last month: dcuddeback/iokit-sys#14 but doubt it would be merged.

Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't rely on it then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found another crate with all the bindings which is being actively maintained: https://crates.io/crates/objc2-io-kit

src/main.rs Outdated
Comment on lines 7 to 9
mod sleep_notifier;
mod status;
mod timesync;
Copy link
Member

Choose a reason for hiding this comment

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

Should sleep_notifier perhaps be a part of the timesync module? If there's no other uses, I believe it should.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, I put all the related code in timesync module.

Comment on lines 29 to 31
kIOMessageSystemWillSleep => tx.send(Activity::Sleep).unwrap(),
kIOMessageSystemWillPowerOn => tx.send(Activity::Wake).unwrap(),
kIOMessageSystemHasPoweredOn => tx.send(Activity::Wake).unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

Should likely return some type of error code on failure, rather than unwrap(). Since it seems to be called by the IO system, perhaps a log message would suffice?

Add a --timesync option which uses vsock to send host time to
qemu-guest-agent running in the guest on VM suspend/resume.

Uses IOKit's power management APIs to detect system sleep/wake
events. Since the official iokit-sys crate is incomplete, a
custom fork is required.

This also maintains feature parity between krunkit and vfkit.

Assisted by: Claude (Anthropic AI)

Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>

Co-authored-by: Tyler Fanelli <tfanelli@redhat.com>
@vyasgun vyasgun marked this pull request as ready for review January 22, 2026 06:22
@jakecorrenti
Copy link
Member

Thanks @vyasgun, code LGTM.

I'm having some issues with my Mac Mini, so I just need to sort that out and manually test before I merge.

Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
@vyasgun
Copy link
Member Author

vyasgun commented Jan 30, 2026

thanks @jakecorrenti - I updated the usage doc as well.

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.

Add --timesync option for guest clock synchronization

3 participants