4397a6525f923fd0aaf1c9d478cdf283aeea9359
[dragonfly.git] / sys / i386 / include / smptests.h
1 /*
2  * Copyright (c) 1996, by Steve Passe
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. The name of the developer may NOT be used to endorse or promote products
11  *    derived from this software without specific prior written permission.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD: src/sys/i386/include/smptests.h,v 1.33.2.1 2000/05/16 06:58:10 dillon Exp $
26  * $DragonFly: src/sys/i386/include/Attic/smptests.h,v 1.4 2004/02/17 19:38:54 dillon Exp $
27  */
28
29 #ifndef _MACHINE_SMPTESTS_H_
30 #define _MACHINE_SMPTESTS_H_
31
32
33 /*
34  * Various 'tests in progress' and configuration parameters.
35  */
36
37 /*
38  * Control the "giant lock" pushdown by logical steps.
39  */
40 #define PUSHDOWN_LEVEL_1
41 #define PUSHDOWN_LEVEL_2
42 #define PUSHDOWN_LEVEL_3_NOT
43 #define PUSHDOWN_LEVEL_4_NOT
44
45 /*
46  * Put FAST_INTR() ISRs at an APIC priority above the regular INTs.
47  * Allow the mp_lock() routines to handle FAST interrupts while spinning.
48  */
49 #ifdef PUSHDOWN_LEVEL_1
50 #define FAST_HI
51 #endif
52
53
54 /*
55  * These defines enable critical region locking of areas that were
56  * protected via cli/sti in the UP kernel.
57  *
58  * MPINTRLOCK protects all the generic areas.
59  * COMLOCK protects the sio/cy drivers.
60  * CLOCKLOCK protects clock hardware and data
61  * known to be incomplete:
62  *      joystick lkm
63  *      ?
64  */
65 #ifdef PUSHDOWN_LEVEL_1
66 #define USE_MPINTRLOCK
67 #define USE_COMLOCK
68 #define USE_CLOCKLOCK
69 #endif
70
71
72 /*
73  * INTR_SIMPLELOCK has been removed, as the interrupt mechanism will likely
74  * not use this sort of optimization if we move to interrupt threads.
75  */
76 #ifdef PUSHDOWN_LEVEL_4
77 #endif
78
79
80 /*
81  * CPL_AND_CML has been removed.  Interrupt threads will eventually not
82  * use either mechanism so there is no point trying to optimize it.
83  */
84 #ifdef PUSHDOWN_LEVEL_3
85 #endif
86
87
88 /*
89  * SPL_DEBUG_POSTCODE/INTR_SPL/SPL_DEBUG - removed
90  *
91  * These functions were too expensive for the standard case but, more 
92  * importantly, we should be able to come up with a much cleaner way
93  * to handle the cpl.  Having to do any locking at all is a mistake
94  * for something that is modified as often as cpl is.
95  */
96
97 /*
98  * FAST_WITHOUTCPL - now made the default (define removed).  Text below 
99  * contains the current discussion.  I am confident we can find a solution
100  * that does not require us to process softints from a hard int, which can
101  * kill serial performance due to the lack of true hardware ipl's.
102  *
103  ****
104  *
105  * Ignore the ipending bits when exiting FAST_INTR() routines.
106  *
107  * according to Bruce:
108  *
109  * setsoft*() may set ipending.  setsofttty() is actually used in the
110  * FAST_INTR handler in some serial drivers.  This is necessary to get
111  * output completions and other urgent events handled as soon as possible.
112  * The flag(s) could be set in a variable other than ipending, but they
113  * needs to be checked against cpl to decide whether the software interrupt
114  * handler can/should run.
115  *
116  *  (FAST_INTR used to just return
117  * in all cases until rev.1.7 of vector.s.  This worked OK provided there
118  * were no user-mode CPU hogs.  CPU hogs caused an average latency of 1/2
119  * clock tick for output completions...)
120  ***
121  *
122  * So I need to restore cpl handling someday, but AFTER
123  *  I finish making spl/cpl MP-safe.
124  */
125 #ifdef PUSHDOWN_LEVEL_1
126 #endif
127
128
129 /*
130  * FAST_SIMPLELOCK no longer exists, because it doesn't help us.  The cpu
131  * is likely to already hold the MP lock and recursive MP locks are now
132  * very cheap, so we do not need this optimization.  Eventually *ALL* 
133  * interrupts will run in their own thread, so there is no sense complicating
134  * matters now.
135  */
136 #ifdef PUSHDOWN_LEVEL_1
137 #endif
138
139
140 /*
141  * Portions of the old TEST_LOPRIO code, back from the grave!
142  */
143 #define GRAB_LOPRIO
144
145
146 /*
147  * Send CPUSTOP IPI for stop/restart of other CPUs on DDB break.
148  *
149 #define VERBOSE_CPUSTOP_ON_DDBBREAK
150  */
151 #define CPUSTOP_ON_DDBBREAK
152
153
154 /*
155  * Bracket code/comments relevant to the current 'giant lock' model.
156  * Everything is now the 'giant lock' model, but we will use this as
157  * we start to "push down" the lock.
158  */
159 #define GIANT_LOCK
160
161 #ifdef APIC_IO
162
163 /*
164  * Don't assume that slow interrupt handler X is called from vector
165  * X + ICU_OFFSET.
166  */
167 #define APIC_INTR_REORDER
168
169 /*
170  * Redirect clock interrupts to a higher priority (fast intr) vector,
171  * while still using the slow interrupt handler. Only effective when 
172  * APIC_INTR_REORDER is defined.
173  */
174 #define APIC_INTR_HIGHPRI_CLOCK
175
176 #endif /* APIC_IO */
177
178 /*
179  * Misc. counters.
180  *
181 #define COUNT_XINVLTLB_HITS
182  */
183
184
185 /**
186  * Hack to "fake-out" kernel into thinking it is running on a 'default config'.
187  *
188  * value == default type
189 #define TEST_DEFAULT_CONFIG     6
190  */
191
192
193 /*
194  * Simple test code for IPI interaction, save for future...
195  *
196 #define TEST_TEST1
197 #define IPI_TARGET_TEST1        1
198  */
199
200
201 /*
202  * Address of POST hardware port.
203  * Defining this enables POSTCODE macros.
204  *
205 #define POST_ADDR               0x80
206  */
207
208
209 /*
210  * POST hardware macros.
211  */
212 #ifdef POST_ADDR
213 #define ASMPOSTCODE_INC                         \
214         pushl   %eax ;                          \
215         movl    _current_postcode, %eax ;       \
216         incl    %eax ;                          \
217         andl    $0xff, %eax ;                   \
218         movl    %eax, _current_postcode ;       \
219         outb    %al, $POST_ADDR ;               \
220         popl    %eax
221
222 /*
223  * Overwrite the current_postcode value.
224  */
225 #define ASMPOSTCODE(X)                          \
226         pushl   %eax ;                          \
227         movl    $X, %eax ;                      \
228         movl    %eax, _current_postcode ;       \
229         outb    %al, $POST_ADDR ;               \
230         popl    %eax
231
232 /*
233  * Overwrite the current_postcode low nibble.
234  */
235 #define ASMPOSTCODE_LO(X)                       \
236         pushl   %eax ;                          \
237         movl    _current_postcode, %eax ;       \
238         andl    $0xf0, %eax ;                   \
239         orl     $X, %eax ;                      \
240         movl    %eax, _current_postcode ;       \
241         outb    %al, $POST_ADDR ;               \
242         popl    %eax
243
244 /*
245  * Overwrite the current_postcode high nibble.
246  */
247 #define ASMPOSTCODE_HI(X)                       \
248         pushl   %eax ;                          \
249         movl    _current_postcode, %eax ;       \
250         andl    $0x0f, %eax ;                   \
251         orl     $(X<<4), %eax ;                 \
252         movl    %eax, _current_postcode ;       \
253         outb    %al, $POST_ADDR ;               \
254         popl    %eax
255 #else
256 #define ASMPOSTCODE_INC
257 #define ASMPOSTCODE(X)
258 #define ASMPOSTCODE_LO(X)
259 #define ASMPOSTCODE_HI(X)
260 #endif /* POST_ADDR */
261
262
263 /*
264  * These are all temps for debugging...
265  *
266 #define GUARD_INTS
267  */
268
269 /*
270  * This macro traps unexpected INTs to a specific CPU, eg. GUARD_CPU.
271  */
272 #ifdef GUARD_INTS
273 #define GUARD_CPU       1
274 #define MAYBE_PANIC(irq_num)            \
275         cmpl    $GUARD_CPU, _cpuid ;    \
276         jne     9f ;                    \
277         cmpl    $1, _ok_test1 ;         \
278         jne     9f ;                    \
279         pushl   lapic_isr3 ;            \
280         pushl   lapic_isr2 ;            \
281         pushl   lapic_isr1 ;            \
282         pushl   lapic_isr0 ;            \
283         pushl   lapic_irr3 ;            \
284         pushl   lapic_irr2 ;            \
285         pushl   lapic_irr1 ;            \
286         pushl   lapic_irr0 ;            \
287         pushl   $irq_num ;              \
288         pushl   _cpuid ;                \
289         pushl   $panic_msg ;            \
290         call    _printf ;               \
291         addl    $44, %esp ;             \
292 9:
293 #else
294 #define MAYBE_PANIC(irq_num)
295 #endif /* GUARD_INTS */
296
297 #endif /* _MACHINE_SMPTESTS_H_ */