simos-lib.prl 7.48 KB
#!/usr/local/bin/perl5 -w
#
# 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. 
#


$CYCLESAMPLE = 256;
$INSTRSAMPLE = 256;

$format{'seconds'} = $format{'avgUTlb'} = "%6.2f";

@field_pct = ('dMR', 'iMR', 'dL1MR', 'dL2MR', 'iL1MR', 'iL2MR', 
	      'dTlbMR', 'iTlbMR');
foreach $aa (@field_pct) {
    $format{$aa} = "%6.5f";
}

@field_steppct = ('UserPct', 'KernelPct', 'UTlbPct','KernelIPct', 'UTlbIPct');
foreach $aa (@field_steppct) {
    $format{$aa} = "%6.4f";
}
 
foreach $aa ('lat-l1','lat-upg','lat-clean','lat-dirty') { 
    $format{$aa} = "%6.1f";
}

@field_time = ('CPU','L1D','L2D','Upg','L1I','L2I');
foreach $aa (@field_time) {
    $format{"time-$aa"} = "%6.3f";
}

foreach $aa ('dMCPI','iMCPI','dL2MCPI','dL1MCPI','dUpgMCPI',
             'dMCPI-cold','dMCPI-true','dMCPI-false','dMCPI-repl','dMCPI-other') {
    $format{$aa} = "%6.3f";
}


@derivedFields = ('_cycles','_instr',
                  'dL1Stall','iL1Stall',
                  'dL1MR','dL2MR','iL1MR','iL1MR',
                  'dTlbMR','iTlbMR',
                  'iMCPI','dMCPI',
                  'dL2MCPI','dL1MCPI','dUpgMCPI',
                  'dMCPI-true','dMCPI-false','dMCPI-repl','dMCPI-other','dMCPI-cold',
                  'memStall','dPrefMCPI');

