solo.tcl 9.22 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. 
#

#source "tcl_support.tcl"

for {set i 0} {$i < $PARAM(CPU.Count)} {incr i} {
    set locks($i) 0
    set lockRetries($i) 0
    set unlocks($i) 0
    set barriers($i) 0
    set barrStart($i) 0
    statistics create lockTime_$i
    statistics create unlockTime_$i
    statistics create barrTime_$i
}

# I have to add 4 since the code creates a LL then uses bnezl
set barEnd1 [expr [symbol read soloApp::_Barrier:START] + 76]
set barEnd2 [expr [symbol read soloApp::_Barrier:START] + 92]


## REGULAR ANL LOCKS

annotation set pre-pc [expr [symbol read soloApp::_LockEnter:START]] {
    # log "LockEnter $CPU $a0 START $CYCLES\n"
    if {![info exists lockStart($CPU,$a0)] || $lockStart($CPU,$a0) == 0} {
        incr locks($CPU)
        set lockStart($CPU,$a0) $CYCLES
    } else {
        incr lockRetries($CPU)
    }
    
    ## Lock profiling info
    set currentLock($CPU) $a0 
    if {[info exists lockWaiters($a0)]} {
        incr lockWaiters($a0)
    } else {
        set lockWaiters($a0) 1
    }
    log "Lock S $CPU $a0 $CYCLES\n"
}

annotation set pc [symbol read soloApp::_LockEnter:END] {
    # log "LockEnter $CPU $a2 END $CYCLES\n"
    if {[info exists lockStart($CPU,$a2)] && $lockStart($CPU,$a2) > 0} {
        set time [expr $CYCLES - $lockStart($CPU,$a2)]
        statistics entry lockTime_$CPU $time
    }

    ## Lock profiling info
    set temp $currentLock($CPU)
    log "Lock E $CPU $temp $CYCLES\n"
}

annotation set pre-pc soloApp::_Unlock:START {
    # log "Unlock $CPU $a0 START $CYCLES\n"
    if {$lockStart($CPU,$a0) != 0} {
        incr unlocks($CPU)
        set lockStart($CPU,$a0) 0
        
        set unlockStart($CPU,$a0) $CYCLES
    }

    ## Lock profiling info
    set currentLock($CPU) $a0         
    # All I do here is figure out what we're unlocking.  
}

annotation set pc soloApp::_Unlock:END {
    # log "Unlock $CPU $a0 END $CYCLES\n"
    if {[info exists unlockStart($CPU,$a0)] && $unlockStart($CPU,$a0) > 0} {
        set time [expr $CYCLES - $unlockStart($CPU,$a0)]
        statistics entry unlockTime_$CPU $time
    }

    ## Lock profiling info
    set lockWaiters($a0) [expr $lockWaiters($a0) - 1]
    log "Unlock $CPU $temp $CYCLES (W: $lockWaiters($a0))\n"
    if {$lockWaiters($a0) < 0} {
        log "ERROR! Lock count $lockWaiters($a0) for lock $a0!!\n";
    }
}


## FLASH LOCKS

#Uncomment for paranoid mode
if [
catch {
    annotation set pre-pc soloApp::FLASHLock:START {
        ## FL Stats stuff
        incr locks($CPU)
        set lockStart($CPU,$a0) $CYCLES
        #log "\n\nLockEnter $CPU $a0 START $CYCLES\n"

        ## Lock profiling info
        set currentLock($CPU) $a0 
        if {[info exists lockWaiters($a0)]} {
            incr lockWaiters($a0)
        } else {
            set lockWaiters($a0) 1
        }
        log "FLASHLock S $CPU $a0 $CYCLES\n"
    }
    
    annotation set pc soloApp::FLASHLock:END {
        set temp $currentLock($CPU)

        ## FL Stats stuff
        #log "\n\nLockEnter $CPU $temp END $CYCLES\n"
        if {[info exists lockStart($CPU,$temp)] && $lockStart($CPU,$temp) > 0} {
            set time [expr $CYCLES - $lockStart($CPU,$temp)]
            statistics entry lockTime_$CPU $time
        }

        ## Lock profiling info
        log "FLASHLock E $CPU $temp $CYCLES\n"
    }
    
    annotation set pre-pc soloApp::FLASHUnlock:START {
        ## FL Stats stuff
        #log "\n\nUnlock $CPU $a0 START $CYCLES\n"
        if {$lockStart($CPU,$a0) != 0} {
            incr unlocks($CPU)
            set lockStart($CPU,$a0) 0
            set unlockStart($CPU,$a0) $CYCLES
        }

        ## Lock profiling info
        set currentLock($CPU) $a0         
        # All I do here is figure out what we're unlocking.  
    }
    
    annotation set pc soloApp::FLASHUnlock:END {
        set temp $currentLock($CPU)

        ## FL Stats stuff
        # log "\n\nUnlock $CPU $temp END $CYCLES\n"
        if {[info exists unlockStart($CPU,$temp)] && $unlockStart($CPU,$temp) > 0} {
            set time [expr $CYCLES - $unlockStart($CPU,$temp)]
            statistics entry unlockTime_$CPU $time
        }

        ## Lock profiling info
        set lockWaiters($temp) [expr $lockWaiters($temp) - 1]
        log "FLASHUnlock $CPU $temp $CYCLES (W: $lockWaiters($temp))\n"
        if {$lockWaiters($temp) < 0} {
            log "ERROR! Lock count $lockWaiters($temp) for lock $temp!!\n";
        }
    }
} msg ] {
    console "*** NOTE: FLASH locks not annotated: $msg\n"
}


## MCS LOCKS

