H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_PVCLOCK_H |
| 2 | #define _ASM_X86_PVCLOCK_H |
Gerd Hoffmann | 7af192c | 2008-06-03 16:17:29 +0200 | [diff] [blame] | 3 | |
| 4 | #include <linux/clocksource.h> |
| 5 | #include <asm/pvclock-abi.h> |
| 6 | |
| 7 | /* some helper functions for xen and kvm pv clock sources */ |
| 8 | cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src); |
Glauber Costa | 424c32f | 2010-05-11 12:17:39 -0400 | [diff] [blame] | 9 | void pvclock_set_flags(u8 flags); |
Glauber Costa | 3807f34 | 2008-07-28 11:47:52 -0300 | [diff] [blame] | 10 | unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src); |
Gerd Hoffmann | 7af192c | 2008-06-03 16:17:29 +0200 | [diff] [blame] | 11 | void pvclock_read_wallclock(struct pvclock_wall_clock *wall, |
| 12 | struct pvclock_vcpu_time_info *vcpu, |
| 13 | struct timespec *ts); |
Jeremy Fitzhardinge | e7a3481c | 2010-10-25 16:53:46 -0700 | [diff] [blame] | 14 | void pvclock_resume(void); |
Gerd Hoffmann | 7af192c | 2008-06-03 16:17:29 +0200 | [diff] [blame] | 15 | |
Zachary Amsden | 347bb44 | 2010-08-19 22:07:29 -1000 | [diff] [blame] | 16 | /* |
| 17 | * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, |
| 18 | * yielding a 64-bit result. |
| 19 | */ |
| 20 | static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift) |
| 21 | { |
| 22 | u64 product; |
| 23 | #ifdef __i386__ |
| 24 | u32 tmp1, tmp2; |
Zachary Amsden | de2d1a5 | 2011-06-15 20:50:04 -0700 | [diff] [blame] | 25 | #else |
| 26 | ulong tmp; |
Zachary Amsden | 347bb44 | 2010-08-19 22:07:29 -1000 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | if (shift < 0) |
| 30 | delta >>= -shift; |
| 31 | else |
| 32 | delta <<= shift; |
| 33 | |
| 34 | #ifdef __i386__ |
| 35 | __asm__ ( |
| 36 | "mul %5 ; " |
| 37 | "mov %4,%%eax ; " |
| 38 | "mov %%edx,%4 ; " |
| 39 | "mul %5 ; " |
| 40 | "xor %5,%5 ; " |
| 41 | "add %4,%%eax ; " |
| 42 | "adc %5,%%edx ; " |
| 43 | : "=A" (product), "=r" (tmp1), "=r" (tmp2) |
| 44 | : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) ); |
| 45 | #elif defined(__x86_64__) |
| 46 | __asm__ ( |
Duncan Sands | 3b21711 | 2011-08-30 10:58:22 +0200 | [diff] [blame] | 47 | "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]" |
Zachary Amsden | de2d1a5 | 2011-06-15 20:50:04 -0700 | [diff] [blame] | 48 | : [lo]"=a"(product), |
| 49 | [hi]"=d"(tmp) |
| 50 | : "0"(delta), |
| 51 | [mul_frac]"rm"((u64)mul_frac)); |
Zachary Amsden | 347bb44 | 2010-08-19 22:07:29 -1000 | [diff] [blame] | 52 | #else |
| 53 | #error implement me! |
| 54 | #endif |
| 55 | |
| 56 | return product; |
| 57 | } |
| 58 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 59 | #endif /* _ASM_X86_PVCLOCK_H */ |