blob: 7f7e577a0e39cfca111c5a0b4718480b01c86170 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PVCLOCK_H
2#define _ASM_X86_PVCLOCK_H
Gerd Hoffmann7af192c2008-06-03 16:17:29 +02003
4#include <linux/clocksource.h>
5#include <asm/pvclock-abi.h>
6
7/* some helper functions for xen and kvm pv clock sources */
8cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
Glauber Costa424c32f2010-05-11 12:17:39 -04009void pvclock_set_flags(u8 flags);
Glauber Costa3807f342008-07-28 11:47:52 -030010unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
Gerd Hoffmann7af192c2008-06-03 16:17:29 +020011void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
12 struct pvclock_vcpu_time_info *vcpu,
13 struct timespec *ts);
14
Zachary Amsden347bb442010-08-19 22:07:29 -100015/*
16 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
17 * yielding a 64-bit result.
18 */
19static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
20{
21 u64 product;
22#ifdef __i386__
23 u32 tmp1, tmp2;
24#endif
25
26 if (shift < 0)
27 delta >>= -shift;
28 else
29 delta <<= shift;
30
31#ifdef __i386__
32 __asm__ (
33 "mul %5 ; "
34 "mov %4,%%eax ; "
35 "mov %%edx,%4 ; "
36 "mul %5 ; "
37 "xor %5,%5 ; "
38 "add %4,%%eax ; "
39 "adc %5,%%edx ; "
40 : "=A" (product), "=r" (tmp1), "=r" (tmp2)
41 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
42#elif defined(__x86_64__)
43 __asm__ (
44 "mul %%rdx ; shrd $32,%%rdx,%%rax"
45 : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
46#else
47#error implement me!
48#endif
49
50 return product;
51}
52
H. Peter Anvin1965aae2008-10-22 22:26:29 -070053#endif /* _ASM_X86_PVCLOCK_H */