]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/hardclock.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 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.
57 #include <time_stamp.h>
59 #include <kern/cpu_number.h>
60 #include <kern/cpu_data.h>
61 #include <kern/kern_types.h>
62 #include <platforms.h>
63 #include <mach_kprof.h>
64 #include <mach_mp_debug.h>
65 #include <mach/std_types.h>
67 #include <mach/clock_types.h>
68 #include <mach/boolean.h>
69 #include <i386/thread.h>
70 #include <i386/eflags.h>
71 #include <kern/assert.h>
72 #include <kern/misc_protos.h>
73 #include <i386/misc_protos.h>
74 #include <kern/time_out.h>
75 #include <kern/processor.h>
79 #include <i386/hardclock_entries.h>
80 #include <i386/rtclock_entries.h>
83 #include <i386/mach_param.h> /* for HZ */
84 #endif /* MACH_MP_DEBUG */
86 extern char return_to_iret
[];
88 #if TIME_STAMP && NCPUS > 1
89 extern unsigned time_stamp
;
90 unsigned old_time_stamp
, time_stamp_cum
, nstamps
;
93 * If H/W provides a counter, record number of ticks and cumulated
94 * time stamps to know timestamps rate.
95 * This should go away when ALARMCLOCKS installed
97 #define time_stamp_stat() \
99 if (!old_time_stamp) { \
100 old_time_stamp = time_stamp; \
104 time_stamp_cum = (time_stamp - old_time_stamp); \
106 #else /* TIME_STAMP && AT386 && NCPUS > 1 */
107 #define time_stamp_stat()
108 #endif /* TIME_STAMP && AT386 && NCPUS > 1 */
111 int masked_pc
[NCPUS
];
112 int missed_clock
[NCPUS
];
113 int detect_lost_tick
= 0;
114 #endif /* MACH_KPROF */
117 int masked_state_cnt
[NCPUS
];
118 int masked_state_max
= 10*HZ
;
119 #endif /* MACH_MP_DEBUG */
122 * In the interest of a fast clock interrupt service path,
123 * this routine should be folded into assembly language with
124 * a direct interrupt vector on the i386. The "pit" interrupt
125 * should always call the rtclock_intr() routine on the master
126 * processor. The return value of the rtclock_intr() routine
127 * indicates whether HZ rate clock processing should be
128 * performed. (On the Sequent, all slave processors will
129 * run at HZ rate). For now, we'll leave this routine in C
130 * (with TIME_STAMP, MACH_MP_DEBUG and MACH_KPROF code this
131 * routine is way too large for assembler anyway).
135 int paranoid_debugger
= TRUE
;
136 int paranoid_count
= 1000;
137 int paranoid_current
= 0;
138 int paranoid_cpu
= 0;
139 #endif /* PARANOID_KDB */
142 hardclock(struct i386_interrupt_state
*regs
) /* saved registers */
145 register unsigned pc
;
146 register boolean_t usermode
;
148 mp_disable_preemption();
149 mycpu
= cpu_number();
152 if (paranoid_cpu
== mycpu
&&
153 paranoid_current
++ >= paranoid_count
) {
154 paranoid_current
= 0;
155 if (paranoid_debugger
)
156 Debugger("hardclock");
158 #endif /* PARANOID_KDB */
162 * If we were masked against the clock skip call
163 * to rtclock_intr(). When MACH_KPROF is set, the
164 * clock frequency of the master-cpu is confined
167 if (SPL_CMP_GE((old_ipl
& 0xFF), SPL7
)) {
168 usermode
= (regs
->efl
& EFL_VM
) || ((regs
->cs
& 0x03) != 0);
169 pc
= (unsigned)regs
->eip
;
171 if (missed_clock
[mycpu
]++ && detect_lost_tick
> 1)
172 Debugger("Mach_KPROF");
173 masked_pc
[mycpu
] = pc
;
175 #endif /* MACH_KPROF */
177 * The master processor executes the rtclock_intr() routine
178 * on every clock tick. The rtclock_intr() routine returns
179 * a zero value on a HZ tick boundary.
181 if (mycpu
== master_cpu
) {
182 if (rtclock_intr(regs
) != 0) {
183 mp_enable_preemption();
187 usermode
= (regs
->efl
& EFL_VM
) || ((regs
->cs
& 0x03) != 0);
188 pc
= (unsigned)regs
->eip
;
189 hertz_tick(usermode
, pc
);
193 * The following code is executed at HZ rate by all processors
194 * in the system. This implies that the clock rate on slave
195 * processors must be HZ rate.
202 * Instead of having the master processor interrupt
203 * all active processors, each processor in turn interrupts
204 * the next active one. This avoids all slave processors
205 * accessing the same R/W data simultaneously.
208 #endif /* NCPUS >1 && AT386 */
210 mp_enable_preemption();
220 mp_disable_preemption();
221 my_cpu
= cpu_number();
223 if (missed_clock
[my_cpu
] > 1 && detect_lost_tick
)
224 printf("hardclock: missed %d clock interrupt(s) at %x\n",
225 missed_clock
[my_cpu
]-1, masked_pc
[my_cpu
]);
226 if (my_cpu
== master_cpu
) {
230 hertz_tick(0, masked_pc
[my_cpu
]);
231 missed_clock
[my_cpu
] = 0;
233 mp_enable_preemption();
235 #endif /* MACH_KPROF */