cachetrace.tcl 3.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. 
#

###
### cache_trace.tcl
###
###
### Cache_trace routines (First cut will change in the future)
### Set the variable cacheTraceFileName before sourcing the file
### if you want a name other than the default ./cachetrace
###
### Cache trace format
###
### | 32 bit physical address |
### | 20 bit virtual address  | 1 bit kernel/user | 2 bit type of cache miss | 9 lower bits of pid |
### Note!!! currently the user/kernel mode and pid are correct only for the uniprocessor case
###
###

set cachetracePageMask 0xfffff000
set cachetracePidMask  0x000001ff
set cachetraceImiss    0x000
set cachetraceRmiss    0x200
set cachetraceWmiss    0x400
set cachetraceUmiss    0x600
set cachetraceIsKernel 0x800
set cachetraceTick     0xffffffff

if {![info exists cacheTraceFileName]} {
    set cacheTraceFileName ./cachetrace
}
set cachetraceFd [binary open $cacheTraceFileName "w"]

annotation set scache instr -tag cachetrace {
    if {($PROCESS($ScacheCPU) == "idle") || ($PROCESS($ScacheCPU) == "runq")} {
        set tmpPid 0
    } else {
        set tmpPid $PID($ScacheCPU)
    }
    set cachetraceVaddr [expr ($ScacheVaddr & $cachetracePageMask) | ($tmpPid & $cachetracePidMask) | $cachetraceImiss]
    if {![inUserMode]} {
        set cachetraceVaddr [expr $cachetraceVaddr | $cachetraceIsKernel]
    }
    binary write $cachetraceFd $ScachePaddr $cachetraceVaddr
}

annotation set scache read -tag cachetrace {
    if {($PROCESS($ScacheCPU) == "idle") || ($PROCESS($ScacheCPU) == "runq")} {
        set tmpPid 0
    } else {
        set tmpPid $PID($ScacheCPU)
    }
    set cachetraceVaddr [expr ($ScacheVaddr & $cachetracePageMask) | ($tmpPid & $cachetracePidMask) | $cachetraceRmiss]
    if {![inUserMode]} {
        set cachetraceVaddr [expr $cachetraceVaddr | $cachetraceIsKernel]
    }
    binary write $cachetraceFd $ScachePaddr $cachetraceVaddr
}

annotation set scache write -tag cachetrace {
    if {($PROCESS($ScacheCPU) == "idle") || ($PROCESS($ScacheCPU) == "runq")} {
        set tmpPid 0
    } else {
        set tmpPid $PID($ScacheCPU)
    }
    set cachetraceVaddr [expr ($ScacheVaddr & $cachetracePageMask) | ($tmpPid & $cachetracePidMask) | $cachetraceWmiss]
    if {![inUserMode]} {
        set cachetraceVaddr [expr $cachetraceVaddr | $cachetraceIsKernel]
    }
    binary write $cachetraceFd $ScachePaddr $cachetraceVaddr
}

annotation set scache upg -tag cachetrace {
    if {($PROCESS($ScacheCPU) == "idle") || ($PROCESS($ScacheCPU) == "runq")} {
        set tmpPid 0
    } else {
        set tmpPid $PID($ScacheCPU)
    }
    set cachetraceVaddr [expr ($ScacheVaddr & $cachetracePageMask) | ($tmpPid & $cachetracePidMask) | $cachetraceUmiss]
    if {![inUserMode]} {
        set cachetraceVaddr [expr $cachetraceVaddr | $cachetraceIsKernel]
    }
    binary write $cachetraceFd $ScachePaddr $cachetraceVaddr
}

annotation set scache sc_upg -tag cachetrace {
    if {($PROCESS($ScacheCPU) == "idle") || ($PROCESS($ScacheCPU) == "runq")} {
        set tmpPid 0
    } else {
        set tmpPid $PID($ScacheCPU)
    }
    set cachetraceVaddr [expr ($ScacheVaddr & $cachetracePageMask) | ($tmpPid & $cachetracePidMask) | $cachetraceUmiss]
    if {![inUserMode]} {
        set cachetraceVaddr [expr $cachetraceVaddr | $cachetraceIsKernel]
    }
    binary write $cachetraceFd $ScachePaddr $cachetraceVaddr
}

annotation set pc [symbol read kernel::clock:START] -tag cachetrace {
    if {$ScacheCPU == 0} {
        binary write $cachetraceFd $cachetraceTick $cachetraceTick
    }
}

annotation set simos exit -tag cachetrace {
    binary close $cachetraceFd
}