Chapter 8. KVM Guest Timing Management
- Interrupts cannot always be delivered simultaneously and instantaneously to all guest virtual machines. This is because interrupts in virtual machines are not true interrupts. Instead, they are injected into the guest virtual machine by the host machine.
- The host may be running another guest virtual machine, or a different process. Therefore, the precise timing typically required by interrupts may not always be possible.
ntpdservice. For more information, see the Red Hat Enterprise 6 Deployment Guide.
ntpdor by the
chronydservice. Note that Chrony has some advantages on virtual machines. For more information, see the Configuring NTP Using the chrony Suite and Configuring NTP Using ntpd sections in the Red Hat Enterprise Linux 7 System Administrator's Guide.
By default, the guest synchronizes its time with the hypervisor as follows:
- When the guest system boots, the guest reads the time from the emulated Real Time Clock (RTC).
- When the NTP protocol is initiated, it automatically synchronizes the guest clock. Afterwards, during normal guest operation, NTP performs clock adjustments in the guest.
- When a guest is resumed after a pause or a restoration process, a command to synchronize the guest clock to a specified value should be issued by the management software (such as virt-manager). This synchronization works only if the QEMU guest agent is installed in the guest and supports the feature. The value to which the guest clock synchronizes is usually the host clock value.
Modern Intel and AMD CPUs provide a constant Time Stamp Counter (TSC). The count frequency of the constant TSC does not vary when the CPU core itself changes frequency, for example to comply with a power-saving policy. A CPU with a constant TSC frequency is necessary in order to use the TSC as a clock source for KVM guests.
constant_tscflag is present. To determine if your CPU has the
constant_tscflag enter the following command:
cat /proc/cpuinfo | grep constant_tsc
constant_tscbit. If no output is given, follow the instructions below.
Systems without a constant TSC frequency cannot use the TSC as a clock source for virtual machines, and require additional configuration. Power management features interfere with accurate time keeping and must be disabled for guest virtual machines to accurately keep time with KVM.
constant_tscbit, disable all power management features . Each system has several timers it uses to keep time. The TSC is not stable on the host, which is sometimes caused by
cpufreqchanges, deep C state, or migration to a host with a faster TSC. Deep C sleep states can stop the TSC. To prevent the kernel using deep C states append
processor.max_cstate=1to the kernel boot. To make this change persistent, edit values of the
GRUB_CMDLINE_LINUXkey in the
/etc/default/grubfile. For example. if you want to enable emergency mode for each boot, edit the entry as follows:
cpufreq(only necessary on hosts without the
constant_tsc), install kernel-tools and enable the
systemctl enable cpupower.service). If you want to disable this service every time the guest virtual machine boots, change the configuration file in
/etc/sysconfig/cpupowerand change the CPUPOWER_START_OPTS and CPUPOWER_STOP_OPTS. Valid limits can be found in the
/sys/devices/system/cpu/cpuid/cpufreq/scaling_available_governorsfiles. For more information on this package or on power management and governors, see the Red Hat Enterprise Linux 7 Power Management Guide.
8.1. Host-wide Time Synchronization
- Set the
ptp_kvmmodule to load after reboot.
echo ptp_kvm > /etc/modules-load.d/ptp_kvm.conf
- Add the
/dev/ptp0clock as a reference to the chrony configuration:
echo "refclock PHC /dev/ptp0 poll 2" >> /etc/chrony.conf
- Restart the chrony daemon:
systemctl restart chronyd
- To verify the host-guest time synchronization has been configured correctly, use the
chronyc sourcescommand on a guest. The output should look similar to the following:
chronyc sources210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== #* PHC0 0 2 377 4 -6ns[ -6ns] +/- 726ns