From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tokarev Subject: Re: TSC in qem[-kvm] 1.1+ and in-kernel irqchip Date: Fri, 10 Aug 2012 01:36:32 +0400 Message-ID: <50242D60.40703@msgid.tls.msk.ru> References: <5024011F.2020200@msgid.tls.msk.ru> <20120809190633.GF20889@amt.cnet> <20120809204748.GA32346@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: KVM list , Avi Kivity , Gerd Hoffmann , qemu-devel To: Marcelo Tosatti Return-path: Received: from isrv.corpit.ru ([86.62.121.231]:58817 "EHLO isrv.corpit.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753647Ab2HIVge (ORCPT ); Thu, 9 Aug 2012 17:36:34 -0400 In-Reply-To: <20120809204748.GA32346@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 10.08.2012 00:47, Marcelo Tosatti wrote: [] >>> calibrate_tsc (void) >>> { >>> /* First calibrate the TSC rate (relative, not absolute time). */ >>> grub_uint64_t start_tsc; >>> grub_uint64_t end_tsc; >>> >>> start_tsc = grub_get_tsc (); >>> grub_pit_wait (0xffff); >>> end_tsc = grub_get_tsc (); >>> >>> tsc_ticks_per_ms = grub_divmod64 (end_tsc - start_tsc, 55, 0); >>> } >> >> Emulation of grub_pit_wait sequence by in-kernel PIT is probably broken. This is grub_pit_wait(): #define TIMER2_REG_CONTROL 0x42 #define TIMER_REG_COMMAND 0x43 #define TIMER2_REG_LATCH 0x61 #define TIMER2_SELECT 0x80 #define TIMER_ENABLE_LSB 0x20 #define TIMER_ENABLE_MSB 0x10 #define TIMER2_LATCH 0x20 #define TIMER2_SPEAKER 0x02 #define TIMER2_GATE 0x01 void grub_pit_wait (grub_uint16_t tics) { /* Disable timer2 gate and speaker. */ grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE), TIMER2_REG_LATCH); /* Set tics. */ grub_outb (TIMER2_SELECT | TIMER_ENABLE_LSB | TIMER_ENABLE_MSB, TIMER_REG_COMMAND); grub_outb (tics & 0xff, TIMER2_REG_CONTROL); grub_outb (tics >> 8, TIMER2_REG_CONTROL); /* Enable timer2 gate, keep speaker disabled. */ grub_outb ((grub_inb (TIMER2_REG_LATCH) & ~ TIMER2_SPEAKER) | TIMER2_GATE, TIMER2_REG_LATCH); /* Wait. */ while ((grub_inb (TIMER2_REG_LATCH) & TIMER2_LATCH) == 0x00); /* Disable timer2 gate and speaker. */ grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE), TIMER2_REG_LATCH); } >> QEMU PIT emulation is also affected by miscalibration. >> >> Please provide steps to reproduce. > > I mean verbose on the steps (does it happen always when setting timeout=10000, > how to set timeout=10000, etc). untested: mkdir /tmp/grub cd /tmp/grub mkdir boot boot/grub cat > boot/grub/grub.cfg <