]>
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 A |
41 | #include <mach/mach_time.h> |
42 | ||
91447636 | 43 | #include <kern/kern_types.h> |
9bccf70c | 44 | |
91447636 | 45 | #include <sys/cdefs.h> |
9bccf70c | 46 | |
b0d623f7 A |
47 | #ifdef __LP64__ |
48 | ||
49 | typedef unsigned long clock_sec_t; | |
50 | typedef unsigned int clock_usec_t, clock_nsec_t; | |
51 | ||
52 | #else /* __LP64__ */ | |
53 | ||
54 | typedef uint32_t clock_sec_t; | |
55 | typedef uint32_t clock_usec_t, clock_nsec_t; | |
56 | ||
57 | #endif /* __LP64__ */ | |
58 | ||
9bccf70c A |
59 | #ifdef MACH_KERNEL_PRIVATE |
60 | ||
c910b4d9 A |
61 | #include <kern/queue.h> |
62 | ||
1c79356b A |
63 | /* |
64 | * Clock operations list structure. Contains vectors to machine | |
0c530ab8 | 65 | * dependent clock routines. |
1c79356b A |
66 | */ |
67 | struct clock_ops { | |
68 | int (*c_config)(void); /* configuration */ | |
69 | ||
70 | int (*c_init)(void); /* initialize */ | |
71 | ||
72 | kern_return_t (*c_gettime)( /* get time */ | |
73 | mach_timespec_t *cur_time); | |
74 | ||
1c79356b A |
75 | kern_return_t (*c_getattr)( /* get attributes */ |
76 | clock_flavor_t flavor, | |
77 | clock_attr_t attr, | |
78 | mach_msg_type_number_t *count); | |
1c79356b A |
79 | }; |
80 | typedef struct clock_ops *clock_ops_t; | |
81 | typedef struct clock_ops clock_ops_data_t; | |
82 | ||
83 | /* | |
84 | * Actual clock object data structure. Contains the machine | |
0c530ab8 | 85 | * dependent operations list and clock operation ports. |
1c79356b A |
86 | */ |
87 | struct clock { | |
88 | clock_ops_t cl_ops; /* operations list */ | |
89 | struct ipc_port *cl_service; /* service port */ | |
90 | struct ipc_port *cl_control; /* control port */ | |
1c79356b A |
91 | }; |
92 | typedef struct clock clock_data_t; | |
93 | ||
94 | /* | |
95 | * Configure the clock system. | |
96 | */ | |
97 | extern void clock_config(void); | |
0c530ab8 | 98 | extern void clock_oldconfig(void); |
55e303ae | 99 | |
1c79356b A |
100 | /* |
101 | * Initialize the clock system. | |
102 | */ | |
103 | extern void clock_init(void); | |
0c530ab8 | 104 | extern void clock_oldinit(void); |
1c79356b | 105 | |
55e303ae A |
106 | extern void clock_timebase_init(void); |
107 | ||
1c79356b A |
108 | /* |
109 | * Initialize the clock ipc service facility. | |
110 | */ | |
111 | extern void clock_service_create(void); | |
112 | ||
0c530ab8 A |
113 | extern void clock_gettimeofday_set_commpage( |
114 | uint64_t abstime, | |
115 | uint64_t epoch, | |
116 | uint64_t offset, | |
b0d623f7 A |
117 | clock_sec_t *secs, |
118 | clock_usec_t *microsecs); | |
9bccf70c | 119 | |
bd504ef0 | 120 | extern void machine_delay_until(uint64_t interval, |
91447636 | 121 | uint64_t deadline); |
1c79356b | 122 | |
2d21ac55 | 123 | extern uint32_t hz_tick_interval; |
9bccf70c | 124 | |
0c530ab8 | 125 | extern void nanotime_to_absolutetime( |
b0d623f7 A |
126 | clock_sec_t secs, |
127 | clock_nsec_t nanosecs, | |
0c530ab8 A |
128 | uint64_t *result); |
129 | ||
91447636 | 130 | #endif /* MACH_KERNEL_PRIVATE */ |
55e303ae | 131 | |
91447636 A |
132 | __BEGIN_DECLS |
133 | ||
134 | #ifdef XNU_KERNEL_PRIVATE | |
55e303ae A |
135 | |
136 | extern void clock_adjtime( | |
b0d623f7 A |
137 | long *secs, |
138 | int *microsecs); | |
9bccf70c A |
139 | |
140 | extern void clock_initialize_calendar(void); | |
141 | ||
55e303ae A |
142 | extern void clock_wakeup_calendar(void); |
143 | ||
144 | extern void clock_gettimeofday( | |
b0d623f7 A |
145 | clock_sec_t *secs, |
146 | clock_usec_t *microsecs); | |
55e303ae | 147 | |
91447636 | 148 | extern void clock_set_calendar_microtime( |
b0d623f7 A |
149 | clock_sec_t secs, |
150 | clock_usec_t microsecs); | |
9bccf70c | 151 | |
91447636 | 152 | extern void clock_get_boottime_nanotime( |
b0d623f7 A |
153 | clock_sec_t *secs, |
154 | clock_nsec_t *nanosecs); | |
9bccf70c | 155 | |
2d21ac55 | 156 | extern void absolutetime_to_microtime( |
b0d623f7 A |
157 | uint64_t abstime, |
158 | clock_sec_t *secs, | |
159 | clock_usec_t *microsecs); | |
2d21ac55 | 160 | |
91447636 A |
161 | extern void clock_deadline_for_periodic_event( |
162 | uint64_t interval, | |
163 | uint64_t abstime, | |
164 | uint64_t *deadline); | |
1c79356b | 165 | |
b0d623f7 A |
166 | #if CONFIG_DTRACE |
167 | ||
168 | extern void clock_get_calendar_nanotime_nowait( | |
169 | clock_sec_t *secs, | |
170 | clock_nsec_t *nanosecs); | |
171 | ||
172 | #endif /* CONFIG_DTRACE */ | |
173 | ||
91447636 | 174 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 175 | |
91447636 | 176 | extern void clock_get_calendar_microtime( |
b0d623f7 A |
177 | clock_sec_t *secs, |
178 | clock_usec_t *microsecs); | |
9bccf70c | 179 | |
39236c6e A |
180 | extern void clock_get_calendar_absolute_and_microtime( |
181 | clock_sec_t *secs, | |
182 | clock_usec_t *microsecs, | |
183 | uint64_t *abstime); | |
184 | ||
91447636 | 185 | extern void clock_get_calendar_nanotime( |
b0d623f7 A |
186 | clock_sec_t *secs, |
187 | clock_nsec_t *nanosecs); | |
2d21ac55 | 188 | |
91447636 | 189 | extern void clock_get_system_microtime( |
b0d623f7 A |
190 | clock_sec_t *secs, |
191 | clock_usec_t *microsecs); | |
91447636 A |
192 | |
193 | extern void clock_get_system_nanotime( | |
b0d623f7 A |
194 | clock_sec_t *secs, |
195 | clock_nsec_t *nanosecs); | |
1c79356b | 196 | |
0b4e3aa0 A |
197 | extern void clock_timebase_info( |
198 | mach_timebase_info_t info); | |
199 | ||
200 | extern void clock_get_uptime( | |
201 | uint64_t *result); | |
202 | ||
203 | extern void clock_interval_to_deadline( | |
204 | uint32_t interval, | |
205 | uint32_t scale_factor, | |
206 | uint64_t *result); | |
207 | ||
208 | extern void clock_interval_to_absolutetime_interval( | |
209 | uint32_t interval, | |
210 | uint32_t scale_factor, | |
211 | uint64_t *result); | |
212 | ||
213 | extern void clock_absolutetime_interval_to_deadline( | |
214 | uint64_t abstime, | |
215 | uint64_t *result); | |
216 | ||
0b4e3aa0 A |
217 | extern void clock_delay_until( |
218 | uint64_t deadline); | |
219 | ||
220 | extern void absolutetime_to_nanoseconds( | |
221 | uint64_t abstime, | |
222 | uint64_t *result); | |
223 | ||
224 | extern void nanoseconds_to_absolutetime( | |
225 | uint64_t nanoseconds, | |
226 | uint64_t *result); | |
227 | ||
3e170ce0 A |
228 | extern uint64_t mach_absolutetime_asleep; |
229 | extern uint64_t mach_absolutetime_last_sleep; | |
230 | ||
91447636 | 231 | #ifdef KERNEL_PRIVATE |
0b4e3aa0 | 232 | |
91447636 A |
233 | /* |
234 | * Obsolete interfaces. | |
235 | */ | |
236 | ||
b0d623f7 A |
237 | #ifndef __LP64__ |
238 | ||
91447636 A |
239 | #define MACH_TIMESPEC_SEC_MAX (0 - 1) |
240 | #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1) | |
241 | ||
242 | #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \ | |
243 | MACH_TIMESPEC_SEC_MAX, \ | |
244 | MACH_TIMESPEC_NSEC_MAX } ) | |
245 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
246 | ||
247 | #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \ | |
248 | do { \ | |
249 | (t1)->tv_nsec += (clock_res_t)(nsec); \ | |
250 | if ((clock_res_t)(nsec) > 0 && \ | |
251 | (t1)->tv_nsec >= NSEC_PER_SEC) { \ | |
252 | (t1)->tv_nsec -= NSEC_PER_SEC; \ | |
253 | (t1)->tv_sec += 1; \ | |
254 | } \ | |
255 | else if ((clock_res_t)(nsec) < 0 && \ | |
256 | (t1)->tv_nsec < 0) { \ | |
257 | (t1)->tv_nsec += NSEC_PER_SEC; \ | |
258 | (t1)->tv_sec -= 1; \ | |
259 | } \ | |
260 | } while (0) | |
261 | ||
316670eb | 262 | #include <Availability.h> |
91447636 | 263 | |
316670eb | 264 | /* Use mach_absolute_time() */ |
39236c6e | 265 | 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 | 266 | |
39236c6e | 267 | 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 | 268 | |
b0d623f7 A |
269 | #else /* __LP64__ */ |
270 | ||
271 | #ifdef XNU_KERNEL_PRIVATE | |
272 | ||
273 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
274 | ||
275 | #endif /* XNU_KERNEL_PRIVATE */ | |
276 | ||
277 | #endif /* __LP64__ */ | |
278 | ||
91447636 A |
279 | extern void delay_for_interval( |
280 | uint32_t interval, | |
281 | uint32_t scale_factor); | |
b0d623f7 | 282 | |
3e170ce0 A |
283 | extern void delay_for_interval_with_leeway( |
284 | uint32_t interval, | |
285 | uint32_t leeway, | |
286 | uint32_t scale_factor); | |
287 | ||
91447636 | 288 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 289 | |
91447636 | 290 | __END_DECLS |
1c79356b A |
291 | |
292 | #endif /* _KERN_CLOCK_H_ */ |