Chapter 14. KVM guest timing management
Virtualization poses various challenges for guest time keeping. Guests using the Time Stamp Counter (TSC) as a clock source may suffer timing issues as some CPUs do not have a constant Time Stamp Counter. Guests without accurate timekeeping may have issues with some networked applications and processes as the guest will run faster or slower than the actual time and fall out of synchronization.
KVM works around this issue by providing guests with a para-virtualized clock. Alternatively, some guests may use other x86 clock sources for their timing in future versions of those operating systems.
Guests can have several problems caused by inaccurate clocks and counters:
These problems exist on other virtualization platforms and timing should always be tested.
The Network Time Protocol (NTP) daemon should be running on the host and the guests. Enable the ntpd
service:
# service ntpd start
Add the ntpd service to the default startup sequence:
# chkconfig ntpd on
Using the ntpd
service should minimize the affects of clock skew in all cases.
Your CPU has a constant Time Stamp Counter if the constant_tsc
flag is present. To determine if your CPU has the constant_tsc
flag run the following command:
$ cat /proc/cpuinfo | grep constant_tsc
If any output is given your CPU has the constant_tsc
bit. If no output is given follow the instructions below.
Systems without constant time stamp counters require additional configuration. Power management features interfere with accurate time keeping and must be disabled for guests to accurately keep time with KVM.
These instructions are for AMD revision F cpus only.
If the CPU lacks the
constant_tsc
bit, disable all power management features (
BZ#513138). Each system has several timers it uses to keep time. The TSC is not stable on the host, which is sometimes caused by
cpufreq
changes, 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=1
to the kernel boot options in the
grub.conf
file on the host:
title Red Hat Enterprise Linux (2.6.32-36.x86-64)
root (hd0,0)
kernel /vmlinuz-2.6.32-36.x86-64 ro root=/dev/VolGroup00/LogVol00 rhgb quiet processor.max_cstate=1
Disable cpufreq
(only necessary on hosts without the constant_tsc
) by editing the /etc/sysconfig/cpuspeed
configuration file and change the MIN_SPEED
and MAX_SPEED
variables to the highest frequency available. Valid limits can be found in the /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies
files.
For certain Red Hat Enterprise Linux guests, additional kernel parameters are required. These parameters can be set by appending them to the end of the /kernel line in the /boot/grub/grub.conf file of the guest.
The table below lists versions of Red Hat Enterprise Linux and the parameters required for guests on systems without a constant Time Stamp Counter.
Red Hat Enterprise Linux | Additional guest kernel parameters |
---|
6.0 AMD64/Intel 64 with the para-virtualized clock | Additional parameters are not required |
6.0 AMD64/Intel 64 without the para-virtualized clock | notsc lpj=n |
5.5 AMD64/Intel 64 with the para-virtualized clock | Additional parameters are not required |
5.5 AMD64/Intel 64 without the para-virtualized clock | divider=10 notsc lpj=n |
5.5 x86 with the para-virtualized clock | Additional parameters are not required |
5.5 x86 without the para-virtualized clock | divider=10 clocksource=acpi_pm lpj=n |
5.4 AMD64/Intel 64 | divider=10 notsc |
5.4 x86 | divider=10 clocksource=acpi_pm |
5.3 AMD64/Intel 64 | divider=10 notsc |
5.3 x86 | divider=10 clocksource=acpi_pm |
4.8 AMD64/Intel 64 | notsc divider=10 |
4.8 x86 | clock=pmtmr divider=10 |
3.9 AMD64/Intel 64 | Additional parameters are not required |
3.9 x86 | Additional parameters are not required |
Windows uses the both the Real-Time Clock (RTC) and the Time Stamp Counter (TSC). For Windows guests the Real-Time Clock can be used instead of the TSC for all time sources which resolves guest timing issues.
To enable the Real-Time Clock for the PMTIMER
clock source (the PMTIMER
usually uses the TSC) add the following line to the Windows boot settings. Windows boot settings are stored in the boot.ini file. Add the following line to the boot.ini
file:
/use pmtimer
Windows uses the both the Real-Time Clock (RTC) and the Time Stamp Counter (TSC). For Windows guests the Real-Time Clock can be used instead of the TSC for all time sources which resolves guest timing issues.
The boot.ini
file is no longer used from Windows Vista and newer. Windows Vista, Windows Server 2008 and Windows 7 use the Boot Configuration Data Editor (bcdedit.exe
) to modify the Windows boot parameters.
This procedure is only required if the guest is having time keeping issues. Time keeping issues may not affect guests on all host systems.
Open the Windows guest.
Open the menu of the menu. Right click on the Command Prompt application, select Run as Administrator.
Confirm the security exception, if prompted.
Set the boot manager to use the platform clock. This should instruct Windows to use the PM timer for the primary clock source. The system UUID ({default}
in the example below) should be changed if the system UUID is different than the default boot device.
C:\Windows\system32>bcdedit /set {default} USEPLATFORMCLOCK on
The operation completed successfully
This fix should improve time keeping for Windows Vista, Windows Server 2008 and Windows 7 guests.