28.12.2014 Views

Timekeeping in VMware Virtual Machines

Timekeeping in VMware Virtual Machines

Timekeeping in VMware Virtual Machines

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Timekeep<strong>in</strong>g</strong> <strong>in</strong> <strong>VMware</strong> <strong>Virtual</strong> Mach<strong>in</strong>es<br />

Introduction<br />

Generally speak<strong>in</strong>g, PC-based operat<strong>in</strong>g systems keep track of time by count<strong>in</strong>g timer <strong>in</strong>terrupts<br />

or ticks. When the operat<strong>in</strong>g system starts up, it reads the current time to the nearest second<br />

from the computer's battery-backed (CMOS) real time clock or queries a network time server to<br />

obta<strong>in</strong> a more precise time. To update the time from that po<strong>in</strong>t on, the operat<strong>in</strong>g system sets up<br />

one of the computer's hardware timekeep<strong>in</strong>g devices to <strong>in</strong>terrupt periodically at a known rate<br />

(say, 100 or 1000 times per second). The operat<strong>in</strong>g system then fields these <strong>in</strong>terrupts and keeps<br />

a count to determ<strong>in</strong>e how much time has passed.<br />

Support<strong>in</strong>g this form of timekeep<strong>in</strong>g accurately <strong>in</strong> a virtual mach<strong>in</strong>e is difficult. <strong>Virtual</strong> mach<strong>in</strong>es<br />

share their underly<strong>in</strong>g hardware with the host operat<strong>in</strong>g system (or on <strong>VMware</strong> ESX Server, the<br />

VMkernel). Other applications and other virtual mach<strong>in</strong>es may also be runn<strong>in</strong>g on the same host<br />

mach<strong>in</strong>e. Thus, at the moment a virtual mach<strong>in</strong>e should generate a virtual timer <strong>in</strong>terrupt, it may<br />

not actually be runn<strong>in</strong>g. In fact, the virtual mach<strong>in</strong>e may not get a chance to run aga<strong>in</strong> until it<br />

has accumulated a backlog of many timer <strong>in</strong>terrupts. In addition, even if a virtual mach<strong>in</strong>e is<br />

runn<strong>in</strong>g at the moment when one of its virtual timer <strong>in</strong>terrupts is due, the virtual mach<strong>in</strong>e may<br />

not check for the <strong>in</strong>terrupt at that moment and deliver it to the guest operat<strong>in</strong>g system on time.<br />

Constantly check<strong>in</strong>g for pend<strong>in</strong>g virtual timer <strong>in</strong>terrupts would <strong>in</strong>troduce a substantial<br />

overhead, slow<strong>in</strong>g down all virtual mach<strong>in</strong>es, so the <strong>VMware</strong> timekeep<strong>in</strong>g implementation<br />

checks for virtual timer <strong>in</strong>terrupts only occasionally — often not until the next real <strong>in</strong>terrupt<br />

occurs on the host mach<strong>in</strong>e.<br />

Because the guest operat<strong>in</strong>g system keeps time by count<strong>in</strong>g <strong>in</strong>terrupts, time as measured by<br />

the guest operat<strong>in</strong>g system falls beh<strong>in</strong>d real time whenever there is a timer <strong>in</strong>terrupt backlog. A<br />

<strong>VMware</strong> virtual mach<strong>in</strong>e deals with this problem by keep<strong>in</strong>g track of the current timer <strong>in</strong>terrupt<br />

backlog and deliver<strong>in</strong>g timer <strong>in</strong>terrupts at a higher rate whenever the backlog gets too large, <strong>in</strong><br />

order to catch up. Catch<strong>in</strong>g up is made more difficult by the fact that a new timer <strong>in</strong>terrupt<br />

should not be generated until the guest operat<strong>in</strong>g system has fully handled the previous one;<br />

otherwise the guest operat<strong>in</strong>g system may fail to see the next <strong>in</strong>terrupt as a separate event and<br />

miss count<strong>in</strong>g it. This phenomenon is called a lost tick.<br />

If the guest is runn<strong>in</strong>g too slowly, perhaps due to competition for CPU time from other virtual<br />

mach<strong>in</strong>es or processes runn<strong>in</strong>g on the host mach<strong>in</strong>e, it may be impossible to feed the guest<br />

enough <strong>in</strong>terrupts to keep up with real time. In current <strong>VMware</strong> products, if the backlog of<br />

<strong>in</strong>terrupts grows beyond 60 seconds, the virtual mach<strong>in</strong>e gives up on catch<strong>in</strong>g up, simply<br />

sett<strong>in</strong>g its record of the backlog to zero. After this happens, if <strong>VMware</strong> Tools is <strong>in</strong>stalled <strong>in</strong> the<br />

guest and the time synchronization feature is enabled, the tools correct the clock read<strong>in</strong>g <strong>in</strong> the<br />

guest operat<strong>in</strong>g system sometime with<strong>in</strong> the next m<strong>in</strong>ute by synchroniz<strong>in</strong>g the guest operat<strong>in</strong>g<br />

time to match the host mach<strong>in</strong>e's clock. The virtual mach<strong>in</strong>e then resumes keep<strong>in</strong>g track of its<br />

backlog and catch<strong>in</strong>g up any new backlog that accumulates.<br />

Another problem with timer <strong>in</strong>terrupts is that they cause a scalability issue as more and more<br />

virtual mach<strong>in</strong>es are run on the same physical mach<strong>in</strong>e. Even when a virtual mach<strong>in</strong>e is<br />

otherwise completely idle, it must run briefly each time it receives a timer <strong>in</strong>terrupt. If a virtual<br />

mach<strong>in</strong>e is request<strong>in</strong>g 100 <strong>in</strong>terrupts per second, it thus becomes ready to run at least 100 times<br />

per second, at evenly spaced <strong>in</strong>tervals. So roughly speak<strong>in</strong>g, if N virtual mach<strong>in</strong>es are runn<strong>in</strong>g,<br />

process<strong>in</strong>g the <strong>in</strong>terrupts imposes a background load of 100*N context switches per second<br />

(even if all the virtual mach<strong>in</strong>es are idle). <strong>Virtual</strong> mach<strong>in</strong>es that request 1000 <strong>in</strong>terrupts per<br />

second create ten times the context switch<strong>in</strong>g load. (<strong>Virtual</strong> mach<strong>in</strong>es runn<strong>in</strong>g Microsoft<br />

W<strong>in</strong>dows request 1000 <strong>in</strong>terrupts per second if they are runn<strong>in</strong>g certa<strong>in</strong> applications that make<br />

use of the Microsoft W<strong>in</strong>dows multimedia timer service. L<strong>in</strong>ux virtual mach<strong>in</strong>es runn<strong>in</strong>g<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!