103 #define OVERFLOW_MODE 0 104 #define WEIGHT_METRIC 0 105 #define DEFAULT_THRESHOLD 2000000L 112 static void papi_event_handler(
int event_set,
void *pc,
long long ovec,
void *context);
140 int nevents =
self->evl.nevents;
141 for (i = 0; i < nevents; i++) {
142 int evcode =
self->evl.events[i].event;
143 if (event_code == evcode)
return i;
181 const PAPI_component_info_t *pci = PAPI_get_component_info(cidx);
182 if (strcmp(pci->name,
"bgpm/L2Unit") == 0)
return true;
196 char *s_end = s + strlen(s);
206 int last_blank =
BUFLEN-1;
213 if (*cur ==
'\n'|| *cur == 0) {
220 buffer[last_blank] = 0;
223 printf(
" %s\n", buffer);
251 if (strncasecmp(str,
"papi:", 5) == 0) {
254 while (str[0] ==
':') {
271 monitor_disable_new_threads();
273 TMSG(PAPI_C,
"Will disable PAPI cuda component (if component is active)");
274 int cidx = PAPI_get_component_index(
"cuda");
276 int res = PAPI_disable_component(cidx);
277 if (res == PAPI_OK) {
278 TMSG(PAPI,
"PAPI cuda component disabled");
281 EMSG(
"*** PAPI cuda component could not be disabled!!!");
285 int ret = PAPI_library_init(PAPI_VER_CURRENT);
286 monitor_enable_new_threads();
288 TMSG(PAPI_C,
"PAPI_library_init = %d", ret);
289 TMSG(PAPI_C,
"PAPI_VER_CURRENT = %d", PAPI_VER_CURRENT);
296 }
else if (ret != PAPI_VER_CURRENT) {
308 ret = PAPI_set_domain(PAPI_DOM_ALL);
309 if (ret != PAPI_OK) {
310 EMSG(
"warning: PAPI_set_domain(PAPI_DOM_ALL) failed: %d", ret);
320 TMSG(PAPI,
"thread init");
323 int retval = PAPI_thread_init(pthread_self);
324 if (retval != PAPI_OK) {
325 EEMSG(
"PAPI_thread_init NOT ok, retval = %d", retval);
328 TMSG(PAPI,
"thread init OK");
334 TMSG(PAPI,
"register thread");
337 int retval = PAPI_register_thread();
338 if (retval != PAPI_OK) {
339 EEMSG(
"PAPI_register_thread NOT ok, retval = %d", retval);
342 TMSG(PAPI,
"register thread ok");
362 if (my_state ==
START) {
363 TMSG(PAPI,
"*NOTE* PAPI start called when already in state START");
373 TMSG(PAPI,
"component %d is synchronous, use synchronous start", cidx);
377 TMSG(PAPI,
"starting PAPI event set %d for component %d", ci->
eventSet, cidx);
379 if (ret == PAPI_EISRUN) {
381 EMSG(
"PAPI returned EISRUN for event set %d component %d", ci->
eventSet, cidx);
383 else if (ret != PAPI_OK) {
384 EMSG(
"PAPI_start failed with %s (%d) for event set %d component %d ",
385 PAPI_strerror(ret), ret, ci->
eventSet, cidx);
391 if (ret != PAPI_OK) {
392 EMSG(
"PAPI_read of event set %d for component %d failed with %s (%d)",
393 ci->
eventSet, cidx, PAPI_strerror(ret), ret);
405 TMSG(PAPI,
"unregister thread");
408 int retval = PAPI_unregister_thread();
409 char msg[] =
"!!NOT PAPI_OK!! (code = -9999999)\n";
410 snprintf(msg,
sizeof(msg)-1,
"!!NOT PAPI_OK!! (code = %d)", retval);
411 TMSG(PAPI,
"unregister thread returns %s", retval == PAPI_OK?
"PAPI_OK" : msg);
423 int nevents =
self->evl.nevents;
426 if (my_state ==
STOP) {
427 TMSG(PAPI,
"*NOTE* PAPI stop called when already in state STOP");
431 if (my_state !=
START) {
432 TMSG(PAPI,
"*WARNING* PAPI stop called when not in state START");
441 TMSG(PAPI,
"component %d is synchronous, stop is trivial", cidx);
445 long_long values[nevents+2];
447 int ret = PAPI_stop(ci->
eventSet, values);
449 EMSG(
"Failed to stop PAPI for eventset %d. Return code = %d ==> %s",
450 ci->
eventSet, ret, PAPI_strerror(ret));
462 TMSG(PAPI,
"shutdown");
479 TMSG(PAPI,
"supports event");
482 if (self->state ==
UNINIT){
491 return PAPI_event_name_to_code(evtmp, &ec) == PAPI_OK;
497 TMSG(PAPI,
"process event list");
502 int num_lush_metrics = 0;
512 TMSG(PAPI,
"checking event spec = %s",event);
514 #ifdef USE_PAPI_CHECKING 516 AMSG(
"WARNING: %s using default threshold %ld, " 521 #endif // USE_PAPI_CHECKING 522 ret = PAPI_event_name_to_code(name, &evcode);
523 if (ret != PAPI_OK) {
524 EMSG(
"unexpected failure in PAPI process_event_list(): " 525 "PAPI_event_name_to_code() returned %s (%d)",
526 PAPI_strerror(ret), ret);
529 if (PAPI_query_event(evcode) != PAPI_OK) {
534 if (lush_metrics == 1 && strncmp(event,
"PAPI_TOT_CYC", 12) == 0) {
538 TMSG(PAPI,
"event %s -> event code = %x, thresh = %ld", event, evcode, thresh);
541 int nevents = (
self->evl).nevents;
542 TMSG(PAPI,
"nevents = %d", nevents);
547 for (i = 0; i < nevents; i++) {
548 char buffer[PAPI_MAX_STR_LEN + 10];
552 PAPI_event_code_to_name(self->evl.events[i].event, buffer);
553 TMSG(PAPI,
"metric for event %d = %s", i, buffer);
556 if (strcmp(buffer,
"PAPI_TOT_CYC") == 0) {
565 || self->evl.events[i].thresh == 0) {
566 TMSG(PAPI,
"using proxy sampling for event %s", buffer);
567 strcat(buffer,
" (proxy)");
568 self->evl.events[i].thresh = 1;
576 int cidx = PAPI_get_event_component(self->evl.events[i].event);
582 threshold =
self->evl.events[i].thresh;
586 TMSG(PAPI,
"Event %s from synchronous component", buffer);
592 if (num_lush_metrics > 0 && strcmp(buffer,
"PAPI_TOT_CYC") == 0) {
594 assert(num_lush_metrics == 1 && (i == (nevents - 1)));
601 self->evl.events[i].thresh, prop);
617 TMSG(PAPI,
"generating all event sets for all components");
620 int num_components = PAPI_num_components();
624 TMSG(PAPI,
"Num components = %d", num_components);
627 hpcrun_abort(
"Failure to allocate vector for PAPI components");
632 for (i = 0; i < num_components; i++) {
653 int nevents = (
self->evl).nevents;
654 for (i = 0; i < nevents; i++) {
655 int evcode =
self->evl.events[i].event;
656 int cidx = PAPI_get_event_component(evcode);
660 TMSG(PAPI,
"Added event code %x to component %d", evcode, cidx);
662 char buffer[PAPI_MAX_STR_LEN];
663 PAPI_event_code_to_name(evcode, buffer);
665 "PAPI_add_event(eventSet=%%d, event_code=%x (event name %s)) component=%d",
666 evcode, buffer, cidx);
668 if (ret != PAPI_OK) {
669 EMSG(
"failure in PAPI gen_event_set(): PAPI_add_event() returned: %s (%d)",
670 PAPI_strerror(ret), ret);
676 for (i = 0; i < num_components; i++) {
683 for (i = 0; i < nevents; i++) {
684 int evcode =
self->evl.events[i].event;
685 long thresh =
self->evl.events[i].thresh;
686 int cidx = PAPI_get_event_component(evcode);
692 TMSG(PAPI,
"event code %d (component %d) is synchronous, so do NOT set overflow", evcode, cidx);
693 TMSG(PAPI,
"Set up sync handler instead");
694 TMSG(PAPI,
"synchronous sample component index = %d", cidx);
702 TMSG(PAPI,
"PAPI_overflow(eventSet=%d, evcode=%x, thresh=%d) = %d",
703 eventSet, evcode, thresh, ret);
704 if (ret != PAPI_OK) {
705 EMSG(
"failure in PAPI gen_event_set(): PAPI_overflow() returned: %s (%d)",
706 PAPI_strerror(ret), ret);
716 PAPI_event_info_t info;
717 int ev, ret, num_total, num_prof;
718 int num_components, cidx;
721 printf(
"PAPI is not available. Probably, the kernel doesn't support PAPI,\n" 722 "or else maybe HPCToolkit is out of sync with PAPI.\n\n");
728 const PAPI_component_info_t *component = PAPI_get_component_info(cidx);
729 printf(
"===========================================================================\n");
730 printf(
"Available PAPI preset events in component %s\n", component->name);
732 printf(
"Name\t Profilable\tDescription\n");
733 printf(
"===========================================================================\n");
737 ev = 0| PAPI_PRESET_MASK;
738 ret = PAPI_enum_cmp_event(&ev, PAPI_ENUM_FIRST, cidx);
739 while (ret == PAPI_OK) {
741 memset(&info, 0,
sizeof(info));
742 if (PAPI_get_event_info(ev, &info) == PAPI_OK && info.count != 0) {
750 printf(
"%-10s\t%s\t%s\n", info.symbol, prof, info.long_descr);
752 ret = PAPI_enum_cmp_event(&ev, PAPI_ENUM_EVENTS, cidx);
754 printf(
"---------------------------------------------------------------------------\n");
755 printf(
"Total PAPI events: %d, able to profile: %d\n", num_total, num_prof);
759 num_components = PAPI_num_components();
760 for(cidx = 0; cidx < num_components; cidx++) {
761 const PAPI_component_info_t* component = PAPI_get_component_info(cidx);
762 int cmp_event_count = 0;
764 if (component->disabled)
continue;
766 printf(
"===========================================================================\n");
767 printf(
"Native events in component %s\n", component->name);
769 printf(
"Name Description\n");
770 printf(
"===========================================================================\n");
772 ev = 0 | PAPI_NATIVE_MASK;
773 ret = PAPI_enum_cmp_event(&ev, PAPI_ENUM_FIRST, cidx);
774 while (ret == PAPI_OK) {
775 memset(&info, 0,
sizeof(info));
776 if (PAPI_get_event_info(ev, &info) == PAPI_OK) {
778 printf(
"%-48s\n", info.symbol);
780 printf(
"---------------------------------------------------------------------------\n");
782 ret = PAPI_enum_cmp_event(&ev, PAPI_ENUM_EVENTS, cidx);
784 printf(
"Total native events for component %s: %d\n", component->name, cmp_event_count);
786 num_total += cmp_event_count;
789 printf(
"Total events reported: %d\n", num_total);
799 #define ss_cls SS_HARDWARE 800 #define ss_sort_order 70 822 PAPI_event_info_t info;
826 if (PAPI_get_event_info(ev_code, &info) != PAPI_OK
827 || info.derived ==
NULL) {
831 || strlen(info.derived) == 0
832 || strcmp(info.derived,
"NOT_DERIVED") == 0
833 || strcmp(info.derived,
"DERIVED_CMPD") == 0) {
844 PAPI_event_code_to_name(ev_code, name);
845 if (PAPI_query_event(ev_code) != PAPI_OK) {
851 if (papi_ret == PAPI_ECNFLCT) {
865 int nevents =
self->evl.nevents;
875 TMSG(PAPI_SAMPLE,
"papi overflow event: event set %d ovec = %ld",
887 int cidx = PAPI_get_eventset_component(event_set);
893 ret = PAPI_read(event_set, values);
894 if (ret != PAPI_OK) {
895 EMSG(
"PAPI_read failed with %s (%d)", PAPI_strerror(ret), ret);
899 ret = PAPI_get_overflow_event_index(event_set, ovec, my_events,
901 if (ret != PAPI_OK) {
902 TMSG(PAPI_SAMPLE,
"papi_event_handler: event set %d ovec %ld " 903 "get_overflow_event_index return code = %d ==> %s",
904 event_set, ovec, ret, PAPI_strerror(ret));
905 #ifdef DEBUG_PAPI_OVERFLOW 906 ret = PAPI_list_events(event_set, my_event_codes, &my_event_codes_count);
907 if (ret != PAPI_OK) {
908 TMSG(PAPI_SAMPLE,
"PAPI_list_events failed inside papi_event_handler." 909 "Return code = %d ==> %s", ret, PAPI_strerror(ret));
911 for (i = 0; i < my_event_codes_count; i++) {
912 TMSG(PAPI_SAMPLE,
"event set %d event code %d = %x\n",
913 event_set, i, my_event_codes[i]);
916 TMSG(PAPI_SAMPLE,
"get_overflow_event_index failure in papi_event_handler");
920 ret = PAPI_list_events(event_set, my_event_codes, &my_event_codes_count);
921 if (ret != PAPI_OK) {
922 hpcrun_abort(
"PAPI_list_events failed inside papi_event_handler." 923 "Return code = %d ==> %s", ret, PAPI_strerror(ret));
926 for (i = 0; i < my_event_count; i++) {
930 TMSG(PAPI_SAMPLE,
"handling papi overflow event: " 931 "event set %d event index = %d event code = 0x%x",
932 event_set, my_events[i], my_event_codes[my_events[i]]);
938 TMSG(PAPI_SAMPLE,
"sampling call path for metric_id = %d", metric_id);
940 uint64_t metricIncrement;
943 float myShare = 1.0 / liveThreads;
944 metricIncrement =
self->evl.events[i].thresh * myShare;
962 for (i = 0; i < nevents; i++) {
971 if (ret != PAPI_OK) {
972 EMSG(
"PAPI_read failed with %s (%d)", PAPI_strerror(ret), ret);
stop_proc_t sync_stop_for_component(int cidx)
get_event_set_proc_t component_get_event_set(int cidx)
static int derived[MAX_EVENTS]
add_event_proc_t component_add_event_proc(int cidx)
static void papi_event_handler(int event_set, void *pc, long long ovec, void *context)
static void hpcrun_safe_exit(void)
static int event_is_derived(int ev_code)
sample_val_t hpcrun_sample_callpath(void *context, int metricId, hpcrun_metricVal_t metricIncr, int skipInner, int isSync, sampling_info_t *data)
void hpcrun_ssfail_derived(char *source, char *event)
int hpcrun_threadmgr_thread_count()
finalize_event_set_proc_t component_finalize_event_set(int cidx)
void blame_shift_source_register(bs_type bst)
void hpcrun_save_papi_error(int error)
void hpcrun_ssfail_all_derived(char *source)
static const char * strip_papi_prefix(const char *str)
void hpcrun_disable_papi_cuda(void)
teardown_proc_t sync_teardown_for_component(int cidx)
#define hpcrun_abort(...)
bool component_uses_sync_samples(int cidx)
static bool disable_papi_cuda
void blame_shift_apply(int metric_id, cct_node_t *node, int metric_incr)
void hpcrun_stats_num_samples_blocked_async_inc(void)
metric_desc_t * hpcrun_set_metric_info_and_period(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_desc_properties_t prop)
get_event_set_proc_t get_event_set
static int get_event_index(sample_source_t *self, int event_code)
void hpcrun_ssfail_unsupported(char *source, char *event)
source_state_t * ss_state
int component_add_event(papi_source_info_t *psi, int cidx, int evcode)
#define metric_property_cycles
finalize_event_set_proc_t finalize_event_set
long long prev_values[MAX_EVENTS]
add_event_proc_t add_event
char * start_tok(char *lst)
papi_component_info_t component_info[0]
bool scale_by_thread_count
#define DEFAULT_THRESHOLD
static void METHOD_FN(init)
__thread bool hpcrun_thread_suppress_sample
void hpcrun_ssfail_start(char *source)
void * hpcrun_malloc(size_t size)
int hpcrun_extract_ev_thresh(const char *in, int evlen, char *ev, long *th, long def)
teardown_proc_t sync_teardown
static int hpcrun_safe_enter_async(void *pc)
int hpcrun_event2metric(sample_source_t *ss, int event_idx)
#define METHOD_CALL(obj, meth,...)
int get_component_event_set(papi_source_info_t *psi, int cidx)
static int const threshold
int hpcrun_new_metric(void)
#define HPCRUN_PAPI_ERROR_VERSION
void monitor_real_abort(void)
void hpcrun_pre_allocate_metrics(size_t num)
setup_proc_t sync_setup_for_component(int cidx)
static void print_desc(char *s)
static bool thread_count_scaling_for_component(int cidx)
start_proc_t sync_start_for_component(int cidx)
lush_agent_pool_t * lush_agents
static void event_fatal_error(int ev_code, int papi_ret)
#define HPCRUN_PAPI_ERROR_UNAVAIL
thread_data_t *(* hpcrun_get_thread_data)(void)
#define metric_property_none
void hpcrun_ssfail_conflict(char *source, char *event)