]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/clock.h
9e769b14e99866079b5fb4914b830d0784d8f218
[apple/xnu.git] / osfmk / kern / clock.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 */
35
36 #ifndef _KERN_CLOCK_H_
37 #define _KERN_CLOCK_H_
38
39 #include <stdint.h>
40 #include <mach/mach_types.h>
41 #include <mach/clock_types.h>
42 #include <mach/message.h>
43 #include <mach/mach_time.h>
44
45 #include <kern/kern_types.h>
46
47 #include <sys/cdefs.h>
48
49 #ifdef MACH_KERNEL_PRIVATE
50
51 /*
52 * Clock operations list structure. Contains vectors to machine
53 * dependent clock routines.
54 */
55 struct clock_ops {
56 int (*c_config)(void); /* configuration */
57
58 int (*c_init)(void); /* initialize */
59
60 kern_return_t (*c_gettime)( /* get time */
61 mach_timespec_t *cur_time);
62
63 kern_return_t (*c_getattr)( /* get attributes */
64 clock_flavor_t flavor,
65 clock_attr_t attr,
66 mach_msg_type_number_t *count);
67 };
68 typedef struct clock_ops *clock_ops_t;
69 typedef struct clock_ops clock_ops_data_t;
70
71 /*
72 * Actual clock object data structure. Contains the machine
73 * dependent operations list and clock operation ports.
74 */
75 struct clock {
76 clock_ops_t cl_ops; /* operations list */
77 struct ipc_port *cl_service; /* service port */
78 struct ipc_port *cl_control; /* control port */
79 };
80 typedef struct clock clock_data_t;
81
82 /*
83 * Configure the clock system.
84 */
85 extern void clock_config(void);
86 extern void clock_oldconfig(void);
87
88 /*
89 * Initialize the clock system.
90 */
91 extern void clock_init(void);
92 extern void clock_oldinit(void);
93
94 extern void clock_timebase_init(void);
95
96 /*
97 * Initialize the clock ipc service facility.
98 */
99 extern void clock_service_create(void);
100
101 typedef void (*clock_timer_func_t)(
102 uint64_t timestamp);
103
104 extern void clock_set_timer_func(
105 clock_timer_func_t func);
106
107 extern void clock_set_timer_deadline(
108 uint64_t deadline);
109
110 extern void clock_gettimeofday_set_commpage(
111 uint64_t abstime,
112 uint64_t epoch,
113 uint64_t offset,
114 uint32_t *secs,
115 uint32_t *microsecs);
116
117 extern void machine_delay_until(
118 uint64_t deadline);
119
120 #include <stat_time.h>
121
122 extern void hertz_tick(
123 #if STAT_TIME
124 natural_t ticks,
125 #endif /* STAT_TIME */
126 boolean_t usermode, /* executing user code */
127 natural_t pc);
128
129 extern void absolutetime_to_microtime(
130 uint64_t abstime,
131 uint32_t *secs,
132 uint32_t *microsecs);
133
134 extern void absolutetime_to_nanotime(
135 uint64_t abstime,
136 uint32_t *secs,
137 uint32_t *nanosecs);
138
139 extern void nanotime_to_absolutetime(
140 uint32_t secs,
141 uint32_t nanosecs,
142 uint64_t *result);
143
144 #endif /* MACH_KERNEL_PRIVATE */
145
146 __BEGIN_DECLS
147
148 #ifdef XNU_KERNEL_PRIVATE
149
150 extern void clock_adjtime(
151 int32_t *secs,
152 int32_t *microsecs);
153
154 extern void clock_initialize_calendar(void);
155
156 extern void clock_wakeup_calendar(void);
157
158 extern void clock_gettimeofday(
159 uint32_t *secs,
160 uint32_t *microsecs);
161
162 extern void clock_set_calendar_microtime(
163 uint32_t secs,
164 uint32_t microsecs);
165
166 extern void clock_get_boottime_nanotime(
167 uint32_t *secs,
168 uint32_t *nanosecs);
169
170 extern void clock_deadline_for_periodic_event(
171 uint64_t interval,
172 uint64_t abstime,
173 uint64_t *deadline);
174
175 #endif /* XNU_KERNEL_PRIVATE */
176
177
178 extern void clock_get_calendar_microtime(
179 uint32_t *secs,
180 uint32_t *microsecs);
181
182 extern void clock_get_calendar_nanotime(
183 uint32_t *secs,
184 uint32_t *nanosecs);
185
186 extern void clock_get_system_microtime(
187 uint32_t *secs,
188 uint32_t *microsecs);
189
190 extern void clock_get_system_nanotime(
191 uint32_t *secs,
192 uint32_t *nanosecs);
193
194 extern void clock_timebase_info(
195 mach_timebase_info_t info);
196
197 extern void clock_get_uptime(
198 uint64_t *result);
199
200 extern void clock_interval_to_deadline(
201 uint32_t interval,
202 uint32_t scale_factor,
203 uint64_t *result);
204
205 extern void clock_interval_to_absolutetime_interval(
206 uint32_t interval,
207 uint32_t scale_factor,
208 uint64_t *result);
209
210 extern void clock_absolutetime_interval_to_deadline(
211 uint64_t abstime,
212 uint64_t *result);
213
214 extern void clock_delay_until(
215 uint64_t deadline);
216
217 extern void absolutetime_to_nanoseconds(
218 uint64_t abstime,
219 uint64_t *result);
220
221 extern void nanoseconds_to_absolutetime(
222 uint64_t nanoseconds,
223 uint64_t *result);
224
225 #ifdef KERNEL_PRIVATE
226
227 /*
228 * Obsolete interfaces.
229 */
230
231 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
232 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
233
234 #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \
235 MACH_TIMESPEC_SEC_MAX, \
236 MACH_TIMESPEC_NSEC_MAX } )
237 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
238
239 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
240 do { \
241 (t1)->tv_nsec += (clock_res_t)(nsec); \
242 if ((clock_res_t)(nsec) > 0 && \
243 (t1)->tv_nsec >= NSEC_PER_SEC) { \
244 (t1)->tv_nsec -= NSEC_PER_SEC; \
245 (t1)->tv_sec += 1; \
246 } \
247 else if ((clock_res_t)(nsec) < 0 && \
248 (t1)->tv_nsec < 0) { \
249 (t1)->tv_nsec += NSEC_PER_SEC; \
250 (t1)->tv_sec -= 1; \
251 } \
252 } while (0)
253
254
255 extern mach_timespec_t clock_get_system_value(void);
256
257 extern mach_timespec_t clock_get_calendar_value(void);
258
259 extern void delay_for_interval(
260 uint32_t interval,
261 uint32_t scale_factor);
262 #ifndef MACH_KERNEL_PRIVATE
263
264 #ifndef ABSOLUTETIME_SCALAR_TYPE
265
266 #define clock_get_uptime(a) \
267 clock_get_uptime(__OSAbsoluteTimePtr(a))
268
269 #define clock_interval_to_deadline(a, b, c) \
270 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
271
272 #define clock_interval_to_absolutetime_interval(a, b, c) \
273 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
274
275 #define clock_absolutetime_interval_to_deadline(a, b) \
276 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
277
278 #define clock_deadline_for_periodic_event(a, b, c) \
279 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
280
281 #define clock_delay_until(a) \
282 clock_delay_until(__OSAbsoluteTime(a))
283
284 #define absolutetime_to_nanoseconds(a, b) \
285 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
286
287 #define nanoseconds_to_absolutetime(a, b) \
288 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
289
290 #endif /* ABSOLUTETIME_SCALAR_TYPE */
291
292 #endif /* !MACH_KERNEL_PRIVATE */
293
294 #endif /* KERNEL_PRIVATE */
295
296 __END_DECLS
297
298 #endif /* _KERN_CLOCK_H_ */