]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/clock.h
ee52ad8f20249dcb159611844d4580fce6f931ad
[apple/xnu.git] / osfmk / kern / clock.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 */
27
28 #ifndef _KERN_CLOCK_H_
29 #define _KERN_CLOCK_H_
30
31 #include <stdint.h>
32 #include <mach/mach_types.h>
33 #include <mach/clock_types.h>
34 #include <mach/message.h>
35 #include <mach/mach_time.h>
36
37 #include <kern/kern_types.h>
38
39 #include <sys/cdefs.h>
40
41 #ifdef MACH_KERNEL_PRIVATE
42
43 /*
44 * Clock operations list structure. Contains vectors to machine
45 * dependent clock routines.
46 */
47 struct clock_ops {
48 int (*c_config)(void); /* configuration */
49
50 int (*c_init)(void); /* initialize */
51
52 kern_return_t (*c_gettime)( /* get time */
53 mach_timespec_t *cur_time);
54
55 kern_return_t (*c_getattr)( /* get attributes */
56 clock_flavor_t flavor,
57 clock_attr_t attr,
58 mach_msg_type_number_t *count);
59 };
60 typedef struct clock_ops *clock_ops_t;
61 typedef struct clock_ops clock_ops_data_t;
62
63 /*
64 * Actual clock object data structure. Contains the machine
65 * dependent operations list and clock operation ports.
66 */
67 struct clock {
68 clock_ops_t cl_ops; /* operations list */
69 struct ipc_port *cl_service; /* service port */
70 struct ipc_port *cl_control; /* control port */
71 };
72 typedef struct clock clock_data_t;
73
74 /*
75 * Configure the clock system.
76 */
77 extern void clock_config(void);
78 extern void clock_oldconfig(void);
79
80 /*
81 * Initialize the clock system.
82 */
83 extern void clock_init(void);
84 extern void clock_oldinit(void);
85
86 extern void clock_timebase_init(void);
87
88 /*
89 * Initialize the clock ipc service facility.
90 */
91 extern void clock_service_create(void);
92
93 typedef void (*clock_timer_func_t)(
94 uint64_t timestamp);
95
96 extern void clock_set_timer_func(
97 clock_timer_func_t func);
98
99 extern void clock_set_timer_deadline(
100 uint64_t deadline);
101
102 extern void clock_gettimeofday_set_commpage(
103 uint64_t abstime,
104 uint64_t epoch,
105 uint64_t offset,
106 uint32_t *secs,
107 uint32_t *microsecs);
108
109 extern void machine_delay_until(
110 uint64_t deadline);
111
112 #include <stat_time.h>
113
114 extern void hertz_tick(
115 #if STAT_TIME
116 natural_t ticks,
117 #endif /* STAT_TIME */
118 boolean_t usermode, /* executing user code */
119 natural_t pc);
120
121 extern void absolutetime_to_microtime(
122 uint64_t abstime,
123 uint32_t *secs,
124 uint32_t *microsecs);
125
126 extern void absolutetime_to_nanotime(
127 uint64_t abstime,
128 uint32_t *secs,
129 uint32_t *nanosecs);
130
131 extern void nanotime_to_absolutetime(
132 uint32_t secs,
133 uint32_t nanosecs,
134 uint64_t *result);
135
136 #endif /* MACH_KERNEL_PRIVATE */
137
138 __BEGIN_DECLS
139
140 #ifdef XNU_KERNEL_PRIVATE
141
142 extern void clock_adjtime(
143 int32_t *secs,
144 int32_t *microsecs);
145
146 extern void clock_initialize_calendar(void);
147
148 extern void clock_wakeup_calendar(void);
149
150 extern void clock_gettimeofday(
151 uint32_t *secs,
152 uint32_t *microsecs);
153
154 extern void clock_set_calendar_microtime(
155 uint32_t secs,
156 uint32_t microsecs);
157
158 extern void clock_get_boottime_nanotime(
159 uint32_t *secs,
160 uint32_t *nanosecs);
161
162 extern void clock_deadline_for_periodic_event(
163 uint64_t interval,
164 uint64_t abstime,
165 uint64_t *deadline);
166
167 #endif /* XNU_KERNEL_PRIVATE */
168
169
170 extern void clock_get_calendar_microtime(
171 uint32_t *secs,
172 uint32_t *microsecs);
173
174 extern void clock_get_calendar_nanotime(
175 uint32_t *secs,
176 uint32_t *nanosecs);
177
178 extern void clock_get_system_microtime(
179 uint32_t *secs,
180 uint32_t *microsecs);
181
182 extern void clock_get_system_nanotime(
183 uint32_t *secs,
184 uint32_t *nanosecs);
185
186 extern void clock_timebase_info(
187 mach_timebase_info_t info);
188
189 extern void clock_get_uptime(
190 uint64_t *result);
191
192 extern void clock_interval_to_deadline(
193 uint32_t interval,
194 uint32_t scale_factor,
195 uint64_t *result);
196
197 extern void clock_interval_to_absolutetime_interval(
198 uint32_t interval,
199 uint32_t scale_factor,
200 uint64_t *result);
201
202 extern void clock_absolutetime_interval_to_deadline(
203 uint64_t abstime,
204 uint64_t *result);
205
206 extern void clock_delay_until(
207 uint64_t deadline);
208
209 extern void absolutetime_to_nanoseconds(
210 uint64_t abstime,
211 uint64_t *result);
212
213 extern void nanoseconds_to_absolutetime(
214 uint64_t nanoseconds,
215 uint64_t *result);
216
217 #ifdef KERNEL_PRIVATE
218
219 /*
220 * Obsolete interfaces.
221 */
222
223 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
224 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
225
226 #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \
227 MACH_TIMESPEC_SEC_MAX, \
228 MACH_TIMESPEC_NSEC_MAX } )
229 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
230
231 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
232 do { \
233 (t1)->tv_nsec += (clock_res_t)(nsec); \
234 if ((clock_res_t)(nsec) > 0 && \
235 (t1)->tv_nsec >= NSEC_PER_SEC) { \
236 (t1)->tv_nsec -= NSEC_PER_SEC; \
237 (t1)->tv_sec += 1; \
238 } \
239 else if ((clock_res_t)(nsec) < 0 && \
240 (t1)->tv_nsec < 0) { \
241 (t1)->tv_nsec += NSEC_PER_SEC; \
242 (t1)->tv_sec -= 1; \
243 } \
244 } while (0)
245
246
247 extern mach_timespec_t clock_get_system_value(void);
248
249 extern mach_timespec_t clock_get_calendar_value(void);
250
251 extern void delay_for_interval(
252 uint32_t interval,
253 uint32_t scale_factor);
254 #ifndef MACH_KERNEL_PRIVATE
255
256 #ifndef ABSOLUTETIME_SCALAR_TYPE
257
258 #define clock_get_uptime(a) \
259 clock_get_uptime(__OSAbsoluteTimePtr(a))
260
261 #define clock_interval_to_deadline(a, b, c) \
262 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
263
264 #define clock_interval_to_absolutetime_interval(a, b, c) \
265 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
266
267 #define clock_absolutetime_interval_to_deadline(a, b) \
268 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
269
270 #define clock_deadline_for_periodic_event(a, b, c) \
271 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
272
273 #define clock_delay_until(a) \
274 clock_delay_until(__OSAbsoluteTime(a))
275
276 #define absolutetime_to_nanoseconds(a, b) \
277 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
278
279 #define nanoseconds_to_absolutetime(a, b) \
280 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
281
282 #endif /* ABSOLUTETIME_SCALAR_TYPE */
283
284 #endif /* !MACH_KERNEL_PRIVATE */
285
286 #endif /* KERNEL_PRIVATE */
287
288 __END_DECLS
289
290 #endif /* _KERN_CLOCK_H_ */