0001
0002 #ifndef _ASM_X86_PVCLOCK_H
0003 #define _ASM_X86_PVCLOCK_H
0004
0005 #include <asm/clocksource.h>
0006 #include <asm/pvclock-abi.h>
0007
0008
0009 u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
0010 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src);
0011 void pvclock_set_flags(u8 flags);
0012 unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
0013 void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
0014 struct pvclock_vcpu_time_info *vcpu,
0015 struct timespec64 *ts);
0016 void pvclock_resume(void);
0017
0018 void pvclock_touch_watchdogs(void);
0019
0020 static __always_inline
0021 unsigned pvclock_read_begin(const struct pvclock_vcpu_time_info *src)
0022 {
0023 unsigned version = src->version & ~1;
0024
0025 virt_rmb();
0026 return version;
0027 }
0028
0029 static __always_inline
0030 bool pvclock_read_retry(const struct pvclock_vcpu_time_info *src,
0031 unsigned version)
0032 {
0033
0034 virt_rmb();
0035 return unlikely(version != src->version);
0036 }
0037
0038
0039
0040
0041
0042 static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
0043 {
0044 u64 product;
0045 #ifdef __i386__
0046 u32 tmp1, tmp2;
0047 #else
0048 ulong tmp;
0049 #endif
0050
0051 if (shift < 0)
0052 delta >>= -shift;
0053 else
0054 delta <<= shift;
0055
0056 #ifdef __i386__
0057 __asm__ (
0058 "mul %5 ; "
0059 "mov %4,%%eax ; "
0060 "mov %%edx,%4 ; "
0061 "mul %5 ; "
0062 "xor %5,%5 ; "
0063 "add %4,%%eax ; "
0064 "adc %5,%%edx ; "
0065 : "=A" (product), "=r" (tmp1), "=r" (tmp2)
0066 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
0067 #elif defined(__x86_64__)
0068 __asm__ (
0069 "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
0070 : [lo]"=a"(product),
0071 [hi]"=d"(tmp)
0072 : "0"(delta),
0073 [mul_frac]"rm"((u64)mul_frac));
0074 #else
0075 #error implement me!
0076 #endif
0077
0078 return product;
0079 }
0080
0081 static __always_inline
0082 u64 __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src, u64 tsc)
0083 {
0084 u64 delta = tsc - src->tsc_timestamp;
0085 u64 offset = pvclock_scale_delta(delta, src->tsc_to_system_mul,
0086 src->tsc_shift);
0087 return src->system_time + offset;
0088 }
0089
0090 struct pvclock_vsyscall_time_info {
0091 struct pvclock_vcpu_time_info pvti;
0092 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
0093
0094 #define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
0095
0096 #ifdef CONFIG_PARAVIRT_CLOCK
0097 void pvclock_set_pvti_cpu0_va(struct pvclock_vsyscall_time_info *pvti);
0098 struct pvclock_vsyscall_time_info *pvclock_get_pvti_cpu0_va(void);
0099 #else
0100 static inline struct pvclock_vsyscall_time_info *pvclock_get_pvti_cpu0_va(void)
0101 {
0102 return NULL;
0103 }
0104 #endif
0105
0106 #endif