timer in vitual machine

转载 2012年03月21日 12:09:01


A virtual machine generally has difficulty synchronizing its time with the physical host computer. Although Microsoft Virtual Server 2005 Virtual Machine Additions are intended to help correct this problem, you might experience time synchronization problems because of the way in which the guest operating system keeps track of the system time. Every kind of operating system has its own way to keep track of the system time.The Linux 2.6 kernel uses three different kinds of algorithms to keep track of the system time. These algorithms are more efficient than the algorithms that are used by the Linux 2.4 kernel and by earlier Linux kernels.

Time synchronization in a virtual machine

An operating system generally tracks time by using the periodic time interrupts that are generated by a specific hardware device. Generally, an operating system obtains the time from a battery-backed Complimentary Metal Oxide Semi-conductor (CMOS) clock during the operating system's startup procedure. The operating system then configures a timer device to generate periodic interrupts. The operating system keeps track of time by counting these interrupts.

For a virtual machine, the actual physical hardware is shared by the host operating system and by the guest operating system. When a virtual machine generates a time interrupt, the guest operating system may be running or may not be running. Therefore, the guest operating system does not immediately account for some of these interrupts. To work around this issue, the virtual machine keeps a backlog of these interrupts. Additionally, the virtual machine increases the frequency of timer interrupts when it is running. The increased frequency of timer interrupts is intended to help the guest operating system maintain the correct time. However, the increased frequency of these interrupts could cause the guest operating system to miss some of the interrupts. These missed interrupts are known as "lost ticks." Lost ticks cause the guest operating system time to lag behind the actual time. Although you may experience this issue on a physical computer, you are more likely to experience this issue in a guest operating system that is running on a virtual machine.

The Linux 2.4 kernel and earlier Linux kernels rely on the timer interrupts that are delivered by the timer.The algorithms that are implemented for time synchronization in the Linux 2.4 kernel do not account for lost ticks. This behavior may cause the Linux guest operating system time to lag behind the actual clock. To help resolve this issue, some Linux distributions patch the Linux 2.4 kernel to deliver timer interrupts at a faster rate. However, the Linux guest operating system could still experience time synchronization issues because of lost ticks.

The Linux 2.6 kernel implements more efficient algorithms to resolve this time synchronization issue. Unlike the Linux 2.4 algorithms, the Linux 2.6 algorithms adjust for lost ticks. However, this adjustment may cause the Linux-based virtual machine to gain time. The Linux 2.6 kernel has three different clock parameters that can be passed to the kernel at boot time. Use these parameters to select the algorithms to use for time synchronization. For more information about these algorithms, see the "Timekeeping in Linux" section. Each of these timekeeping algorithms has advantages and disadvantages. However, you are more likely to notice disadvantages on a virtual machine than on a physical computer.

Computer timer hardware

Every operating system has its own method to handle timekeeping issues. There are various kinds of timer mechanisms that are used to keep time on a computer. These timer mechanisms include the following:
  • Programmable Interval Timer (PIT)
  • CMOS Real Time Clock (RTC)
  • Local Advanced Programmable Interrupt Controller (APIC) Timers
  • Advanced Configuration and Power Interface (ACPI) (This mechanism is also known as a Chipset Timer.)
  • Time Stamp Counter (TSC)
  • High Precision Event Timer (HPET)

Timekeeping in Linux

On an x86-based platform, the Linux 2.6 kernel interacts with the following kinds of clocks to keep track of time:
  • Power Management Timer (PMTMR)
    This clock has the following characteristics:
    • This clock is set by using the clock=pmtmr kernel parameter.
    • This clock uses the ACPI timer.
    • This clock may cause smaller time gains.
  • Time Stamp Counter (TSC)
    This clock has the following characteristics:
    • This clock is set by using the clock=tsc kernel parameter. (This is the default parameter.)
    • This clock uses the PIT counter and the TSC for time interpolation.
    • This clock may cause overcorrection in a virtual machine environment. Therefore, the guest operating system clock may run too fast.
    • This clock may cause time gains of up to 10 percent.
  • Programmable Interval Timer (PIT)
    This clock has the following characteristics:
    • This clock is set by using the clock=pit kernel parameter.
    • This clock uses only the PIT counter for time interpolation.
    • This clock uses the simplest of the available algorithms.
    • This clock does not gain time because it does not use lost tick correction code.
For more information about Virtual Server 2005, visit the following Microsoft Web site:
http://www.microsoft.com/windowsserversystem/virtualserver/default.mspx (http://www.microsoft.com/windowsserversystem/virtualserver/default.mspx)
The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.


转自:http://www.cnblogs.com/zc520/p/3422636.html 迁移到其他的虚拟机程序可行会吓倒一批人。如果你已经按照自己的喜好设置好了虚拟机,那么就不需要再从...
  • wolinxuebin
  • wolinxuebin
  • 2014年01月14日 15:33
  • 1079

学习Machine Learning书籍分级推荐

《How To Get Better At Machine Learning》推荐将学习Maching Learning技术划分为几个不同阶段,并为每个阶段的学习者推荐了参考书籍,在此转载一下 : ...
  • quicknet
  • quicknet
  • 2015年01月05日 15:35
  • 4313


今天部门的一位同事发现oracle的连接数被占用了很多,于是想通过V$SESSION视图找出占用最多连接的用户,于是写了下面的sql:     SELECT USERNAME, MACHINE,...
  • d34588
  • d34588
  • 2014年08月21日 15:11
  • 1384


  • Earl211
  • Earl211
  • 2016年08月29日 15:20
  • 6827

Java多线程总结(3)— Timer 和 TimerTask深入分析

1. 基本概念  java.util.Timer:是一个实用工具类,该类用来调度一个线程(schedule a thread),使它可以在将来某一时刻执行。 Java的Timer类可以调度一个任务运行...
  • Mark_LQ
  • Mark_LQ
  • 2015年12月15日 22:31
  • 2883

Factorization Machines 学习笔记(四)学习算法

最近学习了一种叫做 Factorization Machines(简称 FM)的通用算法,它可对任意的实值向量进行预测。其主要优点包括: 1) 可用于高度稀疏数据场景; 2) 具有线性的计算复杂度。本...
  • peghoty
  • peghoty
  • 2014年10月28日 10:22
  • 24219

MAC - Time Machine 备份文件的迁移

只需将Time Capsulez的"XXX的MacBook Pro.sparsebundle"文件拷贝至新的磁盘即可。
  • w6611415
  • w6611415
  • 2014年07月14日 22:57
  • 6630


.NET中的Timer类型详解 .NET FrameWork中有多个Timer,怎么根据实际情况在选择,确实是一个问题 计时器共有以下四种:...
  • eryongyan
  • eryongyan
  • 2014年03月19日 11:08
  • 1588

Azure Machine Learning Studio 实例 -- 预测xx年的食物工厂总数

Azure Machine Learning Studio 实例 -- 预测xx年的食物工厂总数
  • csharp25
  • csharp25
  • 2016年05月12日 10:15
  • 1660


使用Timer执行定时任务很简单,一般这样子写: Timer timer = new Timer(); TimerTask task = new TimerTas...
  • u012619640
  • u012619640
  • 2016年02月26日 14:54
  • 2020
您举报文章:timer in vitual machine