]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/timer.h
xnu-792.6.22.tar.gz
[apple/xnu.git] / osfmk / kern / timer.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 #ifndef _KERN_TIMER_H_
54 #define _KERN_TIMER_H_
55
56 #include <stat_time.h>
57
58 #include <kern/kern_types.h>
59
60 /*
61 * Definitions for high resolution timers. A check
62 * word on the high portion allows atomic updates.
63 */
64
65 struct timer {
66 uint32_t low_bits;
67 uint32_t high_bits;
68 uint32_t high_bits_check;
69 #if !STAT_TIME
70 uint32_t tstamp;
71 #endif /* STAT_TIME */
72 };
73
74 typedef struct timer timer_data_t, *timer_t;
75
76 /*
77 * Exported kernel interface to timers
78 */
79
80 #if STAT_TIME
81
82 #include <kern/macro_help.h>
83
84 /* Advance a timer by the specified amount */
85 #define TIMER_BUMP(timer, ticks) \
86 MACRO_BEGIN \
87 uint32_t old_low, low; \
88 \
89 old_low = (timer)->low_bits; \
90 low = old_low + (ticks); \
91 if (low < old_low) \
92 timer_update((timer), (timer)->high_bits + 1, low); \
93 else \
94 (timer)->low_bits = low; \
95 MACRO_END
96
97 #define timer_switch(tstamp, new_timer)
98 #define timer_event(tstamp, new_timer)
99
100 #else /* STAT_TIME */
101
102 /* Update the current timer and start a new one */
103 extern void timer_switch(
104 uint32_t tstamp,
105 timer_t new_timer);
106
107 #define TIMER_BUMP(timer, ticks)
108
109 #endif /* STAT_TIME */
110
111 /* Initialize a timer */
112 extern void timer_init(
113 timer_t timer);
114
115 /* Update a saved timer value and return delta to current value */
116 extern uint64_t timer_delta(
117 timer_t timer,
118 uint64_t *save);
119
120 /*
121 * Exported hardware interface to timers
122 */
123
124 /* Read timer value */
125 extern uint64_t timer_grab(
126 timer_t timer);
127
128 /* Update timer value */
129 extern void timer_update(
130 timer_t timer,
131 uint32_t new_high,
132 uint32_t new_low);
133
134 #if !STAT_TIME
135
136 /* Update the current timer at an event */
137 extern void timer_event(
138 uint32_t tstamp,
139 timer_t new_timer);
140
141 #endif /* STAT_TIME */
142
143 #endif /* _KERN_TIMER_H_ */