2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 #ifndef _KERN_TIMER_H_
57 #define _KERN_TIMER_H_
60 #include <stat_time.h>
62 #include <kern/macro_help.h>
63 #include <kern/kern_types.h>
67 * Statistical timer definitions - use microseconds in timer, seconds
68 * in high unit field. No adjustment needed to convert to time_value_t
69 * as a result. Service timers once an hour.
72 #define TIMER_RATE 1000000
73 #define TIMER_HIGH_UNIT TIMER_RATE
78 * Machine dependent definitions based on hardware support.
81 #include <machine/timer.h>
83 #endif /* STAT_TIME */
86 * Definitions for accurate timers. high_bits_check is a copy of
87 * high_bits that allows reader to verify that values read are ok.
93 unsigned high_bits_check
;
97 typedef struct timer timer_data_t
;
98 typedef struct timer
*timer_t
;
101 * Mask to check if low_bits is in danger of overflowing
104 #define TIMER_LOW_FULL 0x80000000
107 * Kernel timers and current timer array. [Exported]
110 extern timer_t current_timer
[NCPUS
];
111 extern timer_data_t kernel_timer
[NCPUS
];
114 * save structure for timer readings. This is used to save timer
115 * readings for elapsed time computations.
123 typedef struct timer_save timer_save_data_t
, *timer_save_t
;
126 * Exported kernel interface to timers
130 #define start_timer(timer)
131 #define timer_switch(timer)
132 #else /* STAT_TIME */
133 /* Start timer for this cpu */
134 extern void start_timer(
137 /* Switch to a new timer */
138 extern void timer_switch(
140 #endif /* STAT_TIME */
142 /* Initialize timer module */
143 extern void init_timers(void);
146 * Initializes a single timer.
148 extern void timer_init(
151 /* Normalize timer value */
152 extern void timer_normalize(
155 /* Read value of timer into tv */
156 extern void timer_read(
160 /* Read thread times */
161 extern void thread_read_times(
163 time_value_t
*user_time_p
,
164 time_value_t
*system_time_p
);
166 /* Compute timer difference */
167 extern unsigned timer_delta(
173 * Macro to bump timer values.
175 #define timer_bump(timer, usec) \
177 (timer)->low_bits += usec; \
178 if ((timer)->low_bits & TIMER_LOW_FULL) { \
179 timer_normalize(timer); \
183 #else /* STAT_TIME */
185 * Exported hardware interface to timers
187 /* Time trap entry */
188 extern void time_trap_uentry(
192 extern void time_trap_uexit(
195 /* Time interrupt entry */
196 extern timer_t
time_int_entry(
200 /* Time interrrupt exit */
201 extern void time_int_exit(
205 #endif /* STAT_TIME */
208 * TIMER_DELTA finds the difference between a timer and a saved value,
209 * and updates the saved value. Look at high_bits check field after
210 * reading low because that's the first written by a normalize
211 * operation; this isn't necessary for current usage because
212 * this macro is only used when the timer can't be normalized:
213 * thread is not running, or running thread calls it on itself at
217 #define TIMER_DELTA(timer, save, result) \
219 register unsigned temp; \
221 temp = (timer).low_bits; \
222 if ((save).high != (timer).high_bits_check) { \
223 result += timer_delta(&(timer), &(save)); \
226 result += temp - (save).low; \
231 #endif /* _KERN_TIMER_H_ */