One more PAPI measurement, dropped precise cycle counting and replaced it with instru...
authorAlexey Rodriguez <mrchebas@gmail.com>
Thu, 21 Dec 2006 11:56:15 +0000 (11:56 +0000)
committerAlexey Rodriguez <mrchebas@gmail.com>
Thu, 21 Dec 2006 11:56:15 +0000 (11:56 +0000)
includes/RtsFlags.h
rts/Papi.c
rts/Papi.h
rts/RtsFlags.c
rts/Stats.c

index d2236b4..46f772a 100644 (file)
@@ -311,6 +311,7 @@ struct PAPI_FLAGS {
 #define PAPI_FLAG_CACHE_L2 2
 #define PAPI_FLAG_BRANCH 3
 #define PAPI_FLAG_STALLS 4
+#define PAPI_FLAG_CB_EVENTS 5
 
 #endif
 
index 6bb0d08..0963ca7 100644 (file)
@@ -59,6 +59,8 @@ struct _papi_events {
 #define DC_MISS 0x4000001a
 #define FR_DISPATCH_STALLS_BR 0x40000055
 #define FR_DISPATCH_STALLS_FULL_LS 0x4000005b
+#define DC_L2_REFILL_MOES 0x40001e1b
+#define DC_SYS_REFILL_MOES 0x40001e1c
 
 /* Number of counted events, computed from size of papi_events */
 #define N_PAPI_EVENTS n_papi_events
@@ -88,6 +90,13 @@ static struct _papi_events papi_events[MAX_PAPI_EVENTS];
 long_long MutatorCounters[MAX_PAPI_EVENTS];
 long_long GCCounters[MAX_PAPI_EVENTS];
 
+long_long start_mutator_cycles;
+long_long start_gc_cycles;
+long_long mutator_cycles;
+long_long gc_cycles;
+
+
+
 /* If you want to add events to count, extend the
  * init_countable_events and the papi_report function.
  * Be aware that your processor can count a limited number
@@ -97,7 +106,7 @@ long_long GCCounters[MAX_PAPI_EVENTS];
 static void
 init_countable_events(void) 
 {
-    PAPI_ADD_EVENT(PAPI_TOT_CYC);
+    PAPI_ADD_EVENT(PAPI_TOT_INS);
     if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_BRANCH) {
        PAPI_ADD_EVENT(FR_BR);
        PAPI_ADD_EVENT(FR_BR_MIS);
@@ -116,16 +125,37 @@ init_countable_events(void)
        PAPI_ADD_EVENT(PAPI_L2_DCA);
        PAPI_ADD_EVENT(PAPI_L2_DCM);
     }
+    if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_CB_EVENTS) {
+       PAPI_ADD_EVENT(DC_L2_REFILL_MOES);
+       PAPI_ADD_EVENT(DC_SYS_REFILL_MOES);
+       PAPI_ADD_EVENT(FR_BR_MIS);
+    }
 };
 
+
+static char temp[BIG_STRING_LEN];
+
+void
+papi_mut_cycles()
+{
+    ullong_format_string(mutator_cycles,temp,rtsTrue/*commas*/); 
+    statsPrintf("  (MUT_CYCLES)  : %s\n",temp);
+}
+
+void
+papi_gc_cycles()
+{
+    ullong_format_string(gc_cycles,temp,rtsTrue/*commas*/); 
+    statsPrintf("  (GC_CYCLES)  : %s\n",temp);
+}
+
 /* This function reports counters for GC and mutator */
 void
 papi_report(long_long PapiCounters[])
 {
-    char temp[BIG_STRING_LEN];
 
     /* I need to improve formatting aesthetics */
-    PAPI_REPORT(PapiCounters,PAPI_TOT_CYC);
+    PAPI_REPORT(PapiCounters,PAPI_TOT_INS);
 
     if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_BRANCH) {
        PAPI_REPORT(PapiCounters,FR_BR);
@@ -136,9 +166,9 @@ papi_report(long_long PapiCounters[])
 
     if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_STALLS) {
        PAPI_REPORT(PapiCounters,FR_DISPATCH_STALLS_BR);
-       PAPI_REPORT_PCT(PapiCounters,FR_DISPATCH_STALLS_BR,PAPI_TOT_CYC);
+       //PAPI_REPORT_PCT(PapiCounters,FR_DISPATCH_STALLS_BR,PAPI_TOT_CYC);
        PAPI_REPORT(PapiCounters,FR_DISPATCH_STALLS_FULL_LS);
-       PAPI_REPORT_PCT(PapiCounters,FR_DISPATCH_STALLS_FULL_LS,PAPI_TOT_CYC);
+       //PAPI_REPORT_PCT(PapiCounters,FR_DISPATCH_STALLS_FULL_LS,PAPI_TOT_CYC);
     }
 
     if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_CACHE_L1) {
@@ -153,6 +183,12 @@ papi_report(long_long PapiCounters[])
        PAPI_REPORT_PCT(PapiCounters,PAPI_L2_DCM,PAPI_L2_DCA);
     }
 
