Page 1 of 1

Managing VirtualBox CentOS 6.3 guest clock drift

Posted: 30. Aug 2012, 17:01
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!

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Posted: 6. Sep 2012, 23:01
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.

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Posted: 20. Sep 2012, 11:02
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

Re: Managing VirtualBox CentOS 6.3 guest clock drift

Posted: 20. Sep 2012, 11:44
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.