sync_stats.tcl 3.36 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. 
#

#### 
#### sync_stats.tcl
####


##
## module init
##

proc syncStatsDump {} {
    global ssLock

    log "SYNCSTATS: start\n"
    foreach lock [array names ssLock] {
        set l [symbol find kernel [lindex $lock 0]]
        set r [symbol find kernel [lindex $lock 1]]
        if [string match "end+*" $l] {
            set l [lindex $lock 0]
        }
        log "SYNCSTATS: lock $l,$r "
        log "[statistics list ssLockWait([lindex $lock 0],[lindex $lock 1])] "
        log "[statistics list ssLockHeld([lindex $lock 0],[lindex $lock 1])]\n"
    }
    log "SYNCSTATS: end\n"
}

annotation set simos exit {
    syncStatsDump
}

annotation set simos sigusr {
    syncStatsDump
}


##
## helper routines
##

proc syncStatsWait {lock} {
    global CPU CYCLES ra ssLockStart ssLock

    set lock [hex [expr $lock & 0xfffffffc]]
    set ssLockStart($lock,$CPU) $CYCLES

    if ![info exists "ssLock($lock $ra)"] {
        set "ssLock($lock $ra)" 1
        statistics create ssLockWait($lock,$ra)
        statistics create ssLockHeld($lock,$ra)
    }
}

proc syncStatsFailed {lock} {
    global CPU CYCLES ra ssLockStart
    set lock [hex [expr $lock & 0xfffffffc]]
    if [info exists ssLockStart($lock,$CPU)] {
        statistics entry ssLockWait($lock,$ra) [expr $CYCLES-$ssLockStart($lock,$CPU)]
    }
}

proc syncStatsAcquire {lock} {
    global CPU CYCLES ra ssLockStart ssLockRA
    set lock [hex [expr $lock & 0xfffffffc]]
    if [info exists ssLockStart($lock,$CPU)] {
        statistics entry ssLockWait($lock,$ra) [expr $CYCLES-$ssLockStart($lock,$CPU)]
        set ssLockStart($lock,$CPU) $CYCLES
        set ssLockRA($lock,$CPU) $ra
    }
}

proc syncStatsRealease {lock} {
    global CPU CYCLES ssLockStart ssLockRA
    set lock [hex [expr $lock & 0xfffffffc]]
    if [info exists ssLockRA($lock,$CPU)] {
        set ra $ssLockRA($lock,$CPU)
        statistics entry ssLockHeld($lock,$ra) [expr $CYCLES-$ssLockStart($lock,$CPU)]
    }
}


##
## the annotations
##

annotation set pre-pc kernel::io_splock:START {
    syncStatsWait $a0
}

if [catch {symbol read kernel::io_splock:ann_splock_gotit}] {
    annotation set pc kernel::io_splock:END {
        syncStatsAcquire $a0
    }
} else {
    annotation set pc kernel::io_splock:ann_splock_gotit {
        syncStatsAcquire $a0
    }
}

annotation set pre-pc kernel::spsemahi:START {
    syncStatsWait $a0
}

annotation set pc kernel::spsemahi:ann_spsemahi_gotit {
    syncStatsAcquire $a0
}

annotation set pc kernel::io_splockspl:START {
    syncStatsWait $a0
}

annotation set pre-pc kernel::io_splockspl:ann_splockspl_gotit {
    syncStatsAcquire $s0
}

annotation set pc kernel::spsema:START {
    syncStatsWait $a0
}

annotation set pc kernel::spsema:END {
    syncStatsAcquire $a0
}

annotation set pc kernel::_trylock:START {
    console "Bogus _trylock\n"
    syncStatsWait $a0
}

annotation set pc kernel::_trylock:ann_trylock_gotit {
    if {$v0 == 0} {
        syncStatsFailed $a0
    } else {
        syncStatsAcquire $a0
    }
}

annotation set pre-pc kernel::io_spunlockspl:START {
    syncStatsRealease $a0
}

annotation set pre-pc kernel::svsema:START {
    syncStatsRealease $a0
}

annotation set pre-pc kernel::svsemax:START {
    syncStatsRealease $a0
}