X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FPapi.c;h=8e8900fe96ede7e1fb7853093eabac05d12cc562;hb=a84385fa752d8fa800a2155cce95f47c68b74e2b;hp=5b4f7852db948d1fb4785101706486e0b283c376;hpb=2b522adea22f77a1c03230f5c9865c00bedb5a5b;p=ghc-hetmet.git diff --git a/rts/Papi.c b/rts/Papi.c index 5b4f785..8e8900f 100644 --- a/rts/Papi.c +++ b/rts/Papi.c @@ -1,64 +1,67 @@ +/* ----------------------------------------------------------------------------- + * (c) The GHC Team 2006 + * + * Initialization and use of the PAPI performance monitoring library + * + * + * For adding events or add your processor counters modify + * + * init_countable_events + * papi_report + * + * ---------------------------------------------------------------------------*/ + + #ifdef USE_PAPI /* ugly */ +#include + #include "Papi.h" #include "Rts.h" #include "RtsUtils.h" #include "Stats.h" #include "RtsFlags.h" +#include "OSThreads.h" - -/* These constants specify which events to keep track of. - * Probably it is better to count one set of events at a time. - * The reason is that processors have limited counters and - * multiplexing is not enabled (yet). - */ -#define PAPI_COUNT_BRANCHES 0 -/* The one below is Opteron specific. - */ -#define PAPI_COUNT_STALLS 0 -#define PAPI_COUNT_DCACHE1_MISSES 1 -#define PAPI_COUNT_DCACHE2_MISSES 0 +// used to protect the aggregated counters +#ifdef THREADED_RTS +static Mutex papi_counter_mutex; +#endif struct _papi_events { int event_code; char * event_name; }; -#define PAPI_ADD_EVENT(EVENT) \ - { \ - ASSERT(n_papi_events= MAX_PAPI_EVENTS) { \ + barf("too many PAPI events"); \ + } \ + papi_events[n_papi_events].event_code = EVENT; \ + papi_events[n_papi_events].event_name = #EVENT; \ + n_papi_events++; \ + } + + PAPI_ADD_EVENT(PAPI_TOT_INS); + if (RtsFlags.PapiFlags.eventType==PAPI_FLAG_BRANCH) { PAPI_ADD_EVENT(FR_BR); PAPI_ADD_EVENT(FR_BR_MIS); /* Docs are wrong? Opteron does not count indirect branch misses exclusively */ PAPI_ADD_EVENT(FR_BR_MISCOMPARE); - } - if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_STALLS) { + } else if (RtsFlags.PapiFlags.eventType==PAPI_FLAG_STALLS) { + PAPI_ADD_EVENT(FR_DISPATCH_STALLS); PAPI_ADD_EVENT(FR_DISPATCH_STALLS_BR); PAPI_ADD_EVENT(FR_DISPATCH_STALLS_FULL_LS); - } - if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_CACHE_L1) { + } else if (RtsFlags.PapiFlags.eventType==PAPI_FLAG_CACHE_L1) { PAPI_ADD_EVENT(PAPI_L1_DCA); PAPI_ADD_EVENT(PAPI_L1_DCM); - } - if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_CACHE_L2) { + } else if (RtsFlags.PapiFlags.eventType==PAPI_FLAG_CACHE_L2) { PAPI_ADD_EVENT(PAPI_L2_DCA); PAPI_ADD_EVENT(PAPI_L2_DCM); + } else 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); + } else { + PAPI_ADD_EVENT(PAPI_STL_ICY); } + + // We might also consider: + // PAPI_BR_MSP Conditional branch instructions mispredicted + // PAPI_RES_STL Cycles stalled on any resource }; -long_long MutatorCounters[MAX_PAPI_EVENTS]; -long_long GCCounters[MAX_PAPI_EVENTS]; +static char temp[BIG_STRING_LEN]; -/* Extract the value corresponding to an event */ -long_long -papi_counter(long_long values[],int event) +void +papi_mut_cycles() { - int i; - for(i=0;i 0) { + errorBelch("PAPI_library_init: wrong version: %x", ver); + stg_exit(EXIT_FAILURE); + } else { + sysErrorBelch("PAPI_library_init"); + stg_exit(EXIT_FAILURE); + } + } + +#ifdef THREADED_RTS + { + int err; + if ((err = PAPI_thread_init(osThreadId)) < 0) { + barf("PAPI_thread_init: %d",err); + } + + initMutex(&papi_counter_mutex); + } +#endif init_countable_events(); - /* One event set for the mutator and another for the GC */ - PAPI_CHECK( PAPI_create_eventset(&MutatorEvents)); - PAPI_CHECK( PAPI_create_eventset(&GCEvents)); + papi_init_eventset(&MutatorEvents); + papi_init_eventset(&GCEvents); +} - /* Both sets contain the same events */ - papi_add_events(MutatorEvents); - papi_add_events(GCEvents); +/* Extract the value corresponding to an event */ +static long_long +papi_counter(long_long values[],int event) +{ + int i; + for(i=0;i