pvclock.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #else
  23. ulong tmp;
  24. #endif
  25. if (shift < 0)
  26. delta >>= -shift;
  27. else
  28. delta <<= shift;
  29. #ifdef __i386__
  30. __asm__ (
  31. "mul %5 ; "
  32. "mov %4,%%eax ; "
  33. "mov %%edx,%4 ; "
  34. "mul %5 ; "
  35. "xor %5,%5 ; "
  36. "add %4,%%eax ; "
  37. "adc %5,%%edx ; "
  38. : "=A" (product), "=r" (tmp1), "=r" (tmp2)
  39. : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
  40. #elif defined(__x86_64__)
  41. __asm__ (
  42. "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
  43. : [lo]"=a"(product),
  44. [hi]"=d"(tmp)
  45. : "0"(delta),
  46. [mul_frac]"rm"((u64)mul_frac));
  47. #else
  48. #error implement me!
  49. #endif
  50. return product;
  51. }
  52. #endif /* _ASM_X86_PVCLOCK_H */