]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2008 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
14 | * | |
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 | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | */ | |
33 | ||
34 | #ifndef _KERN_CLOCK_H_ | |
35 | #define _KERN_CLOCK_H_ | |
36 | ||
37 | #include <stdint.h> | |
38 | #include <mach/mach_types.h> | |
39 | #include <mach/clock_types.h> | |
40 | #include <mach/message.h> | |
41 | #include <mach/mach_time.h> | |
42 | ||
43 | #include <kern/kern_types.h> | |
44 | ||
45 | #include <sys/cdefs.h> | |
46 | ||
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 | ||
59 | #ifdef MACH_KERNEL_PRIVATE | |
60 | ||
61 | #include <kern/queue.h> | |
62 | ||
63 | /* | |
64 | * Clock operations list structure. Contains vectors to machine | |
65 | * dependent clock routines. | |
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 | ||
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); | |
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 | |
85 | * dependent operations list and clock operation ports. | |
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 */ | |
91 | }; | |
92 | typedef struct clock clock_data_t; | |
93 | ||
94 | /* | |
95 | * Configure the clock system. | |
96 | */ | |
97 | extern void clock_config(void); | |
98 | extern void clock_oldconfig(void); | |
99 | ||
100 | /* | |
101 | * Initialize the clock system. | |
102 | */ | |
103 | extern void clock_init(void); | |
104 | extern void clock_oldinit(void); | |
105 | ||
106 | extern void clock_timebase_init(void); | |
107 | ||
108 | /* | |
109 | * Initialize the clock ipc service facility. | |
110 | */ | |
111 | extern void clock_service_create(void); | |
112 | ||
113 | extern void clock_gettimeofday_set_commpage( | |
114 | uint64_t abstime, | |
115 | uint64_t epoch, | |
116 | uint64_t offset, | |
117 | clock_sec_t *secs, | |
118 | clock_usec_t *microsecs); | |
119 | ||
120 | extern void machine_delay_until( | |
121 | uint64_t deadline); | |
122 | ||
123 | #include <stat_time.h> | |
124 | ||
125 | #if STAT_TIME || GPROF | |
126 | ||
127 | extern void hertz_tick( | |
128 | natural_t ticks, | |
129 | boolean_t usermode, /* executing user code */ | |
130 | natural_t pc); | |
131 | ||
132 | #endif /* STAT_TIME */ | |
133 | ||
134 | extern uint32_t hz_tick_interval; | |
135 | ||
136 | extern void absolutetime_to_nanotime( | |
137 | uint64_t abstime, | |
138 | clock_sec_t *secs, | |
139 | clock_nsec_t *nanosecs); | |
140 | ||
141 | extern void nanotime_to_absolutetime( | |
142 | clock_sec_t secs, | |
143 | clock_nsec_t nanosecs, | |
144 | uint64_t *result); | |
145 | ||
146 | #endif /* MACH_KERNEL_PRIVATE */ | |
147 | ||
148 | __BEGIN_DECLS | |
149 | ||
150 | #ifdef XNU_KERNEL_PRIVATE | |
151 | ||
152 | extern void clock_adjtime( | |
153 | long *secs, | |
154 | int *microsecs); | |
155 | ||
156 | extern void clock_initialize_calendar(void); | |
157 | ||
158 | extern void clock_wakeup_calendar(void); | |
159 | ||
160 | extern void clock_gettimeofday( | |
161 | clock_sec_t *secs, | |
162 | clock_usec_t *microsecs); | |
163 | ||
164 | extern void clock_set_calendar_microtime( | |
165 | clock_sec_t secs, | |
166 | clock_usec_t microsecs); | |
167 | ||
168 | extern void clock_get_boottime_nanotime( | |
169 | clock_sec_t *secs, | |
170 | clock_nsec_t *nanosecs); | |
171 | ||
172 | extern void absolutetime_to_microtime( | |
173 | uint64_t abstime, | |
174 | clock_sec_t *secs, | |
175 | clock_usec_t *microsecs); | |
176 | ||
177 | extern void clock_deadline_for_periodic_event( | |
178 | uint64_t interval, | |
179 | uint64_t abstime, | |
180 | uint64_t *deadline); | |
181 | ||
182 | #if CONFIG_DTRACE | |
183 | ||
184 | extern void clock_get_calendar_nanotime_nowait( | |
185 | clock_sec_t *secs, | |
186 | clock_nsec_t *nanosecs); | |
187 | ||
188 | #endif /* CONFIG_DTRACE */ | |
189 | ||
190 | #endif /* XNU_KERNEL_PRIVATE */ | |
191 | ||
192 | extern void clock_get_calendar_microtime( | |
193 | clock_sec_t *secs, | |
194 | clock_usec_t *microsecs); | |
195 | ||
196 | extern void clock_get_calendar_nanotime( | |
197 | clock_sec_t *secs, | |
198 | clock_nsec_t *nanosecs); | |
199 | ||
200 | extern void clock_get_system_microtime( | |
201 | clock_sec_t *secs, | |
202 | clock_usec_t *microsecs); | |
203 | ||
204 | extern void clock_get_system_nanotime( | |
205 | clock_sec_t *secs, | |
206 | clock_nsec_t *nanosecs); | |
207 | ||
208 | extern void clock_timebase_info( | |
209 | mach_timebase_info_t info); | |
210 | ||
211 | extern void clock_get_uptime( | |
212 | uint64_t *result); | |
213 | ||
214 | extern void clock_interval_to_deadline( | |
215 | uint32_t interval, | |
216 | uint32_t scale_factor, | |
217 | uint64_t *result); | |
218 | ||
219 | extern void clock_interval_to_absolutetime_interval( | |
220 | uint32_t interval, | |
221 | uint32_t scale_factor, | |
222 | uint64_t *result); | |
223 | ||
224 | extern void clock_absolutetime_interval_to_deadline( | |
225 | uint64_t abstime, | |
226 | uint64_t *result); | |
227 | ||
228 | extern void clock_delay_until( | |
229 | uint64_t deadline); | |
230 | ||
231 | extern void absolutetime_to_nanoseconds( | |
232 | uint64_t abstime, | |
233 | uint64_t *result); | |
234 | ||
235 | extern void nanoseconds_to_absolutetime( | |
236 | uint64_t nanoseconds, | |
237 | uint64_t *result); | |
238 | ||
239 | #ifdef KERNEL_PRIVATE | |
240 | ||
241 | /* | |
242 | * Obsolete interfaces. | |
243 | */ | |
244 | ||
245 | #ifndef __LP64__ | |
246 | ||
247 | #define MACH_TIMESPEC_SEC_MAX (0 - 1) | |
248 | #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1) | |
249 | ||
250 | #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \ | |
251 | MACH_TIMESPEC_SEC_MAX, \ | |
252 | MACH_TIMESPEC_NSEC_MAX } ) | |
253 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
254 | ||
255 | #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \ | |
256 | do { \ | |
257 | (t1)->tv_nsec += (clock_res_t)(nsec); \ | |
258 | if ((clock_res_t)(nsec) > 0 && \ | |
259 | (t1)->tv_nsec >= NSEC_PER_SEC) { \ | |
260 | (t1)->tv_nsec -= NSEC_PER_SEC; \ | |
261 | (t1)->tv_sec += 1; \ | |
262 | } \ | |
263 | else if ((clock_res_t)(nsec) < 0 && \ | |
264 | (t1)->tv_nsec < 0) { \ | |
265 | (t1)->tv_nsec += NSEC_PER_SEC; \ | |
266 | (t1)->tv_sec -= 1; \ | |
267 | } \ | |
268 | } while (0) | |
269 | ||
270 | ||
271 | extern mach_timespec_t clock_get_system_value(void); | |
272 | ||
273 | extern mach_timespec_t clock_get_calendar_value(void); | |
274 | ||
275 | #else /* __LP64__ */ | |
276 | ||
277 | #ifdef XNU_KERNEL_PRIVATE | |
278 | ||
279 | #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } ) | |
280 | ||
281 | #endif /* XNU_KERNEL_PRIVATE */ | |
282 | ||
283 | #endif /* __LP64__ */ | |
284 | ||
285 | extern void delay_for_interval( | |
286 | uint32_t interval, | |
287 | uint32_t scale_factor); | |
288 | ||
289 | #ifndef MACH_KERNEL_PRIVATE | |
290 | ||
291 | #ifndef __LP64__ | |
292 | ||
293 | #ifndef ABSOLUTETIME_SCALAR_TYPE | |
294 | ||
295 | #define clock_get_uptime(a) \ | |
296 | clock_get_uptime(__OSAbsoluteTimePtr(a)) | |
297 | ||
298 | #define clock_interval_to_deadline(a, b, c) \ | |
299 | clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c)) | |
300 | ||
301 | #define clock_interval_to_absolutetime_interval(a, b, c) \ | |
302 | clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c)) | |
303 | ||
304 | #define clock_absolutetime_interval_to_deadline(a, b) \ | |
305 | clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b)) | |
306 | ||
307 | #define clock_deadline_for_periodic_event(a, b, c) \ | |
308 | clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c)) | |
309 | ||
310 | #define clock_delay_until(a) \ | |
311 | clock_delay_until(__OSAbsoluteTime(a)) | |
312 | ||
313 | #define absolutetime_to_nanoseconds(a, b) \ | |
314 | absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b)) | |
315 | ||
316 | #define nanoseconds_to_absolutetime(a, b) \ | |
317 | nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b)) | |
318 | ||
319 | #endif /* ABSOLUTETIME_SCALAR_TYPE */ | |
320 | ||
321 | #endif /* __LP64__ */ | |
322 | ||
323 | #endif /* MACH_KERNEL_PRIVATE */ | |
324 | ||
325 | #endif /* KERNEL_PRIVATE */ | |
326 | ||
327 | __END_DECLS | |
328 | ||
329 | #endif /* _KERN_CLOCK_H_ */ |