proc_exit.tcl
1.68 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
#
# 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.
#
#
# proc_exit.tcl
#
# Exit a user level process gracefully (via exit()) when it reaches
# a set number of instructions of execution.
#
# $Author: blythe $
# $Date: 2002/05/29 01:09:09 $
set MAX_CPUS 256
for {set i 0} {$i < $MAX_CPUS} {incr i} {
set procExitInsts($i) 0
}
proc procExit {proc numInsts} {
global procExitRemaining
set procExitRemaining($proc) $numInsts
console "PROCEXIT: $proc set for $numInsts instructions\n"
}
annotation set osEvent switchIn {
if {[info exists procExitRemaining($PROCESS($CPU))]
&& ![info exists procExitRemaining($PID($CPU))]} {
console "PROCEXIT: pid $PID($CPU) is a $PROCESS($CPU)\n"
set procExitRemaining($PID($CPU)) $procExitRemaining($PROCESS($CPU))
}
}
annotation set osEvent startUser {
if [info exists procExitRemaining($PID($CPU))] {
set procExitInsts($CPU) $INSTS
if {$procExitRemaining($PID($CPU)) <= 0} {
set slack [expr -1 * $procExitRemaining($PID($CPU))]
exitUserProc $CPU
console "PROCEXIT: Exiting $PID($CPU): slack = $slack instructions\n"
}
}
}
annotation set osEvent endUser {
if [info exists procExitRemaining($PID($CPU))] {
incr procExitRemaining($PID($CPU)) [expr -1 * ($INSTS - $procExitInsts($CPU))]
}
}
set per 0
annotation set simos periodic {
incr per
if {$per == 5} {
foreach p [array names procExitRemaining] {
log "PROCEXIT: $p $procExitRemaining($p)\n"
}
set per 0
}
}