modes.tcl 3.13 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. 
#

###
### modes.tcl
###

FileSourced modes.tcl


if ![info exists modesByPID] {
    set modesByPID 0
}


timing create modes
log [timing fields]

proc modesSwitch args {
    global PROCESS PID CPU CELL M RUNNING_HIVE PARAM
    global modesByPID
    if $modesByPID {
        set args [linsert $args 0 PID$PID($CPU)]
    }

    if [info exists RUNNING_HIVE] {
        eval timing switch modes ${CELL}_$PID($CPU) cell$CELL $args
    } elseif { $PARAM(MACHINE.Count) == 1 } {
        eval timing switch modes $PID($CPU) $args
    } else {
        eval timing switch modes $M($CPU)_$PID($CPU) machine$M($CPU) $args
    }
}

###
### Initialization based on current state
###

annotation set simos enter {
    if [inUserMode] {
        modesSwitch
    } elseif {$PROCESS($CPU) == "idle"} {
        modesSwitch kernel idle
    } elseif {($SIMOS(ISA)=="ALPHA") && ($pc & 1)} {
        modesSwitch kernel pal
    } else {
        modesSwitch kernel
    }
}


###
### The Annotations
###

if {$SIMOS(ISA)=="ALPHA"} { 
    annotation set osEvent switchIn {
        modesSwitch kernel kernel
    }
} else { 
    annotation set osEvent switchIn {
        modesSwitch kernel
    }
}


annotation set osEvent procexit {
    if [info exists RUNNING_HIVE] {
        timing terminate modes ${CELL}_$PID($CPU)
    } elseif { $PARAM(MACHINE.Count) == 1 } {
        timing terminate modes $PID($CPU)
    } else {
        timing terminate modes $M($CPU)_$PID($CPU)
    }
}

proc foobar { msg } {
    global CYCLES pc
    if {$CYCLES > 6152856} { 
        log "Modes $CYCLES pc= [format %-20s $pc] top=[timing current modes] action $msg\n"
    }
}



annotation set osEvent startKernel {
    #foobar "startKernel"
    timing start modes kernel
}

annotation set osEvent endKernel {
    #foobar "endKernel"
    timing end modes kernel
}

if {$SIMOS(ISA)=="ALPHA"} { 
    annotation set osEvent startPal {
        #foobar startPal
        timing start modes pal
    }
    
    annotation set osEvent endPal {
        timing end modes pal
        #foobar endPal
        set cur [timing current modes]
        # poped too far
        if {$cur=="ROOT" && ![inUserMode]} {
            #console "endPal cur=$cur exc=$IPR(0x10b) inUserMode=[inUserMode] \n"
            timing start modes kernel
        }


        
    }
}

annotation set osEvent startIdle {
    #foobar "startIdle"
    if { [timing current modes] != "idle"} {
	timing start modes idle
    }
}

annotation set osEvent endIdle {
    #foobar "endIdle"
    timing end modes idle
}

annotation set osEvent startSync {
    timing start modes sync
}

annotation set osEvent endSync {
    timing end modes sync
}

if [info exists RUNNING_HIVE] {
    annotation set osEvent startRpc {
        timing start modes rpcwait
    }

    annotation set osEvent endRpc {
        timing end modes rpcwait
    }
}

###
### Need to dump to stats 
###

annotation set simos periodic {
    log [timing dump modes]
}

annotation set simos exit {
    timing exit modes
    log [timing dump modes]
}