fault.tcl
8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#
# Copyright (C) 1996-1998 by the Board of Trustees
# of Leland Stanford Junior University.
#
# This file is part of the SimOS distribution.
# See LICENSE file for terms of the license.
#
random seed
##
## returns a random kseg0 address. if an optional node number is supplied
## restricts the address to be on that node
##
proc RandomKSeg0Addr {{node -1}} {
global PARAM numCells K0BASE
set highMem [expr $PARAM(MEMSYS.MemSize) << 20]
if {$node != -1} {
set memPerNode [expr $highMem / $numCells]
set addr [expr [random $memPerNode] + ($memPerNode * $node) + $K0BASE]
} else {
set addr [expr [random $highMem] + $K0BASE]
}
hex [expr $addr & 0xfffffffc]
}
###
### these anns needed for the hivePostPmake script
###
proc NewProc {} {
global CPU CYCLES CELL K0BASE u
set procp "(*(struct proc*)[symbol read kernel:user.h:$u.u_procp])"
log "PROCESS cell=$CELL "
log "pid=[symbol read kernel:timer.c:$procp.p_pid] "
log "name=[symbol read kernel:user.h:$u.u_comm] "
log "cycle=$CYCLES \n"
}
##
## recovery timing
##
annotation set pc kernel::hive_LSET:lset_started {
log "RECOVERY lsetStart cycle=$CYCLES cpu=$CPU\n"
}
annotation set pc kernel::hive_LSET:lset_finished {
log "RECOVERY lsetFinish cycle=$CYCLES cpu=$CPU\n"
}
annotation set pc kernel::hive_RECV:recovery_started {
log "RECOVERY recoveryStart cycle=$CYCLES cpu=$CPU\n"
}
annotation set pc kernel::hive_RECV:recovery_finished {
log "RECOVERY recoveryFinish cycle=$CYCLES cpu=$CPU\n"
}
##
## remote fork
##
annotation set pc kernel:fork.c:procfork_remote:START {
log "REMFORK start cycle=$CYCLES cpu=$CPU to=$a0\n"
}
annotation set pc kernel:fork.c:procfork_remote:END {
log "REMFORK finish cycle=$CYCLES cpu=$CPU\n"
}
##
## pid tracking
##
annotation set pc kernel::exece:END {
NewProc
}
##
## graceful exit
##
annotation set pc kernel::Simos_idlenap {
console "going into idlenap... exiting\n"
exit
}
##
## firewall stats - % data pages unprotected
##
annotation set simos periodic {
for {set cell 0} {$cell < $numCells} {incr cell} {
log "FREEMEM cycle=$CYCLES cell=$cell [symbol read kernel$cell::freemem]\n"
}
}
###
### fault support
###
### globals used:
### faultCPU
### faultType
### faulrArg
### faultWith
### faultTime
### faultEnd
###
set currentDieSet 0
annotation set pc kernel::SimosGetDieSet:END {
set v0 $currentDieSet
}
proc haltFault {start end {cpu -1}} {
global faultCPU
if {$cpu == -1} {
set faultCPU [expr [random 3] + 1]
} else {
set faultCPU $cpu
}
if {$end} {
set time [expr [random [expr $end - $start]] + $start]
} else {
set time $start
}
console "fault set cycles $time cell $faultCPU halt\n"
annotation set cycle $time {
log "FAULT: halting cell $faultCPU cycles $CYCLES\n"
fault cpu $faultCPU halt
set currentDieSet [expr $currentDieSet | (1 << $faultCPU)]
}
annotation set cycle 2000000000 {
console "ERROR: I hit 2 billion cycles. bye bye...\n"
exit
}
}
##
## with: number, "plus4", or "addr"
## type: "preg", "pmap", "pfdHash", "runq", "upage"
##
proc setSmash {type arg cell with start {end 0}} {
global faultCPU faultType faultArg faultWith
if {$end} {
set time [expr [random [expr $end - $start]] + $start]
} else {
set time $start
}
console "fault set faultype $type cycles $time cell $cell smash $type arg $arg with $with\n"
set faultCPU $cell
set faultType $type
set faultArg $arg
set faultWith $with
annotation set cycle $time {
set addr [GET$faultType $faultArg kernel$faultCPU]
if {!$addr} {
console "ERROR: couldn't get smash addr\n"
return
}
if {$faultWith == "plus4"} {
set MEMORY($addr) [expr $MEMORY($addr) + 4]
} elseif {$faultWith == "addr"} {
set MEMORY($addr) $addr
} else {
set MEMORY($addr) $faultWith
}
set av [hex $addr]
set hv [hex $MEMORY($addr)]
log "FAULT: smashing cell $faultCPU cycles $CYCLES type $faultWith ($av := $hv)\n"
if {0} {
# skip this -- OS should now correctly reboot failed cell
set currentDieSet [expr $currentDieSet | (1 << $faultCPU)]
}
}
annotation set cycle 2000000000 {
console "ERROR: I hit 2 billion cycles. bye bye...\n"
exit
}
}
##
## return the address of the processes (given by pid) pregion pointer
##
proc GETpreg {pid kernel} {
set procp [symbol read $kernel::proc]
set nump [symbol read $kernel::v.v_proc]
for {set i 0} {$i < $nump} {incr i} {
if {[symbol read $kernel:proc.h:((proc_t*)$procp)<$i>.p_pid] == $pid} {
return [symbol read $kernel:proc.h:&((proc_t*)$procp)<$i>.p_region]
}
}
return 0
}
##
## return the address of the processes (given by pid) heap segment pointer
##
proc GETpmap {pid kernel} {
set procp [symbol read $kernel::proc]
set nump [symbol read $kernel::v.v_proc]
for {set i 0} {$i < $nump} {incr i} {
if {[symbol read $kernel:proc.h:((proc_t*)$procp)<$i>.p_pid] == $pid} {
set pmap [symbol read $kernel:proc.h:((proc_t*)$procp)<$i>.p_pmap]
return [symbol read $kernel:pmap.c:&((pseg_t*)$pmap)->pseg_segptr<64>]
}
}
return 0
}
##
## return the address of the head of the page hash table
##
proc GETpfdHash {arg kernel} {
return [symbol read $kernel::&phash]
}
##
## return the address of the head of the global affinity runq
##
proc GETrunq {arg kernel} {
set qdp [symbol read $kernel:runq.c:Runq._qlist]
while {[symbol read $kernel:runq_private.h:((QueueDesc*)$qdp)->_type] != 2} {
set qdp [symbol read $kernel:runq_private.h:((QueueDesc*)$qdp)->_link]
}
# I must smash some stuf to make sure it looks down this queue
symbol set $kernel:runq_private.h:((QueueDesc*)$qdp)->_globalq._nq 100
symbol set $kernel:runq_private.h:((QueueDesc*)$qdp)->_globalq._highest_pri 0
return [symbol read $kernel:runq_private.h:&((QueueDesc*)$qdp)->_globalq._arunq]
}
##
## return the address of the processes (given by pid) fileid 3's vnode ptr
##
proc GETupage {pid kernel} {
global MEMORY
set procp [symbol read $kernel::proc]
set nump [symbol read $kernel::v.v_proc]
for {set i 0} {$i < $nump} {incr i} {
if {[symbol read $kernel:proc.h:((proc_t*)$procp)<$i>.p_pid] == $pid} {
return [symbol read $kernel:proc.h:&((proc_t*)$procp)<$i>.p_upgs<0>]
}
}
return 0
}
##
## Must do something different for kernel malloc smash
##
## smash v0 on the first kmem_zone_alloc after random time
##
## with: "minus8" or val
##
proc setKmemAllocSmash {cell with start {end 0}} {
global faultCPU faultWith faultTime faultEnd
if {$end} {
set time [expr [random [expr $end - $start]] + $start]
} else {
set time $start
}
console "fault set cycles $time cell $cell smash kernFree with $with\n"
set faultCPU $cell
set faultWith $with
set faultTime $time
set faultEnd $end
annotation set pc kernel$cell::kmem_zone_alloc:END -tag smashit {
if {$CYCLES > $faultTime} {
if {$faultEnd && ($CYCLES > $faultEnd)} {
console "SMASH ERROR: missed smash time $faultEnd now $CYCLES\n"
exit
}
if {$faultWith == "minus8"} {
set REGISTER(v0) [expr $REGISTER(v0) - 8]
} else {
set REGISTER(v0) $faultWith
}
set hv [hex $REGISTER(v0)]
console "FAULT: smashing cell $faultCPU cycles $CYCLES kmem_register ($hv)\n"
annotation disable smashit
if {0} {
set currentDieSet [expr $currentDieSet | (1 << $faultCPU)]
}
}
}
annotation set cycle 2000000000 {
console "ERROR: I hit 2 billion cycles. bye bye...\n"
simosExit
}
}