Managing VirtualBox CentOS 6.3 guest clock drift

Discussions about using Linux guests in VirtualBox.
Post Reply
ysh
Posts: 2
Joined: 30. Aug 2012, 16:47

Managing VirtualBox CentOS 6.3 guest clock drift

Post by ysh »

Here's my setup:

VirtualBox: 4.1.20 x86_64 installed from yum repository.
Host: CentOS 5.8 kernel 2.6.18-308.1.1.el5 x86_64
Guest: CentOS 6.3 kernel 2.6.32-279.5.2.el6.x86_64

As my requirements are for tight ( < 1 ms) time synchonization between host and guest, I've installed guest additions and am running timesync with the following aggressive parameters:

Code: Select all

VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--enable-timesync"
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust" 1 
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start"
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore" 1
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-latency-factor" 1
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 2
VBoxManage guestproperty set myvm1 "/VirtualBox/GuestAdd/VBoxService/--timesync-interval" 100
With these parameters, time on the guest drifts between 0 and 3 ms from the host (running ntpdate -q <hostip> every 2 seconds in a loop and looking at the offset)

I've experimented with different kernel parameters as recommended in the numerous other threads on this topic. My current guest kernel command line from /boot/grub/menu.lst is:

Code: Select all

	kernel /vmlinuz-2.6.32-279.5.2.el6.x86_64 ro root=/dev/mapper/myvm1-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_myvm1/lv_root rd_LVM_LV=vg_myvm1/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet nmi_watchdog=0 elevator=deadline divider=10 nolapic_timer noapic nolapic nosmp notsc clocksource=acpi_pm nohz=off
I've tried clocksource=pit, clocksource=jiffies, clocksource=acpi_pm, clocksource=tsc, and I just can't stop the drift. I don't think NTP would work because the guest clock drifts too quickly.

Is there any way to reduce the drift or is tighter clock synchronization just not possible in a virtualized configuration?

Thanks!
ysh
Posts: 2
Joined: 30. Aug 2012, 16:47

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Post by ysh »

I made some progress by doing the following to the CentOS 6.3 guests:

- turn off USB
- turn off audio
- turn ON HPET
- Add the following kernel parameters to the default CentOS 6.3 command line in /boot/grub/menu.lst:

Code: Select all

  divider=10 noapm acpi.power_nocheck=1
Right now my offset from the host ranges from 400 usec to 1 ms, and it looks like the Guest Additions timesync doesnt kick in at all.

Any other suggestions would be appreciated.
rschmied
Posts: 18
Joined: 5. Jan 2010, 11:42
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: various
Location: Germany

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Post by rschmied »

Have you tried with earlier kernels (like 2.6.18 / CentOS 5.8)? I'm under the impression that the delay loop calculation with newer kernels is extremely poor and needs improvement like what is available for VMware or HyperV. Essentially, newer Linux kernels can extract the CPU frequency from the hypervisor and make it alot more stable / reliable. Older kernels seem to do a better job w/ VirtualBox but with certain CPUs (especially when lacking VT-x support) the delay loop calibration is way off. Even on CPUs that have VT-x it seems to be not as reliable when compared to 2.6.18 or older kernels running on VirtualBox.

See here: https://www.virtualbox.org/ticket/9756

my $0.02 worth.

Thanks,
-ralph
sej7278
Volunteer
Posts: 1003
Joined: 5. Sep 2008, 14:40
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Solaris, Linux, Windows, OS/2, MacOSX, FreeBSD
Contact:

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Post by sej7278 »

virtualisation isn't the best idea for time-critical applications! you're better off looking at containers like openvz or lxc which actually use the hardware clock.
Post Reply