+    if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_CB_EVENTS) {
+       PAPI_REPORT(PapiCounters,DC_L2_REFILL_MOES);
+       PAPI_REPORT(PapiCounters,DC_SYS_REFILL_MOES);
+       PAPI_REPORT(PapiCounters,FR_BR_MIS);
+    }
+
 }
 
 
@@ -202,15 +238,24 @@ papi_add_events(int EventSet)
   }
 }
 
+/* We should be using elapsed cycles
+ * to be consistent with time metric chosen in Stats.c (Elapsed time).
+ * This is an approximation to the cycles that the program spends.
+ * Note that the counters, in contrast, are virtual and user space.
+ */
+#define PAPI_cycles PAPI_get_virt_cyc
+
 void
 papi_start_mutator_count(void)
 {
     PAPI_CHECK( PAPI_start(MutatorEvents));
+    start_mutator_cycles = PAPI_cycles();
 }
 
 void
 papi_stop_mutator_count(void)
 {
+    mutator_cycles += PAPI_cycles() - start_mutator_cycles;
     PAPI_CHECK( PAPI_accum(MutatorEvents,MutatorCounters));
     PAPI_CHECK( PAPI_stop(MutatorEvents,NULL));
 }
@@ -219,11 +264,13 @@ void
 papi_start_gc_count(void)
 {
       PAPI_CHECK( PAPI_start(GCEvents));
+      start_gc_cycles = PAPI_cycles();
 }
 
 void
 papi_stop_gc_count(void)
 {
+      gc_cycles += PAPI_cycles() - start_gc_cycles;
       PAPI_CHECK( PAPI_accum(GCEvents,GCCounters));
       PAPI_CHECK( PAPI_stop(GCEvents,NULL));
 }
index 1060ca2..835eea6 100644 (file)
@@ -32,6 +32,8 @@ extern long_long GCCounters[];
 
 long_long papi_counter(long_long values[],int event);
 void papi_report(long_long PapiCounters[]);
+void papi_mut_cycles(void);
+void papi_gc_cycles(void);
 void papi_add_events(int EventSet);
 
 void papi_init_eventsets(void);
index ddc1928..d818e77 100644 (file)
@@ -463,6 +463,7 @@ usage_text[] = {
 "            2 - level 2 cache misses",
 "            b - branch mispredictions",
 "            s - stalled cycles",
+"            e - cache miss and branch misprediction events",
 #endif
 "",
 "RTS options may also be specified using the GHCRTS environment variable.",
@@ -677,6 +678,9 @@ error = rtsTrue;
                case 's':
                  RtsFlags.PapiFlags.eventType = PAPI_FLAG_STALLS;
                  break;
+               case 'e':
+                 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CB_EVENTS;
+                 break;
                default:
                  bad_option( rts_argv[arg] );
                }
index 9f12b6d..9342118 100644 (file)
@@ -562,9 +562,11 @@ stat_exit(int alloc)
             * Note that the cycles are counted _after_ the initialization of the RTS -- AR */
 
            statsPrintf("  -- CPU Mutator counters --\n");
+           papi_mut_cycles();
            papi_report(MutatorCounters);
 
            statsPrintf("\n  -- CPU GC counters --\n");
+           papi_gc_cycles();
            papi_report(GCCounters);
 #endif
        }