sema_stats.tcl 2.81 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. 
#

#### 
#### sema_stats.tcl
####


##
## module init
##

proc semaStatsDump {} {
    global ssSema semaRa semaFree

    log "SEMASTATS: start\n"
    foreach sema [array names semaRa] {
        set ra [symbol find kernel [lindex $semaRa($sema) 1]]
        log "SEMAINIT: $sema $semaRa($sema) $ra\n"
    }

    foreach sema [array names semaFree] {
        set ra [symbol find kernel $semaFree($sema)]
        log "SEMAFREE: $sema $semaFree($sema) $ra\n"
    }

    foreach sema [array names ssSema] {
        set l [symbol find kernel $sema]
        if [string match "end+*" $l] {
            set l $sema
        }
        log "SEMASTATS: sema $l "
        log "[statistics list ssSemaWait($sema)]\n"
    }
    log "SEMASTATS: end\n"
}

annotation set simos exit {
    semaStatsDump
}

annotation set simos sigusr {
    semaStatsDump
}


##
## helper routines
##

proc semaStatsWait {sema proc} {
    global CPU CYCLES ssSemaStart ssSema

    set ssSemaStart($sema,$proc) $CYCLES

    if ![info exists "ssSema($sema)"] {
        set "ssSema($sema)" 1
        statistics create ssSemaWait($sema)
    }
}

proc semaStatsAcquire {sema proc} {
    global CPU CYCLES ssSemaStart

    if [info exists ssSemaStart($sema,$proc)] {
        statistics entry ssSemaWait($sema) [expr $CYCLES-$ssSemaStart($sema,$proc)]
        set ssSemaStart($sema,$proc) 0
    }
}



##
## the annotations
##

annotation set pc kernel:sema.c:semaaddproc:START {
    semaStatsWait $a0 $a1
}


annotation set pc kernel:sema.c:semarmproc:START {
    if {([info exists ssSemaStart($a0,$a1)]) && ($ssSemaStart($a0,$a1) != 0) } {
        semaStatsAcquire $a0 $a1
    }
}

annotation set pc kernel:sema.c:semadq:START {
    set semaDq($CPU) $a0
}

annotation set pc kernel:sema.c:semadq:END {
    semaStatsAcquire [hex $semaDq($CPU)] $v0
}


# tracking inits of semaphores

annotation set pc kernel::initsema:START {
    if {![info exists semaRa($a0)]} {
        set semaRa($a0) "I $ra none"
    }
}

annotation set pc kernel::initnsema_lifo:START {
    if {![info exists semaRa($a0)]} {
        set semaRa($a0) "L $ra [symbol read ::((char*)$a2)]"
    }
}

annotation set pc kernel::initsema_mutex:START {
    if {![info exists semaRa($a0)]} {
        set semaRa($a0) "M $ra none"
    }
}

annotation set pc kernel::initnsema_mutex:START {
    if {![info exists semaRa($a0)]} {
        set semaRa($a0) "MN $ra [symbol read ::((char*)$a1)]"
    }
}

annotation set pc kernel::initnsema:START {
    if {![info exists semaRa($a0)]} {
        set semaRa($a0) "N $ra [symbol read ::((char*)$a2)]"
    }
}

annotation set pc kernel::freesema:START {
    if {![info exists semaFree($a0)]} {
        set semaFree($a0) $ra
    }
}