2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 #ifndef _KERN_CLOCK_H_
29 #define _KERN_CLOCK_H_
32 #include <mach/mach_types.h>
33 #include <mach/clock_types.h>
34 #include <mach/message.h>
35 #include <mach/mach_time.h>
37 #include <kern/kern_types.h>
39 #include <sys/cdefs.h>
41 #ifdef MACH_KERNEL_PRIVATE
44 * Clock operations list structure. Contains vectors to machine
45 * dependent clock routines.
48 int (*c_config
)(void); /* configuration */
50 int (*c_init
)(void); /* initialize */
52 kern_return_t (*c_gettime
)( /* get time */
53 mach_timespec_t
*cur_time
);
55 kern_return_t (*c_getattr
)( /* get attributes */
56 clock_flavor_t flavor
,
58 mach_msg_type_number_t
*count
);
60 typedef struct clock_ops
*clock_ops_t
;
61 typedef struct clock_ops clock_ops_data_t
;
64 * Actual clock object data structure. Contains the machine
65 * dependent operations list and clock operation ports.
68 clock_ops_t cl_ops
; /* operations list */
69 struct ipc_port
*cl_service
; /* service port */
70 struct ipc_port
*cl_control
; /* control port */
72 typedef struct clock clock_data_t
;
75 * Configure the clock system.
77 extern void clock_config(void);
78 extern void clock_oldconfig(void);
81 * Initialize the clock system.
83 extern void clock_init(void);
84 extern void clock_oldinit(void);
86 extern void clock_timebase_init(void);
89 * Initialize the clock ipc service facility.
91 extern void clock_service_create(void);
93 typedef void (*clock_timer_func_t
)(
96 extern void clock_set_timer_func(
97 clock_timer_func_t func
);
99 extern void clock_set_timer_deadline(
102 extern void clock_gettimeofday_set_commpage(
107 uint32_t *microsecs
);
109 extern void machine_delay_until(
112 #include <stat_time.h>
114 extern void hertz_tick(
117 #endif /* STAT_TIME */
118 boolean_t usermode
, /* executing user code */
121 extern void absolutetime_to_microtime(
124 uint32_t *microsecs
);
126 extern void absolutetime_to_nanotime(
131 extern void nanotime_to_absolutetime(
136 #endif /* MACH_KERNEL_PRIVATE */
140 #ifdef XNU_KERNEL_PRIVATE
142 extern void clock_adjtime(
146 extern void clock_initialize_calendar(void);
148 extern void clock_wakeup_calendar(void);
150 extern void clock_gettimeofday(
152 uint32_t *microsecs
);
154 extern void clock_set_calendar_microtime(
158 extern void clock_get_boottime_nanotime(
162 extern void clock_deadline_for_periodic_event(
167 #endif /* XNU_KERNEL_PRIVATE */
170 extern void clock_get_calendar_microtime(
172 uint32_t *microsecs
);
174 extern void clock_get_calendar_nanotime(
178 extern void clock_get_system_microtime(
180 uint32_t *microsecs
);
182 extern void clock_get_system_nanotime(
186 extern void clock_timebase_info(
187 mach_timebase_info_t info
);
189 extern void clock_get_uptime(
192 extern void clock_interval_to_deadline(
194 uint32_t scale_factor
,
197 extern void clock_interval_to_absolutetime_interval(
199 uint32_t scale_factor
,
202 extern void clock_absolutetime_interval_to_deadline(
206 extern void clock_delay_until(
209 extern void absolutetime_to_nanoseconds(
213 extern void nanoseconds_to_absolutetime(
214 uint64_t nanoseconds
,
217 #ifdef KERNEL_PRIVATE
220 * Obsolete interfaces.
223 #define MACH_TIMESPEC_SEC_MAX (0 - 1)
224 #define MACH_TIMESPEC_NSEC_MAX (NSEC_PER_SEC - 1)
226 #define MACH_TIMESPEC_MAX ((mach_timespec_t) { \
227 MACH_TIMESPEC_SEC_MAX, \
228 MACH_TIMESPEC_NSEC_MAX } )
229 #define MACH_TIMESPEC_ZERO ((mach_timespec_t) { 0, 0 } )
231 #define ADD_MACH_TIMESPEC_NSEC(t1, nsec) \
233 (t1)->tv_nsec += (clock_res_t)(nsec); \
234 if ((clock_res_t)(nsec) > 0 && \
235 (t1)->tv_nsec >= NSEC_PER_SEC) { \
236 (t1)->tv_nsec -= NSEC_PER_SEC; \
239 else if ((clock_res_t)(nsec) < 0 && \
240 (t1)->tv_nsec < 0) { \
241 (t1)->tv_nsec += NSEC_PER_SEC; \
247 extern mach_timespec_t
clock_get_system_value(void);
249 extern mach_timespec_t
clock_get_calendar_value(void);
251 extern void delay_for_interval(
253 uint32_t scale_factor
);
254 #ifndef MACH_KERNEL_PRIVATE
256 #ifndef ABSOLUTETIME_SCALAR_TYPE
258 #define clock_get_uptime(a) \
259 clock_get_uptime(__OSAbsoluteTimePtr(a))
261 #define clock_interval_to_deadline(a, b, c) \
262 clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
264 #define clock_interval_to_absolutetime_interval(a, b, c) \
265 clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
267 #define clock_absolutetime_interval_to_deadline(a, b) \
268 clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
270 #define clock_deadline_for_periodic_event(a, b, c) \
271 clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
273 #define clock_delay_until(a) \
274 clock_delay_until(__OSAbsoluteTime(a))
276 #define absolutetime_to_nanoseconds(a, b) \
277 absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
279 #define nanoseconds_to_absolutetime(a, b) \
280 nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
282 #endif /* ABSOLUTETIME_SCALAR_TYPE */
284 #endif /* !MACH_KERNEL_PRIVATE */
286 #endif /* KERNEL_PRIVATE */
290 #endif /* _KERN_CLOCK_H_ */