Applies to openSUSE Leap 42.1

16 VM Guest Clock Settings

Abstract

Keeping the correct time in a VM Guest is one of the more difficult aspects of virtualization. Keeping the correct time is especially important for network applications and is also a prerequisite to do a live migration of a VM Guest.

Tip
Tip: Timekeeping on the VM Host Server

It is strongly recommended to ensure the VM Host Server keeps the correct time as well, for example, by using NTP (see Book “Reference”, Chapter 18 “Time Synchronization with NTP” for more information).

16.1 KVM: Using kvm_clock

KVM provides a paravirtualized clock which is currently supported by SUSE Linux Enterprise Server 10 SP3 and newer and RedHat Enterprise Linux 5.4 and newer via the kvm_clock driver. It is strongly recommended to use kvm_clock when available.

Use the following command inside a VM Guest running Linux to check whether the driver kvm_clock has been loaded:

tux > sudo dmesg | grep kvm-clock
[    0.000000] kvm-clock: cpu 0, msr 0:7d3a81, boot clock
[    0.000000] kvm-clock: cpu 0, msr 0:1206a81, primary cpu clock
[    0.012000] kvm-clock: cpu 1, msr 0:1306a81, secondary cpu clock
[    0.160082] Switching to clocksource kvm-clock

To check which clock source is currently used, run the following command in the VM Guest. It should output kvm-clock:

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
Important
Important: kvm-clock and NTP

When using kvm-clock, it is recommended to use NTP in the VM Guest, as well. Using NTP on the VM Host Server is also recommended.

16.1.1 Other Timekeeping Methods

The paravirtualized kvm-clock is currently not for Windows* operating systems. For Windows*, use the Windows Time Service Tools for time synchronization (see http://technet.microsoft.com/en-us/library/cc773263%28WS.10%29.aspx for more information).

16.2 Xen Virtual Machine Clock Settings

When booting, virtual machines get their initial clock time from their host. After getting their initial clock time, fully virtual machines manage their time independently from the host. Paravirtual machines manage clock time according to their independent wallclock setting. If the independent wallclock is enabled, the virtual machine manages its time independently and does not synchronize with the host. If the independent wallclock is disabled, the virtual machine periodically synchronizes its time with the host clock.

Note
Note

OES 2 NetWare virtual machines manage clock time independently after booting. They do not synchronize with the host clock time.

If a guest operating system is configured for NTP and the virtual machine's independent wallclock setting is disabled, it will still periodically synchronize its time with the host time. This dual type of configuration can result in time drift between virtual machines that need to be synchronized. To effectively use an external time source, such as NTP, for time synchronization on a virtual machine, the virtual machine's independent wallclock setting must be enabled (set to 1). Otherwise, it will continue to synchronize its time with its host.

Procedure 16.1: Viewing the Independent Wallclock Setting
  1. Log in to the virtual machine’s operating system as root.

  2. In the virtual machine environment, enter

    cat /proc/sys/xen/independent_wallclock
    • 0 means that the virtual machine is getting its time from the host and is not using independent wallclock.

    • 1 means that the virtual machine is using independent wallclock and managing its time independently from the host.

Procedure 16.2: Permanently Changing the Independent Wallclock Setting
  1. Log in to the virtual machine environment as root.

  2. Edit the virtual machine’s /etc/sysctl.conf file.

  3. Add or change the following entry:

    xen.independent_wallclock=1

    Enter 1 to enable or 0 to disable the wallclock setting.

  4. Save the file and reboot the virtual machine operating system.

    While booting, a virtual machine gets its initial clock time from the host. Then, if the wallclock setting is set to 1 in the sysctl.conf file, it manages its clock time independently and does not synchronize with the host clock time.

Procedure 16.3: Temporarily Changing the Independent Wallclock Setting
  1. Log in to the virtual machine environment as root.

  2. Enter the following command:

    echo "1" > /proc/sys/xen/independent_wallclock

    Enter 1 to enable or 0 to disable the wallclock setting.

  3. Add or change the following entry:

    xen.independent_wallclock=1

    Enter 1 to enable or 0 to disable the wallclock setting.

    Although the current status of the independent wallclock changes immediately, its clock time might not be immediately synchronized. The setting persists until the virtual machine reboots. Then, it gets its initial clock time from the host and uses the independent wallclock according to the setting specified in the sysctl.conf file.

Print this page