1 /******************************************************************************
2  * time.h
3  *
4  * Copyright (c) 2002-2003 Rolf Neugebauer
5  * Copyright (c) 2002-2005 K A Fraser
6  */
7 
8 #ifndef __XEN_TIME_H__
9 #define __XEN_TIME_H__
10 
11 #include <xen/types.h>
12 #include <public/xen.h>
13 
14 extern int init_xen_time(void);
15 extern void cstate_restore_tsc(void);
16 
17 extern unsigned long cpu_khz;
18 extern unsigned long pit0_ticks;
19 
20 struct domain;
21 struct vcpu;
22 
23 /*
24  * System Time
25  * 64 bit value containing the nanoseconds elapsed since boot time.
26  * This value is adjusted by frequency drift.
27  * NOW() returns the current time.
28  * The other macros are for convenience to approximate short intervals
29  * of real time into system time
30  */
31 
32 typedef s64 s_time_t;
33 #define PRI_stime PRId64
34 
35 s_time_t get_s_time_fixed(u64 at_tick);
36 s_time_t get_s_time(void);
37 unsigned long get_localtime(struct domain *d);
38 uint64_t get_localtime_us(struct domain *d);
39 
40 struct tm {
41     int     tm_sec;         /* seconds */
42     int     tm_min;         /* minutes */
43     int     tm_hour;        /* hours */
44     int     tm_mday;        /* day of the month */
45     int     tm_mon;         /* month */
46     int     tm_year;        /* year */
47     int     tm_wday;        /* day of the week */
48     int     tm_yday;        /* day in the year */
49     int     tm_isdst;       /* daylight saving time */
50 };
51 struct tm gmtime(unsigned long t);
52 struct tm wallclock_time(uint64_t *ns);
53 
54 #define SYSTEM_TIME_HZ  1000000000ULL
55 #define NOW()           ((s_time_t)get_s_time())
56 #define SECONDS(_s)     ((s_time_t)((_s)  * 1000000000ULL))
57 #define MILLISECS(_ms)  ((s_time_t)((_ms) * 1000000ULL))
58 #define MICROSECS(_us)  ((s_time_t)((_us) * 1000ULL))
59 #define STIME_MAX ((s_time_t)((uint64_t)~0ull>>1))
60 /* Chosen so (NOW() + delta) wont overflow without an uptime of 200 years */
61 #define STIME_DELTA_MAX ((s_time_t)((uint64_t)~0ull>>2))
62 
63 /* Explicitly OR with 1 just in case version number gets out of sync. */
64 #define version_update_begin(v) (((v) + 1) | 1)
65 #define version_update_end(v)   ((v) + 1)
66 extern void update_vcpu_system_time(struct vcpu *v);
67 extern void update_domain_wallclock_time(struct domain *d);
68 
69 extern void do_settime(
70     u64 secs, unsigned int nsecs, u64 system_time_base);
71 
72 extern void send_timer_event(struct vcpu *v);
73 
74 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds);
75 
76 #include <asm/time.h>
77 
78 #endif /* __XEN_TIME_H__ */
79 
80 /*
81  * Local variables:
82  * mode: C
83  * c-file-style: "BSD"
84  * c-basic-offset: 4
85  * tab-width: 4
86  * indent-tabs-mode: nil
87  * End:
88  */
89