2 * Copyright (c) 2000 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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 #ifndef _KERN_TIMER_H_
54 #define _KERN_TIMER_H_
57 #include <stat_time.h>
59 #include <kern/macro_help.h>
60 #include <kern/kern_types.h>
64 * Statistical timer definitions - use microseconds in timer, seconds
65 * in high unit field. No adjustment needed to convert to time_value_t
66 * as a result. Service timers once an hour.
69 #define TIMER_RATE 1000000
70 #define TIMER_HIGH_UNIT TIMER_RATE
75 * Machine dependent definitions based on hardware support.
78 #include <machine/timer.h>
80 #endif /* STAT_TIME */
83 * Definitions for accurate timers. high_bits_check is a copy of
84 * high_bits that allows reader to verify that values read are ok.
90 unsigned high_bits_check
;
94 typedef struct timer timer_data_t
;
95 typedef struct timer
*timer_t
;
98 * Mask to check if low_bits is in danger of overflowing
101 #define TIMER_LOW_FULL 0x80000000
104 * Kernel timers and current timer array. [Exported]
107 extern timer_t current_timer
[NCPUS
];
108 extern timer_data_t kernel_timer
[NCPUS
];
111 * save structure for timer readings. This is used to save timer
112 * readings for elapsed time computations.
120 typedef struct timer_save timer_save_data_t
, *timer_save_t
;
123 * Exported kernel interface to timers
127 #define start_timer(timer)
128 #define timer_switch(timer)
129 #else /* STAT_TIME */
130 /* Start timer for this cpu */
131 extern void start_timer(
134 /* Switch to a new timer */
135 extern void timer_switch(
137 #endif /* STAT_TIME */
139 /* Initialize timer module */
140 extern void init_timers(void);
143 * Initializes a single timer.
145 extern void timer_init(
148 /* Normalize timer value */
149 extern void timer_normalize(
152 /* Read value of timer into tv */
153 extern void timer_read(
157 /* Read thread times */
158 extern void thread_read_times(
160 time_value_t
*user_time_p
,
161 time_value_t
*system_time_p
);
163 /* Compute timer difference */
164 extern unsigned timer_delta(
170 * Macro to bump timer values.
172 #define timer_bump(timer, usec) \
174 (timer)->low_bits += usec; \
175 if ((timer)->low_bits & TIMER_LOW_FULL) { \
176 timer_normalize(timer); \
180 #else /* STAT_TIME */
182 * Exported hardware interface to timers
184 /* Time trap entry */
185 extern void time_trap_uentry(
189 extern void time_trap_uexit(
192 /* Time interrupt entry */
193 extern timer_t
time_int_entry(
197 /* Time interrrupt exit */
198 extern void time_int_exit(
202 #endif /* STAT_TIME */
205 * TIMER_DELTA finds the difference between a timer and a saved value,
206 * and updates the saved value. Look at high_bits check field after
207 * reading low because that's the first written by a normalize
208 * operation; this isn't necessary for current usage because
209 * this macro is only used when the timer can't be normalized:
210 * thread is not running, or running thread calls it on itself at
214 #define TIMER_DELTA(timer, save, result) \
216 register unsigned temp; \
218 temp = (timer).low_bits; \
219 if ((save).high != (timer).high_bits_check) { \
220 result += timer_delta(&(timer), &(save)); \
223 result += temp - (save).low; \
228 #endif /* _KERN_TIMER_H_ */