proc_exit.tcl 1.68 KB
#
# 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
    }
}