X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FPapi.c;h=62f5d0d3963bd1bf0eb3bbb67b4c0a39381f0780;hb=cd47700887365ca2a6af17d03e731efce65cf2ac;hp=5b4f7852db948d1fb4785101706486e0b283c376;hpb=2b522adea22f77a1c03230f5c9865c00bedb5a5b;p=ghc-hetmet.git diff --git a/rts/Papi.c b/rts/Papi.c index 5b4f785..62f5d0d 100644 --- a/rts/Papi.c +++ b/rts/Papi.c @@ -1,64 +1,72 @@ +/* ----------------------------------------------------------------------------- + * (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 "Papi.h" +#include +/* The posix symbols get defined in a header included from papi.h. + * undefind them here to allow redefinition in PosixSource.h */ +#undef _POSIX_SOURCE +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#include "PosixSource.h" #include "Rts.h" + #include "RtsUtils.h" #include "Stats.h" -#include "RtsFlags.h" - +#include "Papi.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; + const char * event_name; }; -#define PAPI_ADD_EVENT(EVENT) \ - { \ - ASSERT(n_papi_events= max_hardware_counters) { + errorBelch("too many PAPI events for this CPU (max: %d)", + max_hardware_counters); + stg_exit(EXIT_FAILURE); + } + papi_events[n_papi_events].event_code = code; + papi_events[n_papi_events].event_name = name; + n_papi_events++; +} static void init_countable_events(void) { - PAPI_ADD_EVENT(PAPI_TOT_CYC); - if(RtsFlags.PapiFlags.eventType==PAPI_FLAG_BRANCH) { + max_hardware_counters = PAPI_num_counters(); + +#define PAPI_ADD_EVENT(EVENT) papi_add_event(#EVENT,EVENT) + + 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 if (RtsFlags.PapiFlags.eventType==PAPI_USER_EVENTS) { + nat i; + char *name; + char *asciiEventCode; + int code; + for (i = 0; i < RtsFlags.PapiFlags.numUserEvents; i++) { + if(RtsFlags.PapiFlags.userEventsKind[i] == PAPI_PRESET_EVENT_KIND) { + name = RtsFlags.PapiFlags.userEvents[i]; + PAPI_CHECK(PAPI_event_name_to_code(name, &code)) + } + else { // PAPI_NATIVE_EVENT_KIND + asciiEventCode = RtsFlags.PapiFlags.userEvents[i]; + name = papiNativeEventNames[i]; + code = strtol(asciiEventCode, NULL, 16 /* hex number expected */); + PAPI_CHECK(PAPI_event_code_to_name(code, name)) + } + papi_add_event(name, code); + } + } else { + // PAPI_ADD_EVENT(PAPI_L1_DCA); // L1 data cache accesses + // PAPI_ADD_EVENT(PAPI_L1_ICR); // L1 instruction cache reads + // PAPI_ADD_EVENT(PAPI_L1_ICM); // L1 instruction cache misses + // PAPI_ADD_EVENT(PAPI_L1_STM); // L1 store misses + // PAPI_ADD_EVENT(PAPI_L1_DCM); // L1 data cache misses + // PAPI_ADD_EVENT(PAPI_L1_LDM); // L1 load misses + // PAPI_ADD_EVENT(PAPI_L2_TCM); // L2 cache misses + // PAPI_ADD_EVENT(PAPI_L2_STM); // L2 store misses + // PAPI_ADD_EVENT(PAPI_L2_DCW); // L2 data cache writes + // PAPI_ADD_EVENT(PAPI_L2_DCR); // L2 data cache reads + // PAPI_ADD_EVENT(PAPI_L2_TCW); // L2 cache writes + // PAPI_ADD_EVENT(PAPI_L2_TCR); // L2 cache reads + // PAPI_ADD_EVENT(PAPI_CA_CLN); // exclusive access to clean cache line + // PAPI_ADD_EVENT(PAPI_TLB_DM); // TLB misses + PAPI_ADD_EVENT(PAPI_TOT_INS); // Total instructions + PAPI_ADD_EVENT(PAPI_TOT_CYC); // Total instructions + // PAPI_ADD_EVENT(PAPI_CA_SHR); // exclusive access to shared cache line + // PAPI_ADD_EVENT(PAPI_RES_STL); // Cycles stalled on any resource + } -}; -long_long MutatorCounters[MAX_PAPI_EVENTS]; -long_long GCCounters[MAX_PAPI_EVENTS]; + // We might also consider: + // PAPI_BR_MSP Conditional branch instructions mispredicted + // PAPI_RES_STL Cycles stalled on any resource +}; -/* Extract the value corresponding to an event */ -long_long -papi_counter(long_long values[],int event) +static void +papi_report_event(const char *name, StgWord64 value) { - 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) +{ + nat i; + for(i=0;i