pvclock.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. void pvclock_resume(void);
  13. /*
  14. * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
  15. * yielding a 64-bit result.
  16. */
  17. static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
  18. {
  19. u64 product;
  20. #ifdef __i386__
  21. u32 tmp1, tmp2;
  22. #endif
  23. if (shift < 0)
  24. delta >>= -shift;
  25. else
  26. delta <<= shift;
  27. #ifdef __i386__
  28. __asm__ (
  29. "mul %5 ; "
  30. "mov %4,%%eax ; "
  31. "mov %%edx,%4 ; "
  32. "mul %5 ; "
  33. "xor %5,%5 ; "
  34. "add %4,%%eax ; "
  35. "adc %5,%%edx ; "
  36. : "=A" (product), "=r" (tmp1), "=r" (tmp2)
  37. : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
  38. #elif defined(__x86_64__)
  39. __asm__ (
  40. "mul %%rdx ; shrd $32,%%rdx,%%rax"
  41. : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
  42. #else
  43. #error implement me!
  44. #endif
  45. return product;
  46. }
  47. #endif /* _ASM_X86_PVCLOCK_H */