1 #ifndef _ASM_X86_PVCLOCK_H
2 #define _ASM_X86_PVCLOCK_H
4 #include <linux/clocksource.h>
5 #include <asm/pvclock-abi.h>
7 /* some helper functions for xen and kvm pv clock sources */
8 cycle_t
pvclock_clocksource_read(struct pvclock_vcpu_time_info
*src
);
9 u8
pvclock_read_flags(struct pvclock_vcpu_time_info
*src
);
10 void pvclock_set_flags(u8 flags
);
11 unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info
*src
);
12 void pvclock_read_wallclock(struct pvclock_wall_clock
*wall
,
13 struct pvclock_vcpu_time_info
*vcpu
,
15 void pvclock_resume(void);
18 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
19 * yielding a 64-bit result.
21 static inline u64
pvclock_scale_delta(u64 delta
, u32 mul_frac
, int shift
)
44 : "=A" (product
), "=r" (tmp1
), "=r" (tmp2
)
45 : "a" ((u32
)delta
), "1" ((u32
)(delta
>> 32)), "2" (mul_frac
) );
46 #elif defined(__x86_64__)
48 "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
52 [mul_frac
]"rm"((u64
)mul_frac
));
60 static __always_inline
61 u64
pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info
*src
)
63 u64 delta
= __native_read_tsc() - src
->tsc_timestamp
;
64 return pvclock_scale_delta(delta
, src
->tsc_to_system_mul
,
68 static __always_inline
69 unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info
*src
,
70 cycle_t
*cycles
, u8
*flags
)
76 version
= src
->version
;
77 /* Note: emulated platforms which do not advertise SSE2 support
78 * result in kvmclock not using the necessary RDTSC barriers.
79 * Without barriers, it is possible that RDTSC instruction reads from
80 * the time stamp counter outside rdtsc_barrier protected section
81 * below, resulting in violation of monotonicity.
84 offset
= pvclock_get_nsec_offset(src
);
85 ret
= src
->system_time
+ offset
;
86 ret_flags
= src
->flags
;
94 struct pvclock_vsyscall_time_info
{
95 struct pvclock_vcpu_time_info pvti
;
97 } __attribute__((__aligned__(SMP_CACHE_BYTES
)));
99 #define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
100 #define PVCLOCK_VSYSCALL_NR_PAGES (((NR_CPUS-1)/(PAGE_SIZE/PVTI_SIZE))+1)
102 int __init
pvclock_init_vsyscall(struct pvclock_vsyscall_time_info
*i
,
104 struct pvclock_vcpu_time_info
*pvclock_get_vsyscall_time_info(int cpu
);
106 #endif /* _ASM_X86_PVCLOCK_H */