if [
catch {
    annotation set pre-pc soloApp::acquireMCSlock:START {
        ## FL Stats stuff
        incr locks($CPU)
        set lockStart($CPU,$a0) $CYCLES
        #log "\n\nLockEnter $CPU $a0 START $CYCLES\n"

        ## Lock profiling info
        set currentLock($CPU) $a0 
        if {[info exists lockWaiters($a0)]} {
            incr lockWaiters($a0)
        } else {
            set lockWaiters($a0) 1
        }
        log "MCSLock S $CPU $a0 $CYCLES\n"
    }
    
    annotation set pc soloApp::acquireMCSlock:END {
        set temp $currentLock($CPU)

        ## FL Stats stuff
        #log "\n\nLockEnter $CPU $temp END $CYCLES\n"
        if {[info exists lockStart($CPU,$temp)] && $lockStart($CPU,$temp) > 0} {
            set time [expr $CYCLES - $lockStart($CPU,$temp)]
            statistics entry lockTime_$CPU $time
        }

        ## Lock profiling info
        log "MCSLock E $CPU $temp $CYCLES\n"
    }
    
    annotation set pre-pc soloApp::releaseMCSlock:START {
        ## FL Stats stuff
        #log "\n\nUnlock $CPU $a0 START $CYCLES\n"
        if {$lockStart($CPU,$a0) != 0} {
            incr unlocks($CPU)
            set lockStart($CPU,$a0) 0
            set unlockStart($CPU,$a0) $CYCLES
        }

        ## Lock profiling info
        set currentLock($CPU) $a0         
        # All I do here is figure out what we're unlocking.  
    }
    
    annotation set pc soloApp::releaseMCSlock:END {
        set temp $currentLock($CPU)

        ## FL Stats stuff
        # log "\n\nUnlock $CPU $temp END $CYCLES\n"
        if {[info exists unlockStart($CPU,$temp)] && $unlockStart($CPU,$temp) > 0} {
            set time [expr $CYCLES - $unlockStart($CPU,$temp)]
            statistics entry unlockTime_$CPU $time
        }

        ## Lock profiling info
        set lockWaiters($temp) [expr $lockWaiters($temp) - 1]
        log "MCSUnlock $CPU $temp $CYCLES (W: $lockWaiters($temp))\n"
        if {$lockWaiters($temp) < 0} {
            log "ERROR! Lock count $lockWaiters($temp) for lock $temp!!\n";
        }
    }
} msg ] {
    console "*** NOTE: MCS locks not annotated: $msg\n"
}



annotation set pre-pc soloApp::_Barrier:START {
    incr barriers($CPU)
    set barrStart($CPU) $CYCLES
}

## Heinrich's Tree Barriers

#Uncomment for paranoid mode
if [
catch {
    annotation set pre-pc soloApp::TreeBarrier:START {
        console "Enter TreeBarrier on CPU $CPU at cycle $CYCLES\n"
        incr barriers($CPU)
        set barrStart($CPU) $CYCLES
    }
    
    annotation set pc soloApp::TreeBarrier:END {
        if {$barrStart($CPU) > 0} {
            console "Exit TreeBarrier on CPU $CPU at cycle $CYCLES\n"
            set time [expr $CYCLES - $barrStart($CPU)]
            statistics entry barrTime_$CPU $time
            set barrStart($CPU) 0
        }
    }
} msg ] {
    console "*** NOTE: Tree barriers not annotated: $msg\n"
}


## FLASH Barriers

#Uncomment for paranoid mode
if [
catch {
    annotation set pre-pc soloApp::FLASHBarrier:START {
        console "Enter FLASHBarrier on CPU $CPU at cycle $CYCLES\n"
        incr barriers($CPU)
        set barrStart($CPU) $CYCLES
    }
    
    annotation set pc soloApp::FLASHBarrier:END {
        if {$barrStart($CPU) > 0} {
            set time [expr $CYCLES - $barrStart($CPU)]
            console "Exit FLASHBarrier on CPU $CPU at cycle $CYCLES (time: $time)\n"
            statistics entry barrTime_$CPU $time
            set barrStart($CPU) 0
        }
    }
} msg ] {
    console "*** NOTE: FLASH Barriers not annotated: $msg\n"
}


annotation set pre-pc $barEnd1 {
    if {$barrStart($CPU) > 0} {
        set time [expr $CYCLES - $barrStart($CPU)]
        statistics entry barrTime_$CPU $time
        set barrStart($CPU) 0
    }
}

annotation set pre-pc $barEnd2 {
    if {$barrStart($CPU) > 0} {
        set time [expr $CYCLES - $barrStart($CPU)]
        statistics entry barrTime_$CPU $time
        set barrStart($CPU) 0
    }
}

annotation type solo enum { resetStats }

annotation set solo resetStats {
    for {set i 0} {$i < $PARAM(CPU.Count)} {incr i} {
        set locks($i) 0
        set lockRetries($i) 0
        set unlocks($i) 0
        set barriers($i) 0
#        set barrStart($i) 0
        statistics reset lockTime_$i
        statistics reset unlockTime_$i
        statistics reset barrTime_$i
    }
#    unset lockStart
#    unset unlockStart
}

annotation set simos exit {
    for {set i 0} {$i < $PARAM(CPU.Count)} {incr i} {
        log "C$i locks $locks($i) retries $lockRetries($i) unlocks $unlocks($i) barriers $barriers($i)\n"
        log "C$i lock [statistics list lockTime_$i]\n"
        log "C$i unlock [statistics list unlockTime_$i]\n"
        log "C$i barrier [statistics list barrTime_$i]\n"

    }
}