busbw.prl 4.7 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. 
#




$inputFile = shift;
if (!defined($inputFile)) {
    $inputFile = "cpu.log";
}

if (0) { 
    @fields = ('DUMMY', 'MEM',
               'COUNT_IGETS', 'COUNT_LLGETS', 'COUNT_DMAGETS', 'COUNT_DGETS', 
               'COUNT_DMAGETXS', 'COUNT_GETXS', 'COUNT_SCUPGRADES', 'COUNT_UPGRADES',
               'COUNT_WRITEBACKS', 'COUNT_REPLHINTS',
               'COUNT_UNCACHEDWRITES', 'COUNT_UNCACHEDACCWRITES', 'COUNT_UNCACHEDREADS',
               'COUNT_INVALORDNGRADESENT',
               'COUNT_NAKS',
               'COUNT_REMOTEDIRTY',
               'COUNT_EXCLUSIVEONSHARED',
               'COUNT_MEMORYACCESS',
               'COUNT_DRAMBUSY');
    
    $i = 0;
    foreach $field (@fields) {
        $pos{$field} =  $i++;
    }
    
}
open(LOG,$inputFile);

for $i (0..16) { 
    for $j (0..30) {
        $prevCommon[$i][$j] = 0;
        $prevBusUma[$i][$j] = 0;
        $sumBusUma[$j] = 0;
        $sumCommon[$j]  = 0;
    }
}

    
sub PrintRes {
    #
    # figure out bandwidth
    #
    $count{'get'} = ($sumCommon[$posCommon{'IGETS'}] + 
                     $sumCommon[$posCommon{'DGETS'}] + 
                     $sumCommon[$posCommon{'GETXS'}] +
                     $sumCommon[$posCommon{'LLGETS'}] +
                     $sumCommon[$posCommon{'DMAGETS'}] +
                     $sumCommon[$posCommon{'DMAGETXS'}]);
    
    $count{'victimhits'} = $sumBusUma[$posBusUma{'GET_WBBUF'}];
    
    $count{'wb'}  = $sumCommon[$posCommon{'WRITEBACKS'}];

    $count{'upg'} = ($sumCommon[$posCommon{'UPGRADES'}] +
                     $sumCommon[$posCommon{'SCUPGRADES'}] -
                     $sumBusUma[$posBusUma{'UPG_WBBUF'}]);

    $count{'merges'} = $sumBusUma[$posBusUma{'MERGES'}];
    

    $count{'memAccess'} = ($sumCommon[$posCommon{'MEMORYACCESS'}]);
    
    $count{'data'} = ($count{'get'}-$count{'merges'} - $count{'victimhits'});


    $count{'busData'} = $sumBusUma[$posBusUma{'BUS_GETRQST'}] +
        $sumBusUma[$posBusUma{'BUS_GETREPLY'}];
    $count{'busWB'}   = $sumBusUma[$posBusUma{'BUS_WB'}];
    $count{'busUPG'}   = $sumBusUma[$posBusUma{'BUS_UPG'}];

    $count{'busIdle'} = $sumBusUma[$posBusUma{'BUS_IDLE'}];
    $count{'busDiff'} = (4*1024*1024) -
        ($count{'busData'} +  $count{'busWB'} + 
         $count{'busUPG'} + $count{'busIdle'});


    ###
    ### now, some normalization. Assume 4*1024*1024 cycles
    ### between calls
    ###
    
    $occup{'data'} = ($count{'data'}) * 2 *
        ($occupancy{'arb'} + $occupancy{'trans'});
    $occup{'wb'} = $count{'wb'} * 
	($occupancy{'arb'} + $occupancy{'trans'});
    $occup{'upg'} = $count{'upg'} * 
	($occupancy{'arb'} + $occupancy{'trans'});
    
    $occup{'total'} =  $occup{'data'} +$occup{'wb'}+$occup{'upg'};
    
    foreach $a ('busData','busWB','busUPG','busDiff','busIdle') { 
        printf("%s=%6.1f\%\t",  $a, 100.0 * 
               $count{$a} / (4*1024*1024));
    }

    $time = 4* 1024 * 1024 / $config{'CPU.Clock'};
    $norm = $config{'CACHE.2Level.L2Line'} / $time;

    printf("   |  GET %6.0f MB/s  WB %6.0f MB/s  Merges=%6.0f\% \n",
            $norm * $count{'data'},
            $norm * $count{'wb'},
           ($count{'data'}? 100 * $count{'merges'} / $count{'data'}:0));
}


while(<LOG>) { 
    if (/MACHINE (\S+)\t(\S+)/) { 
        $config{$1} = $2;
    }
    if (/PARAM (\S+) (\S+)/) {
        print "XXX config $1 : $2 \n";
        $config{$1} = $2;
    }

    if (/MEMFields/) { 
        print "MEMFields found \n";
        @arr = split;
        for $i (1..$#arr) {
            $posCommon{$arr[$i]} = $i+1;
        }
    }
    if (/MEMBUSUMAFields/) { 
        print "MEMBUSUMA found \n";
        @arr = split;
        for $i (1..$#arr) {
            $posBusUma{$arr[$i]} = $i+1;
        }
    }
    if (/MEMSYS: BusUma - arbitrate: (\d+), transfer: (\d+), memory: (\d+)/){ 
        $occupancy{'arb'} = $1;
        $occupancy{'trans'} = $2;
        $occupancy{'mem'} = $3;
     #   print "YYY $1 $2 $3 \n";
    }
    if (/^MEM /) { 
        @arr = split;
        for $i (2..$#arr) {
            $sumCommon[$i] +=  $arr[$i] - $prevCommon[$arr[1]][$i];
            $prevCommon[$arr[1]][$i] = $arr[$i];
        }

    }
    if (/^MEMBUSUMA /) {     
        @arr = split;
        for $i (2..$#arr) {
            $sumBusUma[$i] +=  $arr[$i] - $prevBusUma[$arr[1]][$i];
            $prevBusUma[$arr[1]][$i] = $arr[$i];
        }
        if ($arr[1]==$config{'MEMSYS.BusUma.NumMemories'}-1) { 
            PrintRes();
            for $i (0..30) {
                $sumCommon[$i] = 0;
                $sumBusUma[$i] = 0;
            }
        }        
    }
}