1
2 #ifndef __X86_TIME_H__
3 #define __X86_TIME_H__
4
5 #include <asm/msr.h>
6
7 /*
8 * PV TSC emulation modes:
9 * 0 = guest rdtsc/p executed natively when monotonicity can be guaranteed
10 * and emulated otherwise (with frequency scaled if necessary)
11 * 1 = guest rdtsc/p always emulated at 1GHz (kernel and user)
12 * 2 = guest rdtsc always executed natively (no monotonicity/frequency
13 * guarantees); guest rdtscp emulated at native frequency if
14 * unsupported by h/w, else executed natively
15 * 3 = Removed, was PVRDTSCP.
16 */
17 #define TSC_MODE_DEFAULT 0
18 #define TSC_MODE_ALWAYS_EMULATE 1
19 #define TSC_MODE_NEVER_EMULATE 2
20
21 typedef u64 cycles_t;
22
23 extern bool disable_tsc_sync;
24
get_cycles(void)25 static inline cycles_t get_cycles(void)
26 {
27 return rdtsc_ordered();
28 }
29
30 unsigned long
31 mktime (unsigned int year, unsigned int mon,
32 unsigned int day, unsigned int hour,
33 unsigned int min, unsigned int sec);
34
35 int time_suspend(void);
36 int time_resume(void);
37
38 void init_percpu_time(void);
39 void time_latch_stamps(void);
40
41 struct ioreq;
42 int hwdom_pit_access(struct ioreq *ioreq);
43
44 int cpu_frequency_change(u64 freq);
45
46 void pit_broadcast_enter(void);
47 void pit_broadcast_exit(void);
48 int pit_broadcast_is_available(void);
49
50 uint64_t acpi_pm_tick_to_ns(uint64_t ticks);
51 uint64_t ns_to_acpi_pm_tick(uint64_t ns);
52
53 uint64_t tsc_ticks2ns(uint64_t ticks);
54
55 uint64_t pv_soft_rdtsc(const struct vcpu *v, const struct cpu_user_regs *regs);
56 u64 gtime_to_gtsc(struct domain *d, u64 time);
57 u64 gtsc_to_gtime(struct domain *d, u64 tsc);
58
59 int tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nsec,
60 uint32_t gtsc_khz, uint32_t incarnation);
61
62 void tsc_get_info(struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec,
63 uint32_t *gtsc_khz, uint32_t *incarnation);
64
65
66 void force_update_vcpu_system_time(struct vcpu *v);
67
68 bool clocksource_is_tsc(void);
69 int host_tsc_is_safe(void);
70 u64 stime2tsc(s_time_t stime);
71
72 struct time_scale;
73 void set_time_scale(struct time_scale *ts, u64 ticks_per_sec);
74 u64 scale_delta(u64 delta, const struct time_scale *scale);
75
76 #endif /* __X86_TIME_H__ */
77