]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/clock.h
xnu-1228.tar.gz
[apple/xnu.git] / osfmk / kern / clock.h
1 /*
2 * Copyright (c) 2000-2007 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 MACH_KERNEL_PRIVATE
48
49 /*
50 * Clock operations list structure. Contains vectors to machine
51 * dependent clock routines.
52 */
53 struct clock_ops {
54 int (*c_config)(void); /* configuration */
55
56 int (*c_init)(void); /* initialize */
57
58 kern_return_t (*c_gettime)( /* get time */
59 mach_timespec_t *cur_time);
60
61 kern_return_t (*c_getattr)( /* get attributes */
62 clock_flavor_t flavor,
63 clock_attr_t attr,
64 mach_msg_type_number_t *count);
65 };
66 typedef struct clock_ops *clock_ops_t;
67 typedef struct clock_ops clock_ops_data_t;
68
69 /*
70 * Actual clock object data structure. Contains the machine
71 * dependent operations list and clock operation ports.
72 */
73 struct clock {
74 clock_ops_t cl_ops; /* operations list */
75 struct ipc_port *cl_service; /* service port */
76 struct ipc_port *cl_control; /* control port */
77 };
78 typedef struct clock clock_data_t;
79
80 /*
81 * Configure the clock system.
82 */
83 extern void clock_config(void);
84 extern void clock_oldconfig(void);
85
86 /*
87 * Initialize the clock system.
88 */
89 extern void clock_init(void);
90 extern void clock_oldinit(void);
91
92 extern void clock_timebase_init(void);
93
94 /*
95 * Initialize the clock ipc service facility.
96 */
97 extern void clock_service_create(void);
98
99 typedef void (*clock_timer_func_t)(
100 uint64_t timestamp);
101
102 extern void clock_set_timer_func(
103 clock_timer_func_t func);
104
105 extern void clock_set_timer_deadline(
106 uint64_t deadline);
107
108 extern void clock_gettimeofday_set_commpage(
109 uint64_t abstime,
110 uint64_t epoch,
111 uint64_t offset,
112 uint32_t *secs,
113 uint32_t *microsecs);
114
115 extern void machine_delay_until(
116 uint64_t deadline);
117
118 #include <stat_time.h>
119
120 #if STAT_TIME || GPROF
121
122 extern void hertz_tick(
123 natural_t ticks,
124 boolean_t usermode, /* executing user code */
125 natural_t pc);
126
127 #endif /* STAT_TIME */
128
129 extern uint32_t hz_tick_interval;
130
131 extern void absolutetime_to_nanotime(
132 uint64_t abstime,
133 uint32_t *secs,
134 uint32_t *nanosecs);
135
136 extern void nanotime_to_absolutetime(
137 uint32_t secs,
138 uint32_t nanosecs,
139 uint64_t *result);
140
141 #endif /* MACH_KERNEL_PRIVATE */
142
143 __BEGIN_DECLS
144
145 #ifdef XNU_KERNEL_PRIVATE
146
147 extern void clock_adjtime(
148 int32_t *secs,
149 int32_t *microsecs);
150
151 extern void clock_initialize_calendar(void);
152
153 extern void clock_wakeup_calendar(void);
154
155 extern void clock_gettimeofday(
156 uint32_t *secs,
157 uint32_t *microsecs);
158
159 extern void clock_set_calendar_microtime(
160 uint32_t secs,
161 uint32_t microsecs);
162
163 extern void clock_get_boottime_nanotime(
164 uint32_t *secs,
165 uint32_t *nanosecs);
166
167 extern void absolutetime_to_microtime(
168 uint64_t abstime,
169 uint32_t *secs,
170 uint32_t *microsecs);
171
172 extern void clock_deadline_for_periodic_event(
173 uint64_t interval,
174 uint64_t abstime,
175 uint64_t *deadline);
176
177 #endif /* XNU_KERNEL_PRIVATE */
178
179 extern void clock_get_calendar_microtime(
180 uint32_t *secs,
181 uint32_t *microsecs);
182
183 extern void clock_get_calendar_nanotime(
184 uint32_t *secs,
185 uint32_t *nanosecs);
186
187 /*
188 * Gah! This file is included everywhere. The other domains do not correctly
189 * include config_dtrace headers, so this isn't being defined. The last test
190 * I ran stopped with a build failure in pexpert/i386/kd.c
191 */
192 #if CONFIG_DTRACE
193 extern void clock_get_calendar_nanotime_nowait(
194 uint32_t *secs,
195 uint32_t *nanosecs);
196 #endif /* CONFIG_DTRACE */
197
198 extern void clock_get_system_microtime(
199 uint32_t *secs,
200 uint32_t *microsecs);
201
202 extern void clock_get_system_nanotime(
203 uint32_t *secs,
204 uint32_t *nanosecs);
205
206 extern void clock_timebase_info(
207 mach_timebase_info_t info);
208
209 extern void clock_get_uptime(
210 uint64_t *result);
211
212 extern void clock_interval_to_deadline(
213 uint32_t interval,
214 uint32_t scale_factor,
215 uint64_t *result);
216
217 extern void clock_interval_to_absolutetime_interval(
218 uint32_t interval,
219 uint32_t scale_factor,
220 uint64_t *result);
221
222 extern void clock_absolutetime_interval_to_deadline(
223 uint64_t abstime,
224 uint64_t *result);
225
226 extern void clock_delay_until(
227 uint64_t deadline);
228
229 extern void absolutetime_to_nanoseconds(
230 uint64_t abstime,
231 uint64_t *result);
232
233 extern void nanoseconds_to_absolutetime(
234 uint64_t nanoseconds,
235 uint64_t *result);
236
237 #ifdef KERNEL_PRIVATE
238
239 /*
240 * Obsolete interfaces.
241 */
242
243 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
244 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
245
246 #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \
247 MACH_TIMESPEC_SEC_MAX, \
248 MACH_TIMESPEC_NSEC_MAX } )
249 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
250
251 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
252 do { \
253 (t1)->tv_nsec += (clock_res_t)(nsec); \
254 if ((clock_res_t)(nsec) > 0 && \
255 (t1)->tv_nsec >= NSEC_PER_SEC) { \
256 (t1)->tv_nsec -= NSEC_PER_SEC; \
257 (t1)->tv_sec += 1; \
258 } \
259 else if ((clock_res_t)(nsec) < 0 && \
260 (t1)->tv_nsec < 0) { \
261 (t1)->tv_nsec += NSEC_PER_SEC; \
262 (t1)->tv_sec -= 1; \
263 } \
264 } while (0)
265
266
267 extern mach_timespec_t clock_get_system_value(void);
268
269 extern mach_timespec_t clock_get_calendar_value(void);
270
271 extern void delay_for_interval(
272 uint32_t interval,
273 uint32_t scale_factor);
274 #ifndef MACH_KERNEL_PRIVATE
275
276 #ifndef ABSOLUTETIME_SCALAR_TYPE
277
278 #define clock_get_uptime(a) \
279 clock_get_uptime(__OSAbsoluteTimePtr(a))
280
281 #define clock_interval_to_deadline(a, b, c) \
282 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
283
284 #define clock_interval_to_absolutetime_interval(a, b, c) \
285 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
286
287 #define clock_absolutetime_interval_to_deadline(a, b) \
288 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
289
290 #define clock_deadline_for_periodic_event(a, b, c) \
291 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
292
293 #define clock_delay_until(a) \
294 clock_delay_until(__OSAbsoluteTime(a))
295
296 #define absolutetime_to_nanoseconds(a, b) \
297 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
298
299 #define nanoseconds_to_absolutetime(a, b) \
300 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
301
302 #endif /* ABSOLUTETIME_SCALAR_TYPE */
303
304 #endif /* !MACH_KERNEL_PRIVATE */
305
306 #endif /* KERNEL_PRIVATE */
307
308 __END_DECLS
309
310 #endif /* _KERN_CLOCK_H_ */