2 * Copyright (c) 2000-2008 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>
49 typedef unsigned long clock_sec_t
;
50 typedef unsigned int clock_usec_t
, clock_nsec_t
;
54 typedef uint32_t clock_sec_t
;
55 typedef uint32_t clock_usec_t
, clock_nsec_t
;
59 #ifdef MACH_KERNEL_PRIVATE
61 #include <kern/queue.h>
64 * Clock operations list structure. Contains vectors to machine
65 * dependent clock routines.
68 int (*c_config
)(void); /* configuration */
70 int (*c_init
)(void); /* initialize */
72 kern_return_t (*c_gettime
)( /* get time */
73 mach_timespec_t
*cur_time
);
75 kern_return_t (*c_getattr
)( /* get attributes */
76 clock_flavor_t flavor
,
78 mach_msg_type_number_t
*count
);
80 typedef struct clock_ops
*clock_ops_t
;
81 typedef struct clock_ops clock_ops_data_t
;
84 * Actual clock object data structure. Contains the machine
85 * dependent operations list and clock operation ports.
88 clock_ops_t cl_ops
; /* operations list */
89 struct ipc_port
*cl_service
; /* service port */
90 struct ipc_port
*cl_control
; /* control port */
92 typedef struct clock clock_data_t
;
95 * Configure the clock system.
97 extern void clock_config(void);
98 extern void clock_oldconfig(void);
101 * Initialize the clock system.
103 extern void clock_init(void);
104 extern void clock_oldinit(void);
106 extern void clock_timebase_init(void);
109 * Initialize the clock ipc service facility.
111 extern void clock_service_create(void);
113 extern void clock_gettimeofday_set_commpage(
118 clock_usec_t
*microsecs
);
120 extern void machine_delay_until(
123 extern uint32_t hz_tick_interval
;
125 extern void absolutetime_to_nanotime(
128 clock_nsec_t
*nanosecs
);
130 extern void nanotime_to_absolutetime(
132 clock_nsec_t nanosecs
,
135 #endif /* MACH_KERNEL_PRIVATE */
139 #ifdef XNU_KERNEL_PRIVATE
141 extern void clock_adjtime(
145 extern void clock_initialize_calendar(void);
147 extern void clock_wakeup_calendar(void);
149 extern void clock_gettimeofday(
151 clock_usec_t
*microsecs
);
153 extern void clock_set_calendar_microtime(
155 clock_usec_t microsecs
);
157 extern void clock_get_boottime_nanotime(
159 clock_nsec_t
*nanosecs
);
161 extern void absolutetime_to_microtime(
164 clock_usec_t
*microsecs
);
166 extern void clock_deadline_for_periodic_event(
173 extern void clock_get_calendar_nanotime_nowait(
175 clock_nsec_t
*nanosecs
);
177 #endif /* CONFIG_DTRACE */
179 #endif /* XNU_KERNEL_PRIVATE */
181 extern void clock_get_calendar_microtime(
183 clock_usec_t
*microsecs
);
185 extern void clock_get_calendar_nanotime(
187 clock_nsec_t
*nanosecs
);
189 extern void clock_get_system_microtime(
191 clock_usec_t
*microsecs
);
193 extern void clock_get_system_nanotime(
195 clock_nsec_t
*nanosecs
);
197 extern void clock_timebase_info(
198 mach_timebase_info_t info
);
200 extern void clock_get_uptime(
203 extern void clock_interval_to_deadline(
205 uint32_t scale_factor
,
208 extern void clock_interval_to_absolutetime_interval(
210 uint32_t scale_factor
,
213 extern void clock_absolutetime_interval_to_deadline(
217 extern void clock_delay_until(
220 extern void absolutetime_to_nanoseconds(
224 extern void nanoseconds_to_absolutetime(
225 uint64_t nanoseconds
,
228 #ifdef KERNEL_PRIVATE
231 * Obsolete interfaces.
236 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
237 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
239 #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \
240 MACH_TIMESPEC_SEC_MAX, \
241 MACH_TIMESPEC_NSEC_MAX } )
242 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
244 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
246 (t1)->tv_nsec += (clock_res_t)(nsec); \
247 if ((clock_res_t)(nsec) > 0 && \
248 (t1)->tv_nsec >= NSEC_PER_SEC) { \
249 (t1)->tv_nsec -= NSEC_PER_SEC; \
252 else if ((clock_res_t)(nsec) < 0 && \
253 (t1)->tv_nsec < 0) { \
254 (t1)->tv_nsec += NSEC_PER_SEC; \
259 #include <Availability.h>
261 /* Use mach_absolute_time() */
262 extern mach_timespec_t
clock_get_system_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0
, __MAC_10_8
, __IPHONE_2_0
, __IPHONE_NA
);
264 extern mach_timespec_t
clock_get_calendar_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0
, __MAC_10_8
, __IPHONE_2_0
, __IPHONE_NA
);
268 #ifdef XNU_KERNEL_PRIVATE
270 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
272 #endif /* XNU_KERNEL_PRIVATE */
274 #endif /* __LP64__ */
276 extern void delay_for_interval(
278 uint32_t scale_factor
);
280 #ifndef MACH_KERNEL_PRIVATE
284 #ifndef ABSOLUTETIME_SCALAR_TYPE
286 #define clock_get_uptime(a) \
287 clock_get_uptime(__OSAbsoluteTimePtr(a))
289 #define clock_interval_to_deadline(a, b, c) \
290 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
292 #define clock_interval_to_absolutetime_interval(a, b, c) \
293 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
295 #define clock_absolutetime_interval_to_deadline(a, b) \
296 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
298 #define clock_deadline_for_periodic_event(a, b, c) \
299 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
301 #define clock_delay_until(a) \
302 clock_delay_until(__OSAbsoluteTime(a))
304 #define absolutetime_to_nanoseconds(a, b) \
305 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
307 #define nanoseconds_to_absolutetime(a, b) \
308 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
310 #endif /* ABSOLUTETIME_SCALAR_TYPE */
312 #endif /* __LP64__ */
314 #endif /* MACH_KERNEL_PRIVATE */
316 #endif /* KERNEL_PRIVATE */
320 #endif /* _KERN_CLOCK_H_ */