2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 #ifndef _KERN_CLOCK_H_
35 #define _KERN_CLOCK_H_
38 #include <mach/mach_types.h>
39 #include <mach/clock_types.h>
40 #include <mach/message.h>
41 #include <mach/mach_time.h>
43 #include <kern/kern_types.h>
45 #include <sys/cdefs.h>
47 #ifdef MACH_KERNEL_PRIVATE
50 * Clock operations list structure. Contains vectors to machine
51 * dependent clock routines.
54 int (*c_config
)(void); /* configuration */
56 int (*c_init
)(void); /* initialize */
58 kern_return_t (*c_gettime
)( /* get time */
59 mach_timespec_t
*cur_time
);
61 kern_return_t (*c_getattr
)( /* get attributes */
62 clock_flavor_t flavor
,
64 mach_msg_type_number_t
*count
);
66 typedef struct clock_ops
*clock_ops_t
;
67 typedef struct clock_ops clock_ops_data_t
;
70 * Actual clock object data structure. Contains the machine
71 * dependent operations list and clock operation ports.
74 clock_ops_t cl_ops
; /* operations list */
75 struct ipc_port
*cl_service
; /* service port */
76 struct ipc_port
*cl_control
; /* control port */
78 typedef struct clock clock_data_t
;
81 * Configure the clock system.
83 extern void clock_config(void);
84 extern void clock_oldconfig(void);
87 * Initialize the clock system.
89 extern void clock_init(void);
90 extern void clock_oldinit(void);
92 extern void clock_timebase_init(void);
95 * Initialize the clock ipc service facility.
97 extern void clock_service_create(void);
99 typedef void (*clock_timer_func_t
)(
102 extern void clock_set_timer_func(
103 clock_timer_func_t func
);
105 extern void clock_set_timer_deadline(
108 extern void clock_gettimeofday_set_commpage(
113 uint32_t *microsecs
);
115 extern void machine_delay_until(
118 #include <stat_time.h>
120 #if STAT_TIME || GPROF
122 extern void hertz_tick(
124 boolean_t usermode
, /* executing user code */
127 #endif /* STAT_TIME */
129 extern uint32_t hz_tick_interval
;
131 extern void absolutetime_to_nanotime(
136 extern void nanotime_to_absolutetime(
141 #endif /* MACH_KERNEL_PRIVATE */
145 #ifdef XNU_KERNEL_PRIVATE
147 extern void clock_adjtime(
151 extern void clock_initialize_calendar(void);
153 extern void clock_wakeup_calendar(void);
155 extern void clock_gettimeofday(
157 uint32_t *microsecs
);
159 extern void clock_set_calendar_microtime(
163 extern void clock_get_boottime_nanotime(
167 extern void absolutetime_to_microtime(
170 uint32_t *microsecs
);
172 extern void clock_deadline_for_periodic_event(
177 #endif /* XNU_KERNEL_PRIVATE */
179 extern void clock_get_calendar_microtime(
181 uint32_t *microsecs
);
183 extern void clock_get_calendar_nanotime(
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
193 extern void clock_get_calendar_nanotime_nowait(
196 #endif /* CONFIG_DTRACE */
198 extern void clock_get_system_microtime(
200 uint32_t *microsecs
);
202 extern void clock_get_system_nanotime(
206 extern void clock_timebase_info(
207 mach_timebase_info_t info
);
209 extern void clock_get_uptime(
212 extern void clock_interval_to_deadline(
214 uint32_t scale_factor
,
217 extern void clock_interval_to_absolutetime_interval(
219 uint32_t scale_factor
,
222 extern void clock_absolutetime_interval_to_deadline(
226 extern void clock_delay_until(
229 extern void absolutetime_to_nanoseconds(
233 extern void nanoseconds_to_absolutetime(
234 uint64_t nanoseconds
,
237 #ifdef KERNEL_PRIVATE
240 * Obsolete interfaces.
243 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
244 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
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 } )
251 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
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; \
259 else if ((clock_res_t)(nsec) < 0 && \
260 (t1)->tv_nsec < 0) { \
261 (t1)->tv_nsec += NSEC_PER_SEC; \
267 extern mach_timespec_t
clock_get_system_value(void);
269 extern mach_timespec_t
clock_get_calendar_value(void);
271 extern void delay_for_interval(
273 uint32_t scale_factor
);
274 #ifndef MACH_KERNEL_PRIVATE
276 #ifndef ABSOLUTETIME_SCALAR_TYPE
278 #define clock_get_uptime(a) \
279 clock_get_uptime(__OSAbsoluteTimePtr(a))
281 #define clock_interval_to_deadline(a, b, c) \
282 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
284 #define clock_interval_to_absolutetime_interval(a, b, c) \
285 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
287 #define clock_absolutetime_interval_to_deadline(a, b) \
288 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
290 #define clock_deadline_for_periodic_event(a, b, c) \
291 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
293 #define clock_delay_until(a) \
294 clock_delay_until(__OSAbsoluteTime(a))
296 #define absolutetime_to_nanoseconds(a, b) \
297 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
299 #define nanoseconds_to_absolutetime(a, b) \
300 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
302 #endif /* ABSOLUTETIME_SCALAR_TYPE */
304 #endif /* !MACH_KERNEL_PRIVATE */
306 #endif /* KERNEL_PRIVATE */
310 #endif /* _KERN_CLOCK_H_ */