]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/timer.c
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 #include <stat_time.h>
54 #include <machine_timer_routines.h>
56 #include <mach/kern_return.h>
57 #include <mach/port.h>
58 #include <kern/queue.h>
59 #include <kern/processor.h>
60 #include <kern/thread.h>
61 #include <kern/sched_prim.h>
62 #include <kern/timer.h>
65 * timer_init initializes a timer.
73 timer
->high_bits_check
= 0;
76 #endif /* STAT_TIME */
80 * Calculate the difference between a timer
81 * and saved value, and update the saved value.
88 uint64_t new, old
= *save
;
90 *save
= new = timer_grab(timer
);
98 * Update the current timer (if any)
99 * and start the new timer, which
100 * could be either the same or NULL.
102 * Called with interrupts disabled.
109 processor_t processor
= current_processor();
111 uint32_t old_low
, low
;
114 * Update current timer.
116 timer
= PROCESSOR_DATA(processor
, current_timer
);
118 old_low
= timer
->low_bits
;
119 low
= old_low
+ tstamp
- timer
->tstamp
;
121 timer_update(timer
, timer
->high_bits
+ 1, low
);
123 timer
->low_bits
= low
;
129 PROCESSOR_DATA(processor
, current_timer
) = new_timer
;
130 if (new_timer
!= NULL
)
131 new_timer
->tstamp
= tstamp
;
134 #if MACHINE_TIMER_ROUTINES
137 * Machine-dependent code implements the timer event routine.
140 #else /* MACHINE_TIMER_ROUTINES */
143 * Update the current timer and start
144 * the new timer. Requires a current
147 * Called with interrupts disabled.
154 processor_t processor
= current_processor();
156 uint32_t old_low
, low
;
159 * Update current timer.
161 timer
= PROCESSOR_DATA(processor
, current_timer
);
162 old_low
= timer
->low_bits
;
163 low
= old_low
+ tstamp
- timer
->tstamp
;
165 timer_update(timer
, timer
->high_bits
+ 1, low
);
167 timer
->low_bits
= low
;
172 PROCESSOR_DATA(processor
, current_timer
) = new_timer
;
173 new_timer
->tstamp
= tstamp
;
176 #endif /* MACHINE_TIMER_ROUTINES */
178 #endif /* STAT_TIME */