public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* pv clock: kvm is incompatible with xen :-(
@ 2008-04-11  7:33 Gerd Hoffmann
  2008-04-11 12:06 ` Avi Kivity
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2008-04-11  7:33 UTC (permalink / raw)
  To: kvm-devel, Glauber de Oliveira Costa, Avi Kivity; +Cc: Jeremy Fitzhardinge

  Hi,

Tried to use kvmclock with xenner and noticed that the kvmclock
(MSR_KVM_SYSTEM_TIME msr) is incompatible with xen.

kvm guests do this to translate the tsc delta into nsecs:

   #define get_clock(cpu, field) per_cpu(hv_clock, cpu).field

   static inline u64 kvm_get_delta(u64 last_tsc)
   {
           int cpu = smp_processor_id();
           u64 delta = native_read_tsc() - last_tsc;
           return (delta * get_clock(cpu, tsc_to_system_mul)) >> 22;
   }

whereas xen guests do this (64bit version):

   static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift)
   {
           u64 product;

           if (shift < 0)
                   delta >>= -shift;
           else
                   delta <<= shift;

           __asm__ (
                   "mul %%rdx ; shrd $32,%%rdx,%%rax"
                   : "=a" (product) : "0" (delta), "d" ((u64)mul_frac));
           return product;
   }

Note that xen does a 64bit multiply (of the 64bit delta and the 32bit
factor) yielding a 128bit result, then picking bits 32-95 for the 64bit
return value.  In contrast kvm does a simple 64bit multiply, which is
equivalent to using the lowest 64 bits.  Thus kvm is off by factor 2^32,
and that without even considering the ordering of two (shift + multiply)
operations and any rounding errors ...

cheers,
  Gerd

-- 
http://kraxel.fedorapeople.org/xenner/

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-04-24 12:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-11  7:33 pv clock: kvm is incompatible with xen :-( Gerd Hoffmann
2008-04-11 12:06 ` Avi Kivity
2008-04-11 13:44   ` Gerd Hoffmann
2008-04-11 15:01     ` Gerd Hoffmann
2008-04-11 19:02     ` Jeremy Fitzhardinge
2008-04-18 14:26       ` Gerd Hoffmann
2008-04-18 22:23         ` Jeremy Fitzhardinge
2008-04-21  7:31           ` Gerd Hoffmann
2008-04-21 11:46             ` Jeremy Fitzhardinge
2008-04-21 12:50               ` Gerd Hoffmann
2008-04-21 13:34                 ` Jeremy Fitzhardinge
2008-04-21 14:20                   ` Gerd Hoffmann
2008-04-22 17:54                 ` Glauber Costa
2008-04-23  6:03                   ` Gerd Hoffmann
2008-04-24 12:57                     ` Glauber Costa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox