From: Keir Fraser Subject: Re: xen PIT timer Date: Sat, 24 Sep 2005 08:48:59 +0100 Message-ID: <9896afa4596a38f1c299759d497b6dfb@cl.cam.ac.uk> References: <20050923194907.GA330@us.ibm.com> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20050923194907.GA330@us.ibm.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ryan Harper Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On 23 Sep 2005, at 20:49, Ryan Harper wrote: > Why does Xen chose to use mode 0, on PIT CH2 for calculating how much > time has passed rather than how Linux using PIT_CH0 in mode 2? Are > there some trade offs? The way we track time in Xen is completely different to Linux. Linux tracks time off periodic interrupts from PIT_CH0: initially assuming each tick is 10ms but allowing that to be trimmed by adjtimex if ntpd is running. Xen only uses PIT_CH0 as a fallback timer on uniprocessor systems with no local APIC: aprt from that it is basically unused. Xen doesn't rely on fixed periodic interrupts -- instead programming the local APIC timer to the next event of interest. We track time by assuming the PIT crystal is a precise 1.119380Mhz source: we can therefore measure the passage of time by reading how far PIT_CH2 has decremented and perform a multiplication. To more quickly estimate the passage of time, each CPU calibrates its local APIC oscillator to PIT_CH2 -- we can then estimate time-of-day with a RDTSC instruction + multiplication. The main problem with using PIT as platform timer is that the counters are only 16 bits. We therefore periodically (every few 10s of ms) read the PIT_CH2 delta out into a wider 64-bit variable. -- Keir