1 #ifndef _ASM_X86_PVCLOCK_H
2 #define _ASM_X86_PVCLOCK_H
4 #include <linux/clocksource.h>
5 #include <asm/pvclock-abi.h>
7 #ifdef CONFIG_KVM_GUEST
8 extern struct pvclock_vsyscall_time_info
*pvclock_pvti_cpu0_va(void);
10 static inline struct pvclock_vsyscall_time_info
*pvclock_pvti_cpu0_va(void)
16 /* some helper functions for xen and kvm pv clock sources */
17 u64
pvclock_clocksource_read(struct pvclock_vcpu_time_info
*src
);
18 u8
pvclock_read_flags(struct pvclock_vcpu_time_info
*src
);
19 void pvclock_set_flags(u8 flags
);
20 unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info
*src
);
21 void pvclock_read_wallclock(struct pvclock_wall_clock
*wall
,
22 struct pvclock_vcpu_time_info
*vcpu
,
24 void pvclock_resume(void);
26 void pvclock_touch_watchdogs(void);
28 static __always_inline
29 unsigned pvclock_read_begin(const struct pvclock_vcpu_time_info
*src
)
31 unsigned version
= src
->version
& ~1;
32 /* Make sure that the version is read before the data. */
37 static __always_inline
38 bool pvclock_read_retry(const struct pvclock_vcpu_time_info
*src
,
41 /* Make sure that the version is re-read after the data. */
43 return unlikely(version
!= src
->version
);
47 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
48 * yielding a 64-bit result.
50 static inline u64
pvclock_scale_delta(u64 delta
, u32 mul_frac
, int shift
)
73 : "=A" (product
), "=r" (tmp1
), "=r" (tmp2
)
74 : "a" ((u32
)delta
), "1" ((u32
)(delta
>> 32)), "2" (mul_frac
) );
75 #elif defined(__x86_64__)
77 "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
81 [mul_frac
]"rm"((u64
)mul_frac
));
89 static __always_inline
90 u64
__pvclock_read_cycles(const struct pvclock_vcpu_time_info
*src
, u64 tsc
)
92 u64 delta
= tsc
- src
->tsc_timestamp
;
93 u64 offset
= pvclock_scale_delta(delta
, src
->tsc_to_system_mul
,
95 return src
->system_time
+ offset
;
98 struct pvclock_vsyscall_time_info
{
99 struct pvclock_vcpu_time_info pvti
;
100 } __attribute__((__aligned__(SMP_CACHE_BYTES
)));
102 #define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
104 #endif /* _ASM_X86_PVCLOCK_H */