Time Synchronization In Virtual Machines
Timekeeping in virtual machines (VMs) can be pretty tricky. If timer tick interrupts are virtualized then the interrupt handler in a particular VM can be delayed when the physical machine is busy e.g. with other VMs, and next time when the physical host is idle, several IRQs might be handled in a batch to catch up with the current time.
This means that if the time in a VM is compared to a real external reference clock in regular intervals the time difference observed in subsequent comparisons can jump back and forth even though the reference clock is stable. For example, if 1 second seems to have passed inside a VM, the time of a real clock may have gained 1.1 seconds because the timer updates in the VM were delayed, or only 0.9 seconds if the timer updates were batched to catch up.
So how accurately the time in a virtual machine can be disciplined by any synchronization software depends in general on how good the undisciplined time in a VM is kept, which in turn depends on the implementation of the virtualization software (i.e., the hypervisor), which has to take care that timer interrupts in each VM are scheduled accurately whenever an associated timer tick interval has expired.
So in fact the performance of time synchronization in a VM depends on the type and version of the operating system running in the VM, and on the type and version of the hypervisor software running on the physical machine, and thus depends on the scheduling of timer ticks for the VMs.
Some virtualization systems provide their own mechanisms to discipline the time in a VM more or less accurately, while others suggest to install a software like the NTP daemon in a VM.
Generally it is not advisable to run a VM as time server for other physical machines since the time provided by such server is usually less accurate and provides significantly more jitter than a physical machine acting as time server.
A more detailed explanation of the basics can be found in a paper provided by VMware:
- Timekeeping in VMware Virtual Machines
https://www.vmware.com/pdf/vmware_timekeeping.pdf
Other resources:
- The NTP Support Web: Known Operating System Issues
http://support.ntp.org/bin/view/Support/KnownOsIssues
- Especially: Xen, VMware, and Other Virtual Machine Implementations
http://support.ntp.org/bin/view/Support/KnownOsIssues#Section_9.2.2.
VMware
In early versions of VMware the time inside a VM was jumping back and forth so much that programs like ntpd
were
unable to discipline the system time in the VM successfully, so the general advice was just to let the hypervisor adjust the VM's time in periodic intervals.
In current VMware versions this has been very much improved, so VMware (now part of Broadcom) suggests to install NTP in each VM, if the VM runs Linux or Windows:
- Timekeeping best practices for Linux guests
https://knowledge.broadcom.com/external/article/310053/timekeeping-best-practices-for-linux-gue.html
- Timekeeping best practices for Windows, including NTP
https://knowledge.broadcom.com/external/article?articleNumber=315346
Note:
If you run ntpd
under Windows please use NTP version 4.2.8 or newer, and configure the NTP servers to be polled using configuration lines like this in ntp.conf
:
server aa.bb.cc.dd iburst minpoll 6 maxpoll 6
where aa.bb.cc.dd has to be replaced by the hostname or IP address of the real NTP server. This configuration yields the best result under Windows in general.
More information on timekeeping in VMware is available if you search the VMware knowledge base for timekeeping
:
https://kb.vmware.com/selfservice/microsites/searchEntry.do
Under VMware it is also possible under certain conditions to use a PCI card directly as reference time source from within a single VM. See Accessing Meinberg PCI Devices From Within A VMware Virtual Machine for details.
Known Limitations
When a VM is moved from one physical machine to the next, or a snapshot is taken from a VM then the VM is temporarily suspended, which results in a time offset when the VM is resumed.
Other Virtualization Systems
There are other virtualization implementations like
- Microsoft's Virtual PC / Hyper-V, see also:
Accurate Time In Windows
- Oracles's VirtualBox
- XEN
- Linux KVM
and some more. The underlying basics are mostly always the same, but we haven't collected specific information, yet.
— Martin Burnicki martin.burnicki@meinberg.de, last updated 2024-08-13