Re: TSC in qem[-kvm] 1.1+ and in-kernel irqchip

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <<EOF
set timeout=10000
menuentry 'test' {
  echo "booted:"; read line
}
EOF
grub-mkrescue -o ../grub.iso .

kvm -cdrom ../grub.iso


This should show a menu with single entry "test",
and wait for 10000 seconds, with a countdown.
10000 is enough to actually see it -- with reasonable
timeout it isn't easy to see that it displays the
menu, instead it immediately goes to the booting,
displaying the "booted:" line.


kvm -cdrom ../grub.iso -cpu host,-tsc
kvm -cdrom ../grub.iso -no-kvm-irqchip
...
-- these works fine.

Tried with grub from debian wheezy (1.99-22.1) and
from ubuntu 12.04, but i guess it should be the
same with various versions of grub.

Thanks!

/mjt
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux