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