]>
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@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
1c79356b A |
32 | */ |
33 | ||
0a7de745 A |
34 | #ifndef _KERN_CLOCK_H_ |
35 | #define _KERN_CLOCK_H_ | |
1c79356b | 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 | |
5ba3f43e | 48 | |
0a7de745 | 49 | #ifdef __LP64__ |
b0d623f7 | 50 | |
0a7de745 A |
51 | typedef unsigned long clock_sec_t; |
52 | typedef unsigned int clock_usec_t, clock_nsec_t; | |
b0d623f7 | 53 | |
0a7de745 | 54 | #else /* __LP64__ */ |
b0d623f7 | 55 | |
0a7de745 A |
56 | typedef uint32_t clock_sec_t; |
57 | typedef uint32_t clock_usec_t, clock_nsec_t; | |
b0d623f7 | 58 | |
0a7de745 | 59 | #endif /* __LP64__ */ |
b0d623f7 | 60 | |
0a7de745 | 61 | #ifdef MACH_KERNEL_PRIVATE |
9bccf70c | 62 | |
c910b4d9 A |
63 | #include <kern/queue.h> |
64 | ||
1c79356b A |
65 | /* |
66 | * Clock operations list structure. Contains vectors to machine | |
0c530ab8 | 67 | * dependent clock routines. |
1c79356b | 68 | */ |
0a7de745 A |
69 | struct clock_ops { |
70 | int (*c_config)(void); /* configuration */ | |
1c79356b | 71 | |
0a7de745 | 72 | int (*c_init)(void); /* initialize */ |
1c79356b | 73 | |
0a7de745 A |
74 | kern_return_t (*c_gettime)( /* get time */ |
75 | mach_timespec_t *cur_time); | |
1c79356b | 76 | |
0a7de745 A |
77 | kern_return_t (*c_getattr)( /* get attributes */ |
78 | clock_flavor_t flavor, | |
79 | clock_attr_t attr, | |
80 | mach_msg_type_number_t *count); | |
1c79356b | 81 | }; |
0a7de745 A |
82 | typedef const struct clock_ops *clock_ops_t; |
83 | typedef struct clock_ops clock_ops_data_t; | |
1c79356b A |
84 | |
85 | /* | |
86 | * Actual clock object data structure. Contains the machine | |
0c530ab8 | 87 | * dependent operations list and clock operation ports. |
1c79356b | 88 | */ |
0a7de745 A |
89 | struct clock { |
90 | clock_ops_t cl_ops; /* operations list */ | |
91 | struct ipc_port *cl_service; /* service port */ | |
92 | struct ipc_port *cl_control; /* control port */ | |
1c79356b | 93 | }; |
0a7de745 | 94 | typedef struct clock clock_data_t; |
1c79356b A |
95 | |
96 | /* | |
97 | * Configure the clock system. | |
98 | */ | |
0a7de745 A |
99 | extern void clock_config(void); |
100 | extern void clock_oldconfig(void); | |
55e303ae | 101 | |
1c79356b A |
102 | /* |
103 | * Initialize the clock system. | |
104 | */ | |
0a7de745 A |
105 | extern void clock_init(void); |
106 | extern void clock_oldinit(void); | |
1c79356b | 107 | |
0a7de745 | 108 | extern void clock_timebase_init(void); |
55e303ae | 109 | |
1c79356b A |
110 | /* |
111 | * Initialize the clock ipc service facility. | |
112 | */ | |
0a7de745 | 113 | extern void clock_service_create(void); |
1c79356b | 114 | |
5ba3f43e | 115 | extern void clock_gettimeofday_set_commpage( |
0a7de745 A |
116 | uint64_t abstime, |
117 | uint64_t sec, | |
118 | uint64_t frac, | |
119 | uint64_t scale, | |
120 | uint64_t tick_per_sec); | |
9bccf70c | 121 | |
0a7de745 A |
122 | extern void machine_delay_until(uint64_t interval, |
123 | uint64_t deadline); | |
1c79356b | 124 | |
0a7de745 | 125 | extern uint32_t hz_tick_interval; |
9bccf70c | 126 | |
0a7de745 A |
127 | extern void nanotime_to_absolutetime( |
128 | clock_sec_t secs, | |
129 | clock_nsec_t nanosecs, | |
130 | uint64_t *result); | |
0c530ab8 | 131 | |
91447636 | 132 | #endif /* MACH_KERNEL_PRIVATE */ |
55e303ae | 133 | |
91447636 A |
134 | __BEGIN_DECLS |
135 | ||
0a7de745 | 136 | #ifdef XNU_KERNEL_PRIVATE |
55e303ae | 137 | |
0a7de745 A |
138 | extern void clock_adjtime( |
139 | long *secs, | |
140 | int *microsecs); | |
9bccf70c | 141 | |
0a7de745 | 142 | extern void clock_initialize_calendar(void); |
9bccf70c | 143 | |
0a7de745 | 144 | extern void clock_wakeup_calendar(void); |
55e303ae | 145 | |
0a7de745 | 146 | extern void clock_update_calendar(void); |
5ba3f43e | 147 | |
0a7de745 | 148 | extern void clock_get_calendar_uptime(clock_sec_t *secs); |
5ba3f43e | 149 | |
0a7de745 A |
150 | extern void clock_gettimeofday_new(clock_sec_t *secs, |
151 | clock_usec_t *microsecs); | |
152 | extern void clock_gettimeofday( | |
153 | clock_sec_t *secs, | |
154 | clock_usec_t *microsecs); | |
55e303ae | 155 | |
0a7de745 A |
156 | extern void clock_gettimeofday_and_absolute_time( |
157 | clock_sec_t *secs, | |
158 | clock_usec_t *microsecs, | |
159 | uint64_t *absolute_time); | |
39037602 A |
160 | |
161 | ||
0a7de745 A |
162 | extern void clock_set_calendar_microtime( |
163 | clock_sec_t secs, | |
164 | clock_usec_t microsecs); | |
9bccf70c | 165 | |
0a7de745 A |
166 | extern void clock_get_boottime_nanotime( |
167 | clock_sec_t *secs, | |
168 | clock_nsec_t *nanosecs); | |
9bccf70c | 169 | |
0a7de745 A |
170 | extern void clock_get_boottime_microtime( |
171 | clock_sec_t *secs, | |
172 | clock_nsec_t *microsecs); | |
39037602 | 173 | |
0a7de745 A |
174 | extern void absolutetime_to_microtime( |
175 | uint64_t abstime, | |
176 | clock_sec_t *secs, | |
177 | clock_usec_t *microsecs); | |
2d21ac55 | 178 | |
0a7de745 A |
179 | extern void clock_deadline_for_periodic_event( |
180 | uint64_t interval, | |
181 | uint64_t abstime, | |
182 | uint64_t *deadline); | |
1c79356b | 183 | |
0a7de745 | 184 | #if CONFIG_DTRACE |
b0d623f7 | 185 | |
0a7de745 A |
186 | extern void clock_get_calendar_nanotime_nowait( |
187 | clock_sec_t *secs, | |
188 | clock_nsec_t *nanosecs); | |
b0d623f7 | 189 | |
0a7de745 | 190 | #endif /* CONFIG_DTRACE */ |
b0d623f7 | 191 | |
39037602 A |
192 | boolean_t kdp_clock_is_locked(void); |
193 | ||
0a7de745 | 194 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 195 | |
0a7de745 A |
196 | extern void clock_get_calendar_microtime( |
197 | clock_sec_t *secs, | |
198 | clock_usec_t *microsecs); | |
9bccf70c | 199 | |
0a7de745 A |
200 | extern void clock_get_calendar_absolute_and_microtime( |
201 | clock_sec_t *secs, | |
202 | clock_usec_t *microsecs, | |
203 | uint64_t *abstime); | |
39236c6e | 204 | |
0a7de745 A |
205 | extern void clock_get_calendar_nanotime( |
206 | clock_sec_t *secs, | |
207 | clock_nsec_t *nanosecs); | |
2d21ac55 | 208 | |
0a7de745 A |
209 | extern void clock_get_system_microtime( |
210 | clock_sec_t *secs, | |
211 | clock_usec_t *microsecs); | |
91447636 | 212 | |
0a7de745 A |
213 | extern void clock_get_system_nanotime( |
214 | clock_sec_t *secs, | |
215 | clock_nsec_t *nanosecs); | |
1c79356b | 216 | |
0a7de745 A |
217 | extern void clock_timebase_info( |
218 | mach_timebase_info_t info); | |
0b4e3aa0 | 219 | |
0a7de745 A |
220 | extern void clock_get_uptime( |
221 | uint64_t *result); | |
0b4e3aa0 | 222 | |
0a7de745 A |
223 | extern void clock_interval_to_deadline( |
224 | uint32_t interval, | |
225 | uint32_t scale_factor, | |
226 | uint64_t *result); | |
0b4e3aa0 | 227 | |
f427ee49 A |
228 | extern void nanoseconds_to_deadline( |
229 | uint64_t interval, | |
230 | uint64_t *result); | |
231 | ||
0a7de745 A |
232 | extern void clock_interval_to_absolutetime_interval( |
233 | uint32_t interval, | |
234 | uint32_t scale_factor, | |
235 | uint64_t *result); | |
0b4e3aa0 | 236 | |
0a7de745 A |
237 | extern void clock_absolutetime_interval_to_deadline( |
238 | uint64_t abstime, | |
239 | uint64_t *result); | |
0b4e3aa0 | 240 | |
0a7de745 A |
241 | extern void clock_continuoustime_interval_to_deadline( |
242 | uint64_t abstime, | |
243 | uint64_t *result); | |
39037602 | 244 | |
0a7de745 A |
245 | extern void clock_delay_until( |
246 | uint64_t deadline); | |
0b4e3aa0 | 247 | |
0a7de745 A |
248 | extern void absolutetime_to_nanoseconds( |
249 | uint64_t abstime, | |
250 | uint64_t *result); | |
0b4e3aa0 | 251 | |
0a7de745 A |
252 | extern void nanoseconds_to_absolutetime( |
253 | uint64_t nanoseconds, | |
254 | uint64_t *result); | |
0b4e3aa0 | 255 | |
39037602 A |
256 | /* |
257 | * Absolute <-> Continuous Time conversion routines | |
258 | * | |
259 | * It is the caller's responsibility to ensure that these functions are | |
260 | * synchronized with respect to updates to the continuous timebase. The | |
261 | * returned value is only valid until the next update to the continuous | |
262 | * timebase. | |
263 | * | |
264 | * If the value to be returned by continuoustime_to_absolutetime would be | |
265 | * negative, zero is returned. This occurs when the provided continuous time | |
266 | * is less the amount of the time the system spent asleep and /must/ be | |
267 | * handled. | |
268 | */ | |
0a7de745 A |
269 | extern uint64_t absolutetime_to_continuoustime( |
270 | uint64_t abstime); | |
271 | extern uint64_t continuoustime_to_absolutetime( | |
272 | uint64_t conttime); | |
39037602 | 273 | |
3e170ce0 A |
274 | extern uint64_t mach_absolutetime_asleep; |
275 | extern uint64_t mach_absolutetime_last_sleep; | |
f427ee49 A |
276 | #if HIBERNATION && HAS_CONTINUOUS_HWCLOCK |
277 | extern uint64_t hwclock_conttime_offset; | |
278 | #endif | |
3e170ce0 | 279 | |
0a7de745 | 280 | #ifdef KERNEL_PRIVATE |
0b4e3aa0 | 281 | |
91447636 A |
282 | /* |
283 | * Obsolete interfaces. | |
284 | */ | |
285 | ||
0a7de745 A |
286 | #ifndef __LP64__ |
287 | ||
288 | #define MACH_TIMESPEC_SEC_MAX (0 - 1) | |
289 | #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1) | |
290 | ||
291 | #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \ | |
292 | MACH_TIMESPEC_SEC_MAX, \ | |
293 | MACH_TIMESPEC_NSEC_MAX } ) | |
294 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
295 | ||
296 | #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \ | |
297 | do { \ | |
298 | (t1)->tv_nsec += (clock_res_t)(nsec); \ | |
299 | if ((clock_res_t)(nsec) > 0 && \ | |
300 | (t1)->tv_nsec >= NSEC_PER_SEC) { \ | |
301 | (t1)->tv_nsec -= NSEC_PER_SEC; \ | |
302 | (t1)->tv_sec += 1; \ | |
303 | } \ | |
304 | else if ((clock_res_t)(nsec) < 0 && \ | |
305 | (t1)->tv_nsec < 0) { \ | |
306 | (t1)->tv_nsec += NSEC_PER_SEC; \ | |
307 | (t1)->tv_sec -= 1; \ | |
308 | } \ | |
91447636 A |
309 | } while (0) |
310 | ||
316670eb | 311 | #include <Availability.h> |
91447636 | 312 | |
316670eb | 313 | /* Use mach_absolute_time() */ |
0a7de745 | 314 | 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 | 315 | |
0a7de745 | 316 | 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 | 317 | |
0a7de745 | 318 | #else /* __LP64__ */ |
b0d623f7 | 319 | |
0a7de745 | 320 | #ifdef XNU_KERNEL_PRIVATE |
b0d623f7 | 321 | |
0a7de745 | 322 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) |
b0d623f7 | 323 | |
0a7de745 | 324 | #endif /* XNU_KERNEL_PRIVATE */ |
b0d623f7 | 325 | |
0a7de745 | 326 | #endif /* __LP64__ */ |
b0d623f7 | 327 | |
0a7de745 A |
328 | extern void delay_for_interval( |
329 | uint32_t interval, | |
330 | uint32_t scale_factor); | |
b0d623f7 | 331 | |
0a7de745 A |
332 | extern void delay_for_interval_with_leeway( |
333 | uint32_t interval, | |
334 | uint32_t leeway, | |
335 | uint32_t scale_factor); | |
3e170ce0 | 336 | |
0a7de745 | 337 | #ifdef XNU_KERNEL_PRIVATE |
39037602 | 338 | extern void delay(int usec); |
0a7de745 | 339 | #endif /* XNU_KERNEL_PRIVATE */ |
39037602 | 340 | |
0a7de745 | 341 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 342 | |
91447636 | 343 | __END_DECLS |
1c79356b | 344 | |
0a7de745 | 345 | #endif /* _KERN_CLOCK_H_ */ |