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 cycle_t
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);
29 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
30 * yielding a 64-bit result.
32 static inline u64
pvclock_scale_delta(u64 delta
, u32 mul_frac
, int shift
)
55 : "=A" (product
), "=r" (tmp1
), "=r" (tmp2
)
56 : "a" ((u32
)delta
), "1" ((u32
)(delta
>> 32)), "2" (mul_frac
) );
57 #elif defined(__x86_64__)
59 "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
63 [mul_frac
]"rm"((u64
)mul_frac
));
71 static __always_inline
72 u64
pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info
*src
)
74 u64 delta
= rdtsc_ordered() - src
->tsc_timestamp
;
75 return pvclock_scale_delta(delta
, src
->tsc_to_system_mul
,
79 static __always_inline
80 unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info
*src
,
81 cycle_t
*cycles
, u8
*flags
)
87 version
= src
->version
;
89 offset
= pvclock_get_nsec_offset(src
);
90 ret
= src
->system_time
+ offset
;
91 ret_flags
= src
->flags
;
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 */