]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
c910b4d9 | 2 | * Copyright (c) 2000-2008 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
1c79356b A |
32 | */ |
33 | ||
34 | #ifndef _KERN_CLOCK_H_ | |
35 | #define _KERN_CLOCK_H_ | |
36 | ||
91447636 A |
37 | #include <stdint.h> |
38 | #include <mach/mach_types.h> | |
1c79356b | 39 | #include <mach/clock_types.h> |
91447636 | 40 | #include <mach/message.h> |
1c79356b | 41 | #include <mach/mach_time.h> |
39037602 | 42 | #include <mach/boolean.h> |
1c79356b | 43 | |
91447636 | 44 | #include <kern/kern_types.h> |
9bccf70c | 45 | |
91447636 | 46 | #include <sys/cdefs.h> |
9bccf70c | 47 | |
b0d623f7 A |
48 | #ifdef __LP64__ |
49 | ||
50 | typedef unsigned long clock_sec_t; | |
51 | typedef unsigned int clock_usec_t, clock_nsec_t; | |
52 | ||
53 | #else /* __LP64__ */ | |
54 | ||
55 | typedef uint32_t clock_sec_t; | |
56 | typedef uint32_t clock_usec_t, clock_nsec_t; | |
57 | ||
58 | #endif /* __LP64__ */ | |
59 | ||
9bccf70c A |
60 | #ifdef MACH_KERNEL_PRIVATE |
61 | ||
c910b4d9 A |
62 | #include <kern/queue.h> |
63 | ||
1c79356b A |
64 | /* |
65 | * Clock operations list structure. Contains vectors to machine | |
0c530ab8 | 66 | * dependent clock routines. |
1c79356b A |
67 | */ |
68 | struct clock_ops { | |
69 | int (*c_config)(void); /* configuration */ | |
70 | ||
71 | int (*c_init)(void); /* initialize */ | |
72 | ||
73 | kern_return_t (*c_gettime)( /* get time */ | |
74 | mach_timespec_t *cur_time); | |
75 | ||
1c79356b A |
76 | kern_return_t (*c_getattr)( /* get attributes */ |
77 | clock_flavor_t flavor, | |
78 | clock_attr_t attr, | |
79 | mach_msg_type_number_t *count); | |
1c79356b A |
80 | }; |
81 | typedef struct clock_ops *clock_ops_t; | |
82 | typedef struct clock_ops clock_ops_data_t; | |
83 | ||
84 | /* | |
85 | * Actual clock object data structure. Contains the machine | |
0c530ab8 | 86 | * dependent operations list and clock operation ports. |
1c79356b A |
87 | */ |
88 | struct clock { | |
89 | clock_ops_t cl_ops; /* operations list */ | |
90 | struct ipc_port *cl_service; /* service port */ | |
91 | struct ipc_port *cl_control; /* control port */ | |
1c79356b A |
92 | }; |
93 | typedef struct clock clock_data_t; | |
94 | ||
95 | /* | |
96 | * Configure the clock system. | |
97 | */ | |
98 | extern void clock_config(void); | |
0c530ab8 | 99 | extern void clock_oldconfig(void); |
55e303ae | 100 | |
1c79356b A |
101 | /* |
102 | * Initialize the clock system. | |
103 | */ | |
104 | extern void clock_init(void); | |
0c530ab8 | 105 | extern void clock_oldinit(void); |
1c79356b | 106 | |
55e303ae A |
107 | extern void clock_timebase_init(void); |
108 | ||
1c79356b A |
109 | /* |
110 | * Initialize the clock ipc service facility. | |
111 | */ | |
112 | extern void clock_service_create(void); | |
113 | ||
0c530ab8 A |
114 | extern void clock_gettimeofday_set_commpage( |
115 | uint64_t abstime, | |
116 | uint64_t epoch, | |
117 | uint64_t offset, | |
b0d623f7 A |
118 | clock_sec_t *secs, |
119 | clock_usec_t *microsecs); | |
9bccf70c | 120 | |
bd504ef0 | 121 | extern void machine_delay_until(uint64_t interval, |
91447636 | 122 | uint64_t deadline); |
1c79356b | 123 | |
2d21ac55 | 124 | extern uint32_t hz_tick_interval; |
9bccf70c | 125 | |
0c530ab8 | 126 | extern void nanotime_to_absolutetime( |
b0d623f7 A |
127 | clock_sec_t secs, |
128 | clock_nsec_t nanosecs, | |
0c530ab8 A |
129 | uint64_t *result); |
130 | ||
91447636 | 131 | #endif /* MACH_KERNEL_PRIVATE */ |
55e303ae | 132 | |
91447636 A |
133 | __BEGIN_DECLS |
134 | ||
135 | #ifdef XNU_KERNEL_PRIVATE | |
55e303ae A |
136 | |
137 | extern void clock_adjtime( | |
b0d623f7 A |
138 | long *secs, |
139 | int *microsecs); | |
9bccf70c A |
140 | |
141 | extern void clock_initialize_calendar(void); | |
142 | ||
55e303ae A |
143 | extern void clock_wakeup_calendar(void); |
144 | ||
145 | extern void clock_gettimeofday( | |
b0d623f7 A |
146 | clock_sec_t *secs, |
147 | clock_usec_t *microsecs); | |
55e303ae | 148 | |
39037602 A |
149 | extern void clock_gettimeofday_and_absolute_time( |
150 | clock_sec_t *secs, | |
151 | clock_usec_t *microsecs, | |
152 | uint64_t *absolute_time); | |
153 | ||
154 | ||
91447636 | 155 | extern void clock_set_calendar_microtime( |
b0d623f7 A |
156 | clock_sec_t secs, |
157 | clock_usec_t microsecs); | |
9bccf70c | 158 | |
91447636 | 159 | extern void clock_get_boottime_nanotime( |
b0d623f7 A |
160 | clock_sec_t *secs, |
161 | clock_nsec_t *nanosecs); | |
9bccf70c | 162 | |
39037602 A |
163 | extern void clock_get_boottime_microtime( |
164 | clock_sec_t *secs, | |
165 | clock_nsec_t *microsecs); | |
166 | ||
2d21ac55 | 167 | extern void absolutetime_to_microtime( |
b0d623f7 A |
168 | uint64_t abstime, |
169 | clock_sec_t *secs, | |
170 | clock_usec_t *microsecs); | |
2d21ac55 | 171 | |
91447636 A |
172 | extern void clock_deadline_for_periodic_event( |
173 | uint64_t interval, | |
174 | uint64_t abstime, | |
175 | uint64_t *deadline); | |
1c79356b | 176 | |
b0d623f7 A |
177 | #if CONFIG_DTRACE |
178 | ||
179 | extern void clock_get_calendar_nanotime_nowait( | |
180 | clock_sec_t *secs, | |
181 | clock_nsec_t *nanosecs); | |
182 | ||
183 | #endif /* CONFIG_DTRACE */ | |
184 | ||
39037602 A |
185 | boolean_t kdp_clock_is_locked(void); |
186 | ||
91447636 | 187 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 188 | |
91447636 | 189 | extern void clock_get_calendar_microtime( |
b0d623f7 A |
190 | clock_sec_t *secs, |
191 | clock_usec_t *microsecs); | |
9bccf70c | 192 | |
39236c6e A |
193 | extern void clock_get_calendar_absolute_and_microtime( |
194 | clock_sec_t *secs, | |
195 | clock_usec_t *microsecs, | |
196 | uint64_t *abstime); | |
197 | ||
91447636 | 198 | extern void clock_get_calendar_nanotime( |
b0d623f7 A |
199 | clock_sec_t *secs, |
200 | clock_nsec_t *nanosecs); | |
2d21ac55 | 201 | |
91447636 | 202 | extern void clock_get_system_microtime( |
b0d623f7 A |
203 | clock_sec_t *secs, |
204 | clock_usec_t *microsecs); | |
91447636 A |
205 | |
206 | extern void clock_get_system_nanotime( | |
b0d623f7 A |
207 | clock_sec_t *secs, |
208 | clock_nsec_t *nanosecs); | |
1c79356b | 209 | |
0b4e3aa0 A |
210 | extern void clock_timebase_info( |
211 | mach_timebase_info_t info); | |
212 | ||
213 | extern void clock_get_uptime( | |
214 | uint64_t *result); | |
215 | ||
216 | extern void clock_interval_to_deadline( | |
217 | uint32_t interval, | |
218 | uint32_t scale_factor, | |
219 | uint64_t *result); | |
220 | ||
221 | extern void clock_interval_to_absolutetime_interval( | |
222 | uint32_t interval, | |
223 | uint32_t scale_factor, | |
224 | uint64_t *result); | |
225 | ||
226 | extern void clock_absolutetime_interval_to_deadline( | |
227 | uint64_t abstime, | |
228 | uint64_t *result); | |
229 | ||
39037602 A |
230 | extern void clock_continuoustime_interval_to_deadline( |
231 | uint64_t abstime, | |
232 | uint64_t *result); | |
233 | ||
0b4e3aa0 A |
234 | extern void clock_delay_until( |
235 | uint64_t deadline); | |
236 | ||
237 | extern void absolutetime_to_nanoseconds( | |
238 | uint64_t abstime, | |
239 | uint64_t *result); | |
240 | ||
39037602 | 241 | extern void nanoseconds_to_absolutetime( |
0b4e3aa0 A |
242 | uint64_t nanoseconds, |
243 | uint64_t *result); | |
244 | ||
39037602 A |
245 | /* |
246 | * Absolute <-> Continuous Time conversion routines | |
247 | * | |
248 | * It is the caller's responsibility to ensure that these functions are | |
249 | * synchronized with respect to updates to the continuous timebase. The | |
250 | * returned value is only valid until the next update to the continuous | |
251 | * timebase. | |
252 | * | |
253 | * If the value to be returned by continuoustime_to_absolutetime would be | |
254 | * negative, zero is returned. This occurs when the provided continuous time | |
255 | * is less the amount of the time the system spent asleep and /must/ be | |
256 | * handled. | |
257 | */ | |
258 | extern uint64_t absolutetime_to_continuoustime( | |
259 | uint64_t abstime); | |
260 | extern uint64_t continuoustime_to_absolutetime( | |
261 | uint64_t conttime); | |
262 | ||
3e170ce0 A |
263 | extern uint64_t mach_absolutetime_asleep; |
264 | extern uint64_t mach_absolutetime_last_sleep; | |
265 | ||
91447636 | 266 | #ifdef KERNEL_PRIVATE |
0b4e3aa0 | 267 | |
91447636 A |
268 | /* |
269 | * Obsolete interfaces. | |
270 | */ | |
271 | ||
b0d623f7 A |
272 | #ifndef __LP64__ |
273 | ||
91447636 A |
274 | #define MACH_TIMESPEC_SEC_MAX (0 - 1) |
275 | #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1) | |
276 | ||
277 | #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \ | |
278 | MACH_TIMESPEC_SEC_MAX, \ | |
279 | MACH_TIMESPEC_NSEC_MAX } ) | |
280 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
281 | ||
282 | #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \ | |
283 | do { \ | |
284 | (t1)->tv_nsec += (clock_res_t)(nsec); \ | |
285 | if ((clock_res_t)(nsec) > 0 && \ | |
286 | (t1)->tv_nsec >= NSEC_PER_SEC) { \ | |
287 | (t1)->tv_nsec -= NSEC_PER_SEC; \ | |
288 | (t1)->tv_sec += 1; \ | |
289 | } \ | |
290 | else if ((clock_res_t)(nsec) < 0 && \ | |
291 | (t1)->tv_nsec < 0) { \ | |
292 | (t1)->tv_nsec += NSEC_PER_SEC; \ | |
293 | (t1)->tv_sec -= 1; \ | |
294 | } \ | |
295 | } while (0) | |
296 | ||
316670eb | 297 | #include <Availability.h> |
91447636 | 298 | |
316670eb | 299 | /* Use mach_absolute_time() */ |
39236c6e | 300 | extern mach_timespec_t clock_get_system_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0); |
91447636 | 301 | |
39236c6e | 302 | extern mach_timespec_t clock_get_calendar_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0); |
91447636 | 303 | |
b0d623f7 A |
304 | #else /* __LP64__ */ |
305 | ||
306 | #ifdef XNU_KERNEL_PRIVATE | |
307 | ||
308 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
309 | ||
310 | #endif /* XNU_KERNEL_PRIVATE */ | |
311 | ||
312 | #endif /* __LP64__ */ | |
313 | ||
91447636 A |
314 | extern void delay_for_interval( |
315 | uint32_t interval, | |
316 | uint32_t scale_factor); | |
b0d623f7 | 317 | |
3e170ce0 A |
318 | extern void delay_for_interval_with_leeway( |
319 | uint32_t interval, | |
320 | uint32_t leeway, | |
321 | uint32_t scale_factor); | |
322 | ||
39037602 A |
323 | #ifdef XNU_KERNEL_PRIVATE |
324 | extern void delay(int usec); | |
325 | #endif /* XNU_KERNEL_PRIVATE */ | |
326 | ||
91447636 | 327 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 328 | |
91447636 | 329 | __END_DECLS |
1c79356b A |
330 | |
331 | #endif /* _KERN_CLOCK_H_ */ |