2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
36 #ifndef _KERN_CLOCK_H_
37 #define _KERN_CLOCK_H_
40 #include <mach/mach_types.h>
41 #include <mach/clock_types.h>
42 #include <mach/message.h>
43 #include <mach/mach_time.h>
45 #include <kern/kern_types.h>
47 #include <sys/cdefs.h>
49 #ifdef MACH_KERNEL_PRIVATE
52 * Clock operations list structure. Contains vectors to machine
53 * dependent clock routines.
56 int (*c_config
)(void); /* configuration */
58 int (*c_init
)(void); /* initialize */
60 kern_return_t (*c_gettime
)( /* get time */
61 mach_timespec_t
*cur_time
);
63 kern_return_t (*c_getattr
)( /* get attributes */
64 clock_flavor_t flavor
,
66 mach_msg_type_number_t
*count
);
68 typedef struct clock_ops
*clock_ops_t
;
69 typedef struct clock_ops clock_ops_data_t
;
72 * Actual clock object data structure. Contains the machine
73 * dependent operations list and clock operation ports.
76 clock_ops_t cl_ops
; /* operations list */
77 struct ipc_port
*cl_service
; /* service port */
78 struct ipc_port
*cl_control
; /* control port */
80 typedef struct clock clock_data_t
;
83 * Configure the clock system.
85 extern void clock_config(void);
86 extern void clock_oldconfig(void);
89 * Initialize the clock system.
91 extern void clock_init(void);
92 extern void clock_oldinit(void);
94 extern void clock_timebase_init(void);
97 * Initialize the clock ipc service facility.
99 extern void clock_service_create(void);
101 typedef void (*clock_timer_func_t
)(
104 extern void clock_set_timer_func(
105 clock_timer_func_t func
);
107 extern void clock_set_timer_deadline(
110 extern void clock_gettimeofday_set_commpage(
115 uint32_t *microsecs
);
117 extern void machine_delay_until(
120 #include <stat_time.h>
122 extern void hertz_tick(
125 #endif /* STAT_TIME */
126 boolean_t usermode
, /* executing user code */
129 extern void absolutetime_to_microtime(
132 uint32_t *microsecs
);
134 extern void absolutetime_to_nanotime(
139 extern void nanotime_to_absolutetime(
144 #endif /* MACH_KERNEL_PRIVATE */
148 #ifdef XNU_KERNEL_PRIVATE
150 extern void clock_adjtime(
154 extern void clock_initialize_calendar(void);
156 extern void clock_wakeup_calendar(void);
158 extern void clock_gettimeofday(
160 uint32_t *microsecs
);
162 extern void clock_set_calendar_microtime(
166 extern void clock_get_boottime_nanotime(
170 extern void clock_deadline_for_periodic_event(
175 #endif /* XNU_KERNEL_PRIVATE */
178 extern void clock_get_calendar_microtime(
180 uint32_t *microsecs
);
182 extern void clock_get_calendar_nanotime(
186 extern void clock_get_system_microtime(
188 uint32_t *microsecs
);
190 extern void clock_get_system_nanotime(
194 extern void clock_timebase_info(
195 mach_timebase_info_t info
);
197 extern void clock_get_uptime(
200 extern void clock_interval_to_deadline(
202 uint32_t scale_factor
,
205 extern void clock_interval_to_absolutetime_interval(
207 uint32_t scale_factor
,
210 extern void clock_absolutetime_interval_to_deadline(
214 extern void clock_delay_until(
217 extern void absolutetime_to_nanoseconds(
221 extern void nanoseconds_to_absolutetime(
222 uint64_t nanoseconds
,
225 #ifdef KERNEL_PRIVATE
228 * Obsolete interfaces.
231 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
232 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
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 } )
239 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
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; \
247 else if ((clock_res_t)(nsec) < 0 && \
248 (t1)->tv_nsec < 0) { \
249 (t1)->tv_nsec += NSEC_PER_SEC; \
255 extern mach_timespec_t
clock_get_system_value(void);
257 extern mach_timespec_t
clock_get_calendar_value(void);
259 extern void delay_for_interval(
261 uint32_t scale_factor
);
262 #ifndef MACH_KERNEL_PRIVATE
264 #ifndef ABSOLUTETIME_SCALAR_TYPE
266 #define clock_get_uptime(a) \
267 clock_get_uptime(__OSAbsoluteTimePtr(a))
269 #define clock_interval_to_deadline(a, b, c) \
270 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
272 #define clock_interval_to_absolutetime_interval(a, b, c) \
273 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
275 #define clock_absolutetime_interval_to_deadline(a, b) \
276 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
278 #define clock_deadline_for_periodic_event(a, b, c) \
279 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
281 #define clock_delay_until(a) \
282 clock_delay_until(__OSAbsoluteTime(a))
284 #define absolutetime_to_nanoseconds(a, b) \
285 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
287 #define nanoseconds_to_absolutetime(a, b) \
288 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
290 #endif /* ABSOLUTETIME_SCALAR_TYPE */
292 #endif /* !MACH_KERNEL_PRIVATE */
294 #endif /* KERNEL_PRIVATE */
298 #endif /* _KERN_CLOCK_H_ */