pvclock.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _ASM_X86_PVCLOCK_H
  2. #define _ASM_X86_PVCLOCK_H
  3. #include <linux/clocksource.h>
  4. #include <asm/pvclock-abi.h>
  5. /* some helper functions for xen and kvm pv clock sources */
  6. cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
  7. void pvclock_set_flags(u8 flags);
  8. unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
  9. void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
  10. struct pvclock_vcpu_time_info *vcpu,
  11. struct timespec *ts);
  12. /*
  13. * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
  14. * yielding a 64-bit result.
  15. */
  16. static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
  17. {
  18. u64 product;
  19. #ifdef __i386__
  20. u32 tmp1, tmp2;
  21. #endif
  22. if (shift < 0)
  23. delta >>= -shift;
  24. else
  25. delta <<= shift;
  26. #ifdef __i386__
  27. __asm__ (
  28. "mul %5 ; "
  29. "mov %4,%%eax ; "
  30. "mov %%edx,%4 ; "
  31. "mul %5 ; "
  32. "xor %5,%5 ; "
  33. "add %4,%%eax ; "
  34. "adc %5,%%edx ; "
  35. : "=A" (product), "=r" (tmp1), "=r" (tmp2)
  36. : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
  37. #elif defined(__x86_64__)
  38. __asm__ (
  39. "mul %%rdx ; shrd $32,%%rdx,%%rax"
  40. : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
  41. #else
  42. #error implement me!
  43. #endif
  44. return product;
  45. }
  46. #endif /* _ASM_X86_PVCLOCK_H */