sub ComputeDerivedFields {
    my $f = shift;
    my $time;
    
    if ($f->{'cycleSample'} > 0) {
        $f->{'_cycles'} = $f->{'cycleSample'} * $CYCLESAMPLE;
        $f->{'_instr'}  = $f->{'instrSample'} * $INSTRSAMPLE;

    } elsif (defined($f->{'instrCount'})) {
        # Embra stuff
        $f->{'_instr'} = $f->{'instrCount'};
        $f->{'dStall'} = $f->{'dL2Stall'} + $f->{'dUpgradeStall'};
        $f->{'iStall'} = $f->{'iL2Stall'};
        $f->{'_cycles'} = $f->{'instrCount'} + 
            $f->{'dStall'} + $f->{'iStall'};
    }

    $f->{'dL1Stall'} = $f->{'dStall'} - 
        $f->{'dL2Stall'} - $f->{'dUpgradeStall'};
    $f->{'iL1Stall'} = $f->{'iStall'} - $f->{'iL2Stall'};
    
    $f->{'memStall'} = $f->{'dStall'} + $f->{'iStall'};
    if (defined($f->{'dStallPrefetch'})) { 
        $f->{'memStall'} += $f->{'dStallPrefetch'};
    }
    
    # Handle cold misses etc
    if (defined($f->{'read.ice'})) {
	$f->{'cold'} = $f->{'read.ice'} + $f->{'read.cold'} +
	    $f->{'write.ice'} + $f->{'write.cold'};
    }
    
    $time =  $f->{'_cycles'};
    
    # Ensure we don't get any divide by 0 fatal errors
    # Check whether this is necessary before committing!
    if ($time != 0) {
	$f->{'time-CPU'} = 100 * $f->{'_instr'} / $time;
	$f->{'time-L1D'} = 100 * $f->{'dL1Stall'} / $time;
	$f->{'time-L2D'} = 100 * $f->{'dL2Stall'} / $time;
	$f->{'time-Upg'} = 100 * $f->{'dUpgradeStall'} / $time;
	$f->{'time-L1I'} = 100 * $f->{'iL1Stall'} / $time;
	$f->{'time-L2I'} = 100 * $f->{'iL2Stall'} / $time;
	$f->{'seconds'} = $f->{'_cycles'} / $config{'Clock'} / 1000 / 1000;
    } else {
	# Initialize everything to -1.0 (per Ed's convention)
	$f->{'time-CPU'} = $f->{'time-L1D'} =  
	    $f->{'time-L2D'} = $f->{'time-Upg'} = 
		$f->{'time-L1I'} = $f->{'time-L2I'} = -1.0;
	$f->{'seconds'} = -1.0;
    }
	
    # Now calculate D1/D2/I1/I2 miss rates etc
    $instrCount = $f->{'_instr'};
    if ($instrCount != 0) {
	$f->{'dL1MR'} = 100.0*$f->{'dL1Miss'}/$instrCount;
	$f->{'dL2MR'} = 100.0*$f->{'dL2Miss'}/$instrCount;
	$f->{'iL1MR'} = 100.0*$f->{'iL1Miss'}/$instrCount;
	$f->{'iL2MR'} = 100.0*$f->{'iL2Miss'}/$instrCount;

	$f->{'dTlbMR'} = 100.0*$f->{'dTlb'}/$instrCount;
	$f->{'iTlbMR'} = 100.0*$f->{'iTlb'}/$instrCount;

	# TODO - the upgrade numbers
        $f->{'dMCPI'}   = $f->{'dStall'} / $instrCount;
        $f->{'iMCPI'}   = $f->{'iStall'} / $instrCount;
        $f->{'dL2MCPI'} = $f->{'dL2Stall'} / $instrCount;
        $f->{'dL1MCPI'} = $f->{'dL1Stall'} / $instrCount;
        $f->{'dUpgMCPI'} = $f->{'dUpgradeStall'} / $instrCount;
        if (defined($f->{'dStallPrefetch'})) {
            $f->{'dPrefMCPI'} = $f->{'dStallPrefetch'}  / $instrCount;
        }
        
    } else {        
        $f->{'dL1MR'} = $f->{'dL2MR'} = $f->{'iL1MR'} = 
	    $f->{'iL2MR'} = $f->{'dMR'} = $f->{'iMR'} = 
		$f->{'dTlbMR'} = $f->{'iTlbMR'} = -1.0;
        $f->{'dMCPI'} =   $f->{'iMCPI'} =  $f->{'dL2MCPI'} =  
            $f->{'dL1MCPI'} =   $f->{'dUpgMCPI'} = -1;
    }
    

    # Cache miss classification 
    if (defined($f->{'trueSharing.ice'})) {
        $f->{'missclass-true'} = 
            ($f->{'trueSharing.inv'}+
             $f->{'trueSharing.capinv'}+
             $f->{'trueSharing.cap'}+
             $f->{'trueSharing.cold'});
        $f->{'missclass-cold'} = 
            ($f->{'falseSharing.ice'}+
             $f->{'falseSharing.cold'});
        $f->{'missclass-repl'} = 
            ($f->{'falseSharing.cap'});
        $f->{'missclass-false'} = 
            ($f->{'falseSharing.inv'}+
             $f->{'falseSharing.capinv'});
        $f->{'missclass-other'} =  $f->{'dL2Miss'} - 
            ($f->{'missclass-true'}+
             $f->{'missclass-cold'}+
             $f->{'missclass-repl'}+
             $f->{'missclass-false'});
     
        if (defined($f->{'prefetchNoMiss'}  )) { 
            $f->{'missclass-other'} += $f->{'prefetchNoMiss'};
        }

        foreach $i ('cold','true','false','repl','other') {
            if ($f->{'dL2Miss'} > 0 ) { 
                $f->{"missrate-$i"} = $f->{"missclass-$i"} *
                    $f->{"dL2MR"} /  $f->{"dL2Miss"};
            } else {
                $f->{"missrate-$i"} = -1;
            }
            
        }
        
        if ($instrCount > 0 ) { 
            $f->{'dMCPI-true'} = 
                ($f->{'trueShStall.inv'}+
                 $f->{'trueShStall.capinv'}+
                 $f->{'trueShStall.cap'}+
                 $f->{'trueShStall.cold'}) / $instrCount;
            $f->{'dMCPI-cold'} = 
                ($f->{'falseShStall.ice'}+
                 $f->{'falseShStall.cold'}) / $instrCount;
            $f->{'dMCPI-repl'} = 
                ($f->{'falseShStall.cap'}) / $instrCount;
            $f->{'dMCPI-false'} = 
                ($f->{'falseShStall.inv'}+
                 $f->{'falseShStall.capinv'}) / $instrCount;
            $f->{'dMCPI-other'} =  $f->{'dL2MCPI'} -
            ($f->{'dMCPI-true'}+
             $f->{'dMCPI-cold'}+
             $f->{'dMCPI-repl'}+
             $f->{'dMCPI-false'});

        } else { 
            foreach $i ('dMCPI-true','dMCPI-cold','dMCPI-repl',
                        'dMCPI-false','dMCPI-other') {
                $f->{$i} = -1;
            }
        }
    }
    
    # latencies (mipsy only)
    if( defined($f->{'dL2DirtyStall'} &&
                $f->{'dL2DirtyStall'} > 0 )) { 

        if ($f->{'dL1Miss'}-$f->{'dL2Miss'}-$f->{'dUpgrade'} > 0 ) {  
            $f->{'lat-l1'} =1.0 *  $f->{'dL1Stall'} / 
                ($f->{'dL1Miss'}-$f->{'dL2Miss'}-$f->{'dUpgrade'});

            if ($f->{'dUpgrade'}>0 ) {
                $f->{'lat-upg'} = 1.0 * $f->{'dUpgradeStall'} / 
                    ($f->{'dUpgrade'});
            } else {
                $f->{'lat-upg'} = -1;
            }

            if (($f->{'dL2Miss'} - $f->{'dL2DirtyMiss'}) > 0) {
		$f->{'lat-clean'} = 1.0 * 
		    ($f->{'dL2Stall'} - $f->{'dL2DirtyStall'})/
			($f->{'dL2Miss'} - $f->{'dL2DirtyMiss'});
	    } else {
		$f->{'lat-clean'} = -1;
	    }
	    
            if ($f->{'dL2DirtyMiss'} > 0 ) {
                $f->{'lat-dirty'} = 1.0 * 
                ($f->{'dL2DirtyStall'} / $f->{'dL2DirtyMiss'});
            } else {
                $f->{'lat-dirty'} = -1.0 ;
            }
        }
    }
}

return 1;