Please review my preliminary patch to add percentage of time spent on DTLB 
misses to cpupcstat.
I appreciate your feedback.

Thank you

Avantika 

-----


This patch adds percentage of execution time spent servicing DTLB misses to 
the results of the cpupcstat script.  This is a preliminary patch which
makes changes to OProfile collection, adding collection of execution time
in cycles, but does not make changes to data collection using Perf.
It assumes that a file tlbmiscost.config exists under libhugetlbfs, 
containing the tlb miss cost in format: TLBMISSCOST=n, where n is the tlb
miss cost measured in cycles.

Signed-off-by: Avantika Mathur <mat...@us.ibm.com>
---
 TLBC/OpCollect.pm      |   40 ++++++++++++++++++++++++++--------------
 cpupcstat              |   28 ++++++++++++++++++++++++----
 oprofile_map_events.pl |   13 ++++++++++---
 3 files changed, 60 insertions(+), 21 deletions(-)

diff -uprN libhugetlbfs/cpupcstat libhugetlbfs-new/cpupcstat
--- libhugetlbfs/cpupcstat      2009-09-01 19:01:29.000000000 -0400
+++ libhugetlbfs-new/cpupcstat  2009-11-29 23:26:58.000000000 -0500
@@ -26,6 +26,14 @@ my $time_limit;
 my $persist = 0;
 my $kernel;
 my $force_oprofile;
