Timekeeping in VMware Virtual Machines
Timekeeping in VMware Virtual Machines
Timekeeping in VMware Virtual Machines
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Timekeep<strong>in</strong>g</strong> <strong>in</strong> <strong>VMware</strong> <strong>Virtual</strong> Mach<strong>in</strong>es<br />
• As with the local APIC timer, software does not have a reliable way to determ<strong>in</strong>e the TSC's<br />
<strong>in</strong>put frequency. Generally, the only way to determ<strong>in</strong>e the TSC's frequency is to measure it<br />
approximately us<strong>in</strong>g the PIT or CMOS timer.<br />
• Several forms of power management technology vary the processor's clock speed<br />
dynamically and thus change the TSC's <strong>in</strong>put oscillator rate with little or no notice.<br />
• On shared-bus SMP mach<strong>in</strong>es, all the TSCs run off a common clock oscillator, so they can<br />
generally be synchronized with each other at startup time and thereafter treated as a<br />
s<strong>in</strong>gle system-wide clock. This does not work on some NUMA (non-uniform memory<br />
access) multiprocessors, however, as different NUMA nodes often run off separate clock<br />
oscillators. Although the nom<strong>in</strong>al frequencies of the oscillators on each NUMA node may<br />
be the same, each oscillator is controlled by a separate crystal, and the crystal precision is<br />
typically no better than 20 parts per million. In fact, on some systems (such as the IBM<br />
x440/x445 family), these clock rates are <strong>in</strong>tentionally varied dynamically over a small range<br />
(2% or so) to reduce the effects of emitted RF (radio frequency) noise, a technique called<br />
spread-spectrum clock<strong>in</strong>g.<br />
Despite these drawbacks, both operat<strong>in</strong>g systems and application programs frequently use the<br />
TSC for timekeep<strong>in</strong>g. Some versions of the W<strong>in</strong>dows operat<strong>in</strong>g system read the TSC to<br />
implement the QueryPerformanceCounter system call. Many versions of L<strong>in</strong>ux use the<br />
TSC to generate additional bits of precision for the gettimeofday system call, beyond the<br />
count of timer <strong>in</strong>terrupts received. <strong>VMware</strong> products also use the hardware TSC for f<strong>in</strong>e-gra<strong>in</strong>ed<br />
timekeep<strong>in</strong>g.<br />
HPET (High Precision Event Timer)<br />
The HPET is a device available <strong>in</strong> some newer PCs. Most PC systems do not have this device and<br />
most operat<strong>in</strong>g systems do not use it. The HPET has one central up-counter that runs<br />
cont<strong>in</strong>uously (unless stopped by software). It is usually 64 bits wide, but 32-bit implementations<br />
are permitted by its specification. The counter's period can be read from a register. The HPET<br />
provides multiple timers (three or more), each consist<strong>in</strong>g of a register that is compared with the<br />
central counter. When a register value matches, the correspond<strong>in</strong>g timer fires. If the timer is set<br />
to be periodic, the HPET hardware automatically adds its period to the compare register, thus<br />
comput<strong>in</strong>g the next time for this timer to fire.<br />
<strong>VMware</strong> Timer <strong>Virtual</strong>ization<br />
<strong>VMware</strong> products use a patent-pend<strong>in</strong>g technique to allow the many timer devices <strong>in</strong> a virtual<br />
mach<strong>in</strong>e to fall beh<strong>in</strong>d real time and catch up as needed, yet rema<strong>in</strong> sufficiently consistent with<br />
one another that guest software is not disrupted by anomalous time read<strong>in</strong>gs. In <strong>VMware</strong><br />
term<strong>in</strong>ology, the time that is visible to guests on their timer devices is called apparent time.<br />
Generally, all timer devices <strong>in</strong> a virtual mach<strong>in</strong>e operate identically to the correspond<strong>in</strong>g timer<br />
devices <strong>in</strong> a physical mach<strong>in</strong>e, but they show apparent time <strong>in</strong>stead of real time. The follow<strong>in</strong>g<br />
sections note some exceptions to this rule and provide some additional details about each<br />
emulated timer device.<br />
<strong>Virtual</strong> PIT<br />
<strong>VMware</strong> products fully emulate the tim<strong>in</strong>g functions of all three timers <strong>in</strong> the PIT device. In<br />
addition, when the guest operat<strong>in</strong>g system programs the speaker timer to generate a sound,<br />
the virtual mach<strong>in</strong>e requests a beep sound from the host mach<strong>in</strong>e. (Note, however, that the host<br />
sound generated may not be the requested frequency or duration.)<br />
6