9

I got VirtualBox running on Windows 7 host, running Ubuntu servers and XP-SP3 clients.

Often I note that the clock on the guest machines is strictly late in comparison to the host time. I first noted it when I got wierd benchmarking results for all kind of performance tests, and assumed that compare tests on the same machine to themselves would be OK - which is not.

The situation gets worse when client-server tests are involed. It might have been acceptable if all the guests would retain the same delay, but I run into situations where the time on the XP clients is more advanced on the servers, and situation that the time on the Ubuntu servers is more advanced then on the xp clients.

In a sense I could live with that - because it presents interesting test cases - but sometimes it gets to differences of 20 minuets.

I tried fidlling with the configuration for no avail - but I aught to be missing something...

Anybody? Thanks in advance.

Radagast the Brown
  • 3,156
  • 3
  • 27
  • 40
  • 1
    Have you tried configuring the machines to use a network time server? That might be the easiest way to keep all the times in sync with one another. – Cody Gray - on strike Mar 15 '11 at 07:06
  • Is it a VBox setting, or OS setting? – Radagast the Brown Mar 15 '11 at 07:08
  • It's an OS setting. Windows has supported network time servers since at least XP; find it by clicking on the taskbar clock. I don't know about Ubuntu, but I assume something similar is either built-in or freely available. – Cody Gray - on strike Mar 15 '11 at 07:13
  • If there is no better way using the configuration of the VBox - because they're all running on the same host, why involve network - that's what I'll have to do. But that will not help me in the benchmarking scenario - just make sure the cp is right every several minuets... :( – Radagast the Brown Mar 15 '11 at 11:29
  • Clocks on different discrete machines tend to drift, as well. Perhaps running in a VM is exacerbating the problem, but it certainly hasn't created it outright. You really shouldn't be comparing the individual *time* values obtained from benchmarks across virtual machines in the first place. I'm not sure what you're trying to accomplish, but this makes little sense to me. Just run the benchmark relative to the individual host (which makes time disparities *across* machines not a factor), and then compare aggregate results. – Cody Gray - on strike Mar 15 '11 at 12:30
  • @CodyGray OP specifically said that comparing values on the *same* VM produced odd results. The accepted answer shows the reason why: the VM clock gets corrected to the host clock every so often. – Ian Ni-Lewis Nov 15 '15 at 13:14

3 Answers3

14

If you have installed VirtualBox additions (and you probably have) there is a service on the guest host that syncs the time.

This service corrects the clock drift every 10 seconds if the difference between the host and guest clock is below 20 minutes, if the difference is above 20 minutes it just resets the guest clock to the host time. Thus you should never find a machine out of sync more than 20 minutes.

It is possible to change the 20 minute threshold using the --timesync-set-threshold guest parameter. You could for example set it to 1000ms, so you should never find a machine with a difference above one second.

You can configure the guest --timesync-set-threshold from the host machine using the following command:

VBoxManage guestproperty set <your-vm-name> "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 1000

You should restart your guest additions service or your guest machine in order for it to take effect.

Further reading:

Jens
  • 5,767
  • 5
  • 54
  • 69
  • 1
    GREAT!!! - just what I was looking for! setting timesync-set-threshold to 50ms was just the precision I needed for the benchmarks. I ran them again - this time with quite accurate results :) – Radagast the Brown Nov 20 '12 at 14:11
  • 1
    I had found these parameters, but not that I had to restart vboxadd-service in the guest before they take effect. Thanks. – JanKanis May 07 '19 at 14:15
  • I strongly recommend you do NOT rely upon a guest as a time source. Can confirm very odd system time behaviour (win10 as guest and host, with guest tools installed on the guest). Behaviour looks like every so often, the guest clock gets set to a couple minutes in the past - then the system clock runs slightly fast until it catches up with 'real' time - but does so with overshoot. The whole performance repeats periodically. – RGD2 Dec 11 '20 at 05:00
2

A universal solution would be to:

  1. Host an NTP server on Guest
  2. Configure Hosts to sync with NTP every few minutes

Regarding clock-skew with VirtualBox, has this issue with some configurations. With Windows 7 guests, disabling IO APIC helps in some cases.

Details : http://forums.virtualbox.org/viewtopic.php?f=8&t=21480

Shamit Verma
  • 3,839
  • 23
  • 22
  • Thanks for the answer. I tried it for some time. It helps partially for the general flow, but it's not good enough for benchmarking, for performance counters, and for flows that depend on consistent server time flow :( – Radagast the Brown Mar 29 '11 at 07:59
  • I strongly recommend you do NOT rely upon a guest as a time source. Can confirm very odd system time behaviour (win10 as guest and host, with guest tools installed on the guest). Run your time server on dedicated hardware, not in a VM. – RGD2 Dec 11 '20 at 05:08
0

First make sure Windows is not restricted to use HPET only as this may prevent the host and guest(s) to get an accurate RTC source:

Open administrator cmd.exe and type bcdedit /enum and then make sure useplatformclock is not there, if it is type bcdedit /deletevalue useplatformclock to remove it and then reboot Windows.

I had enabled this on my host to fix an old driver issue (some also say it's 'best' for performance with no reliable proofs), there was no noticeable issue at first but then I discovered that the RTC was drifting quite a lot (up to 0.5s per hour...).

There are also other inherent problems in Windows (possibly fixed in Windows 8) where the timer precision is set OS wise while it can be changed by any application that needs a higher precision and set back to a lower precision later. These changes will also skew the RTC over time. So the best thing to do (from my own experience) is to:

  1. disable host->guest clock synchornisation entirely using:

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

(you then need to shut-down the VM and restart it for this change to take effect)

  1. install an NTP package on the guest that uses standard external time sources (like any standalone computer would).

  2. Install a proper NTP port on the Windows host (I personally use Heiko Gerstung's)

  3. Additionally you should make sure your virtualbox guest additions are up to date.

Community
  • 1
  • 1
2072
  • 275
  • 3
  • 6