+my $tlbcostconfig="tlbmisscost.config";
+my $data;
+my $cycles_executed;
+my $cycles_miss;
+my $tlbmisscost;
+my $percent;
+my $samples_timer;
+my $samples_dtlb;
 
 sub start_target()
 {
@@ -52,6 +60,7 @@ sub run_profile()
        my $new;
        my $collector;
 
+       printf("BIng is %s \n", $Bin);
        if ($force_oprofile) {
                $collector = TLBC::OpCollect->new();
        } else {
@@ -63,7 +72,7 @@ sub run_profile()
        if ($collector->setup($vmlinux, "dtlb_miss") == 0) {
                $collector = TLBC::OpCollect->new();
                if ($force_oprofile ||
-                       $collector->setup($vmlinux, "dtlb_miss") == 0) {
+                       $collector->setup($vmlinux, "timer,dtlb_miss") == 0) {
                        die("Unable to setup data collector");
                }
        }
@@ -86,17 +95,18 @@ sub run_profile()
        $binName = `basename $binName`;
        chomp($binName);
 
+       ($samples_timer, $samples_dtlb) = split(/,/, $collector->samples());
        printf("%20s%20s%24s\n", "Target Name", "DTLB Miss Samples",
                "Samples/second");
 
-       printf("%20s%20s%24s\n", "", "Sample every " . $collector->samples(), 
"");
+       printf("%20s%20s%24s\n", "", "Sample every " . $samples_dtlb, "");
        sleep($wait_time);
 
        # While our target is still running and we have not exceeded our
        # runtime, collect oprofile data every $wait_time seconds to display
        # the dtlb miss rate.
        while (waitpid($pid, WNOHANG) <= 0 || $persist) {
-               $ret = $collector->get_current_eventcount($binName);
+               ($new,$ret) = split(/,/, 
$collector->get_current_eventcount($binName));
                $new = $ret - $prev;
                printf("%20s%20d%24f\n", $binName, $new, $new / $wait_time);
                $prev = $ret;
@@ -116,7 +126,7 @@ sub run_profile()
        }
        $end_time = time();
        $time_elapsed = $end_time - $start_time;
-       $misses = $collector->get_current_eventcount($binName);
+       ($cycles_executed, $misses) = split(/,/, 
$collector->get_current_eventcount($binName));
        if ($kernel) {
                $kern_misses = $collector->get_current_eventcount("vmlinux");
        }
@@ -192,6 +202,16 @@ if ($misses > 0) {
        print("\n$target saw $misses total DTLB miss samples over ",
                "$time_elapsed seconds\n");
        print("at rate of ", $misses / $time_elapsed, " samples/second\n");
+       open(DAT, $tlbcostconfig) || die("Failed to open file %s", 
$tlbcostconfig);
+       $data=<DAT>;
+       close(DAT);
+       ($data,$tlbmisscost)=split(/\=/,$data);
+       chomp($tlbmisscost);
+
+       $cycles_executed = $cycles_executed * $samples_timer;
+       $cycles_miss = $tlbmisscost * $misses * $samples_dtlb;
+       $percent=($cycles_miss / $cycles_executed) * 100;
+       print("$percent%", " of the execution time was spent servicing DTLB 
misses\n");
 }
 
 if ($kern_misses > 0) {
diff -uprN libhugetlbfs/oprofile_map_events.pl 
libhugetlbfs-new/oprofile_map_events.pl
--- libhugetlbfs/oprofile_map_events.pl 2009-11-24 15:14:58.000000000 -0500
+++ libhugetlbfs-new/oprofile_map_events.pl     2009-11-29 23:48:44.000000000 
-0500
@@ -17,6 +17,7 @@ my $opt_event;
 my $opt_cycle_factor=1;
 my $opt_event_factor=1;
 my $p = "oprofile_map_events.pl";
+my $verify = 0;
 
 my $oprofile_event;
 my (%map_event_name, %map_event_mask);
@@ -85,6 +86,7 @@ open (CPUTYPE, "/proc/sys/dev/oprofile/c
        open (CPUTYPE, "/dev/oprofile/cpu_type") ||
                die("Failed to open cpu_type oprofile device");
 ($arch, $cputype) = split(/\//, <CPUTYPE>);
+$cputype="970MP";
 close CPUTYPE;
 printVerbose("$p\::arch = $arch\n");
 printVerbose("$p\::cputype = $cputype\n");
@@ -124,14 +126,19 @@ if ($opt_cycle_factor != 1 || $opt_event
 open (VERIFY, "opcontrol --list-events|") || die("Failed to exec opcontrol");
 my ($oprofile_event_name) = split(/:/, $oprofile_event);
 printVerbose("$p\::checking $oprofile_event_name\n");
+printVerbose("oprofile_event: %s, oprofile_event_name: %s\n", $oprofile_event, 
$oprofile_event_name);
 while (!eof(VERIFY)) {
        if (<VERIFY> =~ /^$oprofile_event_name:/) {
                close(VERIFY);
                print "$oprofile_event\n";
+               $verify = 1;
                exit(0);
        }
 }
 close(VERIFY);
-printVerbose("$p\::opcontrol --list-events disagrees\n");
-print "UNKNOWN_OPROFILE_DISPARITY\n";
-exit(-3);
+if ( $verify == 0) {
+       printVerbose("$p\::opcontrol --list-events disagrees\n");
+       print "UNKNOWN_OPROFILE_DISPARITY\n";
+       exit(-3);
+}
+exit(0);
diff -uprN libhugetlbfs/TLBC/OpCollect.pm libhugetlbfs-new/TLBC/OpCollect.pm
--- libhugetlbfs/TLBC/OpCollect.pm      2009-09-01 19:01:29.000000000 -0400
+++ libhugetlbfs-new/TLBC/OpCollect.pm  2009-11-30 00:15:00.000000000 -0500
@@ -18,7 +18,7 @@ use TLBC::DataCollect;
 
 our @ISA = qw(TLBC::DataCollect);
 
-my $count = 0;
+my $count = " ";
 my $reference;
 
 #use interface 'DataCollect';
@@ -38,8 +38,12 @@ sub _setup_oprofile()
        my $self = shift;
        my $vmlinux = shift;
        my $event = shift;
-       my $cmd = "$Bin/oprofile_start.sh --vmlinux=$vmlinux " .
-                  "--event=$event  > /dev/null 2>&1";
+       my @events = split(/,/, $event);
+       my $list = "";
+       foreach $event (@events) {
+               $list = "--event $event $list";
+       }
+       my $cmd = "$Bin/oprofile_start.sh --vmlinux=$vmlinux $list";
        system($cmd) == 0 or return 0;
        return $self;
 }
@@ -50,14 +54,18 @@ sub _get_event()
        my $event = shift;
        my @vals;
        my $lowlevel_event;
-       $lowlevel_event = `$Bin/oprofile_map_events.pl --event $event 
2>/dev/null`;
-       chomp($lowlevel_event);
-       if ($lowlevel_event eq "" || $lowlevel_event !~ /^[A-Z0-9_]+:[0-9]+/) {
-               die "Unable to find $event event for this CPU\n";
-       }
+       my @events = split(/,/, $event);
+
+       foreach $event (@events) {
+               $lowlevel_event = `$Bin/oprofile_map_events.pl --event $event 
2>/dev/null`;
+               chomp($lowlevel_event);
+               if ($lowlevel_event eq "" || $lowlevel_event !~ 
/^[A-Z0-9_]+:[0-9]+/) {
+                       die "Unable to find $event event for this CPU\n";
+               }
+               @vals = split(/:/, $lowlevel_event);
+               $count = "$count $vals[1],";
+        }
 
-       @vals = split(/:/, $lowlevel_event);
-       $count = $vals[1];
        return $self;
 }
 
@@ -93,9 +101,11 @@ sub get_current_eventcount()
        my @results;
        my $line;
        my $report;
-       my $hits = 0;
+       my $event1 = 0;
+       my $event2 = 0;
        my $self = shift;
        my $binName = shift;
+       my $return;
 
        system("opcontrol --dump > /dev/null 2>&1");
        $report = `opreport`;
@@ -105,11 +115,13 @@ sub get_current_eventcount()
                        chomp($line);
                        $line =~ s/^\s+//;
                        $line =~ s/\s+$//;
-                       my @vals = split(/ /, $line);
-                       $hits += $vals[0];
+                       my @vals = split(/\s+/, $line);
+                       $event1 += $vals[0];
+                       $event2 += $vals[2];
                }
        }
-       return $hits;
+       $return = "$event1,$event2";
+       return $return;
 }
 
 sub shutdown()


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to