int PAPI_add_env_event(int *EventSet, int *EventCode, char *env_variable){ int real_event=*EventCode; char *eventname; int retval; if ( env_variable != NULL ){ if ( (eventname=getenv(env_variable)) ) { if ( eventname[0] == 'P' ) { /* Use the PAPI name */ retval=PAPI_event_name_to_code(eventname, &real_event ); if ( retval != PAPI_OK ) real_event = *EventCode; } else{ if ( strlen(eventname)>1 && eventname[1]=='x') sscanf(eventname, "%#x", &real_event); else real_event = atoi(eventname); } } } if ( (retval = PAPI_add_event( *EventSet, real_event))!= PAPI_OK ){ if ( real_event != *EventCode ) { if ( (retval = PAPI_add_event( *EventSet, *EventCode)) == PAPI_OK ){ real_event = *EventCode; } } } *EventCode = real_event; return retval; }
int _hl_rate_calls(float *real_time, float *proc_time, long long * ins, float *rate, int EVENT, HighLevelInfo * state) { long long values[2] = { 0, 0 }; int retval = 0; int level = 0; if (EVENT == PAPI_FP_INS) level = HL_FLIPS; else if (EVENT == PAPI_TOT_INS) level = HL_IPC; else if (EVENT == PAPI_FP_OPS) level = HL_FLOPS; if (state->running != 0 && state->running != level) return (PAPI_EINVAL); if (state->running == 0) { if (PAPI_query_event(EVENT) != PAPI_OK) return (PAPI_ENOEVNT); if ((retval = PAPI_add_event(state->EventSet, EVENT)) != PAPI_OK) { _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } if (PAPI_query_event(PAPI_TOT_CYC) != PAPI_OK) return (PAPI_ENOEVNT); if ((retval = PAPI_add_event(state->EventSet, PAPI_TOT_CYC)) != PAPI_OK) { _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } state->initial_time = PAPI_get_real_usec(); if ((retval = PAPI_start(state->EventSet)) != PAPI_OK) return (retval); state->running = level; } else { if ((retval = PAPI_stop(state->EventSet, values)) != PAPI_OK) return (retval); /* Use Multiplication because it is much faster */ *real_time = (float) ((long long)(PAPI_get_real_usec() - state->initial_time) * .000001); *proc_time = (float) (values[1]*.000001/((_papi_hwi_system_info.hw_info.mhz==0)?1:_papi_hwi_system_info.hw_info.mhz)); if (*proc_time > 0) *rate = (float) ((float) values[0]*(EVENT==PAPI_TOT_INS?1:_papi_hwi_system_info.hw_info.mhz)/(values[1]==0?1:values[1])); state->total_proc_time += *proc_time; state->total_ins += values[0]; *proc_time = state->total_proc_time; *ins = (long long)state->total_ins; if ((retval = PAPI_start(state->EventSet)) != PAPI_OK) { state->running = 0; return (retval); } } return PAPI_OK; }
int main( int argc, char **argv ) { double c, a = 0.999, b = 1.001; int n = 1000; int EventSet = PAPI_NULL; int retval; int i, j = 0; long long g1[2]; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); if ( PAPI_query_event( PAPI_L2_TCM ) == PAPI_OK ) j++; if ( j == 1 && ( retval = PAPI_add_event( EventSet, PAPI_L2_TCM ) ) != PAPI_OK ) { if ( retval != PAPI_ECNFLCT ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); j--; /* The event was not added */ } i = j; if ( PAPI_query_event( PAPI_L2_DCM ) == PAPI_OK ) j++; if ( j == ( i + 1 ) && ( retval = PAPI_add_event( EventSet, PAPI_L2_DCM ) ) != PAPI_OK ) { if ( retval != PAPI_ECNFLCT ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); j--; /* The event was not added */ } if ( j ) { if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); for ( i = 0; i < n; i++ ) { c = a * b; } if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c); if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
void my_papi_start( int myrank ) { #ifdef PAPI_MONITOR int retval, index ; char EventCodeStr[PAPI_MAX_STR_LEN]; if(myrank == 0) DO_TEST = 1; retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI library init error! %d\n", retval); exit(1); } fprintf(stderr,"PAPI Library start ...\n"); if (PAPI_create_eventset(&PAPI_EventSet) != PAPI_OK) exit(1); for (index = 0 ; index < NEVENTS ; index ++) { PAPI_event_code_to_name(PAPI_events[index], EventCodeStr); /*fprintf(stderr,"Adding event %s ... ",EventCodeStr); */ if (PAPI_add_event(PAPI_EventSet,PAPI_events[index]) != PAPI_OK) exit(1); /*fprintf(stderr," DONE !\n"); */ } /*fprintf(stderr,"\n"); */ if (PAPI_start(PAPI_EventSet) != PAPI_OK) exit(1); #endif /*PAPI_MONITOR */ }
void counter_init( int *eventset, int *num_papi_events ) { char error_str[PAPI_MAX_STR_LEN]; // int events[] = {PAPI_TOT_INS,PAPI_BR_INS,PAPI_SR_INS}; int events[] = {PAPI_TOT_CYC,PAPI_L3_TCM}; int stat; int thread = omp_get_thread_num(); if( thread == 0 ) printf("Initializing PAPI counters...\n"); *num_papi_events = sizeof(events) / sizeof(int); if ((stat = PAPI_thread_init((long unsigned int (*)(void)) omp_get_thread_num)) != PAPI_OK) { PAPI_perror("PAPI_thread_init"); exit(1); } if ( (stat= PAPI_create_eventset(eventset)) != PAPI_OK) { PAPI_perror("PAPI_create_eventset"); exit(1); } for( int i = 0; i < *num_papi_events; i++ ) { if ((stat=PAPI_add_event(*eventset,events[i])) != PAPI_OK) { PAPI_perror("PAPI_add_event"); exit(1); } } if ((stat=PAPI_start(*eventset)) != PAPI_OK) { PAPI_perror("PAPI_start"); exit(1); } }
void papi_init(int eventNumber){ if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI is unsupported.\n"); papi_supported = false; } if (PAPI_num_counters() < 5) { fprintf(stderr, "PAPI is unsupported.\n"); papi_supported = false; } if ((papi_err = PAPI_create_eventset(&eventSet)) != PAPI_OK) { fprintf(stderr, "Could not create event set: %s\n", PAPI_strerror(papi_err)); } /* force program to run on a single CPU */ cpu_set_t my_set; /* Define your cpu_set bit mask. */ CPU_ZERO(&my_set); /* Initialize it all to 0, i.e. no CPUs selected. */ CPU_SET(0, &my_set); if (sched_setaffinity(0, sizeof(cpu_set_t), &my_set) != 0) { perror("sched_setaffinity error"); } if ((papi_err = PAPI_add_event(eventSet, events[eventNumber])) != PAPI_OK ) { fprintf(stderr, "Could not add event: %s\n", PAPI_strerror(papi_err)); } }
int check_papi_counter(char * counter_name) { PAPI_event_info_t * info; int EventSet = PAPI_NULL; unsigned int event_code = 0x0; int err; if ((err=PAPI_create_eventset (&EventSet)) != PAPI_OK){ fprintf(stderr,"Failed to create a PAPI eventset\n"); exit(1); } if((err = PAPI_event_name_to_code(counter_name,&event_code)) != PAPI_OK){ return err; } if((err = PAPI_add_event (EventSet, event_code)) != PAPI_OK) { return err; } PAPI_remove_named_event (EventSet, counter_name); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ){ printf("********** Call to destroy eventset failed when trying to validate event '%s' **********\n", counter_name); } return err; }
static void vt_metric_test(void) { int i; int retval; int EventSet = PAPI_NULL; /* create event set */ retval = PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK) vt_metric_error(retval, "PAPI_create_eventset"); for ( i = 0; i < nmetrics; i++ ) { /* add event to event set */ retval = PAPI_add_event(EventSet, metricv[i]->papi_code); if ( retval != PAPI_OK ) { char errstring[PAPI_MAX_STR_LEN]; sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name); vt_metric_error(retval, errstring); } vt_cntl_msg("Event %s added to event set", metricv[i]->name); } retval = PAPI_cleanup_eventset(EventSet); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&EventSet); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_destroy_eventset"); vt_cntl_msg("Event set tested OK"); }
void start_papi() { values = calloc(en, sizeof(long long)); if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI is unsupported.\n"); papi_supported = 0; } if (PAPI_num_counters() < en) { fprintf(stderr, "PAPI is unsupported.\n"); papi_supported = 0; } if ((papi_err = PAPI_create_eventset(&eventSet)) != PAPI_OK) { fprintf(stderr, "Could not create event set: %s\n", PAPI_strerror(papi_err)); } for (int i=0; i<en; ++i) { if ((papi_err = PAPI_add_event(eventSet, events[i])) != PAPI_OK ) { fprintf(stderr, "Could not add event: %s %s\n", event_names[i], PAPI_strerror(papi_err)); } } /* start counters */ if (papi_supported) { if ((papi_err = PAPI_start(eventSet)) != PAPI_OK) { fprintf(stderr, "Could not start counters: %s\n", PAPI_strerror(papi_err)); } } }
int PAPI_start_counters(int *events, int array_len) { int i, retval; HighLevelInfo *state = NULL; if ((retval = _internal_check_state(&state)) != PAPI_OK) return (retval); if(state->running != 0) return(PAPI_EINVAL); /* load events to the new EventSet */ for (i = 0; i < array_len; i++) { retval = PAPI_add_event(state->EventSet, events[i]); if (retval == PAPI_EISRUN) return (retval); if (retval) { /* remove any prior events that may have been added * and cleanup the high level information */ _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } } /* start the EventSet */ if ((retval = _internal_start_hl_counters(state)) == PAPI_OK) { state->running = HL_START_COUNTERS; state->num_evts = array_len; } return (retval); }
struct vt_metv* vt_metric_create() { struct vt_metv* metv; int retval, i; if ( nmetrics == 0 ) return NULL; metv = (struct vt_metv*)malloc(sizeof(struct vt_metv)); if ( metv == NULL ) vt_error(); /* create event set */ metv->EventSet = PAPI_NULL; retval = PAPI_create_eventset(&metv->EventSet); if ( retval != PAPI_OK) vt_metric_error(retval, "PAPI_create_eventset"); for ( i = 0; i < nmetrics; i++ ) { /* add event to event set */ retval = PAPI_add_event(metv->EventSet, metricv[i]->papi_code); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_add_event"); } retval = PAPI_start(metv->EventSet); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_start"); /*vt_cntl_msg("Counters started");*/ return metv; }
static void measure_event( int index, PAPI_option_t * option ) { int retval; long long value; if ( ( retval = PAPI_add_event( EventSet, PAPI_event[index] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( index == 0 ) { /* if ((retval = PAPI_get_opt(PAPI_DATA_ADDRESS, option)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_get_opt(PAPI_DATA_ADDRESS)", retval); */ printf ( "Requested Start Address: %p; Start Offset: 0x%5x; Actual Start Address: %p\n", option->addr.start, option->addr.start_off, option->addr.start - option->addr.start_off ); printf ( "Requested End Address: %p; End Offset: 0x%5x; Actual End Address: %p\n", option->addr.end, option->addr.end_off, option->addr.end + option->addr.end_off ); } PAPI_start( EventSet ); do_malloc_work( NUM ); do_static_work( NUM ); PAPI_stop( EventSet, &value ); printf( "%s: %lld\n", event_name[index], value ); if ( ( retval = PAPI_remove_event( EventSet, PAPI_event[index] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval ); }
int polybench_papi_start_counter(int evid) { # ifndef POLYBENCH_NO_FLUSH_CACHE polybench_flush_cache(); # endif # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval = 1; char descr[PAPI_MAX_STR_LEN]; PAPI_event_info_t evinfo; PAPI_event_code_to_name (polybench_papi_eventlist[evid], descr); if (PAPI_add_event (polybench_papi_eventset, polybench_papi_eventlist[evid]) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_add_event", 1); if (PAPI_get_event_info (polybench_papi_eventlist[evid], &evinfo) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_get_event_info", retval); if ((retval = PAPI_start (polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_start", retval); # ifdef _OPENMP } } #pragma omp barrier # endif return 0; }
void initialize_papi (int eventCode) { /* Initialize the PAPI library */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI library init error! %d\n",PAPI_EINVAL); handle_error(1); } if (EventSet==PAPI_NULL) { if (PAPI_create_eventset(&EventSet) != PAPI_OK) { printf("PAPI create eventset error\n"); handle_error(1); } } else { if (PAPI_cleanup_eventset(EventSet) != PAPI_OK) { printf("PAPI cleanup error\n"); handle_error(1); } } if (PAPI_add_event(EventSet, eventCode) != PAPI_OK) { printf("PAPI add event error: %x\n", eventCode); handle_error(1); } }
/* Test whether requested event combination valid */ static void metric_test(void) { int i, j; int retval; int component; struct eventmap_t * EventSet[VT_METRIC_MAXNUM]; for (i=0; i<VT_METRIC_MAXNUM; i++) EventSet[i] = NULL; for (i=0; i < nmetrics; i++) { #ifdef PAPIC /* Preset-counter belong to Component 0! */ component = PAPI_COMPONENT_INDEX(metricv[i]->papi_code); #else component = 0; #endif /* search for the eventset that matches the counter */ j=0; while (EventSet[j]!=NULL && j < VT_METRIC_MAXNUM && EventSet[j]->ComponentId!=component){ j++; } if (EventSet[j]==NULL) /* create eventset, if no matching found */ { EventSet[j] = malloc(sizeof(eventmap_t)); EventSet[j]->EventId=PAPI_NULL; retval = PAPI_create_eventset(&(EventSet[j]->EventId)); if ( retval != PAPI_OK) metric_error(retval, "PAPI_create_eventset"); EventSet[j]->ComponentId=component; } /* add event to event set */ retval = PAPI_add_event(EventSet[j]->EventId, metricv[i]->papi_code); if ( retval != PAPI_OK ) { char errstring[PAPI_MAX_STR_LEN]; sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name); metric_error(retval, errstring); } vt_cntl_msg(2, "Event %s added to event set", metricv[i]->name); } /* foreach used eventset */ for (i=0; i < VT_METRIC_MAXNUM && EventSet[i]!=NULL; i++) { retval = PAPI_cleanup_eventset(EventSet[i]->EventId); if ( retval != PAPI_OK ) metric_error(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&(EventSet[i]->EventId)); if ( retval != PAPI_OK ) metric_error(retval, "PAPI_destroy_eventset"); free(EventSet[i]); } vt_cntl_msg(2, "Event set tested OK"); }
static int check_event( int event_code, char *name ) { int retval; char errstring[PAPI_MAX_STR_LEN]; long long values; int EventSet = PAPI_NULL; /* Is there an issue with older machines? */ /* Disable for now, add back once we can reproduce */ // if ( PENTIUM4 ) { // if ( strcmp( name, "REPLAY_EVENT:BR_MSP" ) == 0 ) { // return 1; // } // } retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_add_event( EventSet, event_code ); if ( retval != PAPI_OK ) { printf( "Error adding %s\n", name ); return 0; } else { // printf( "Added %s successfully ", name ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error starting %s : %s\n", name, errstring ); } else { retval = PAPI_stop( EventSet, &values ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error stopping %s: %s\n", name, errstring ); return 0; } else { printf( "Added and Stopped %s successfully.\n", name ); } } retval=PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } retval=PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_destroy_eventset", retval); } return ( 1 ); }
void * my_thread( void *v ) { long num = ( long ) v; int n; int EventSet = PAPI_NULL; long long value; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); pthread_setspecific( key, v ); count[num] = 0; iter[num] = 0; last[num] = start; if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 ); if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 ); if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 ); if ( PAPI_start( EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 ); printf( "launched timer in thread %ld\n", num ); for ( n = 1; n <= program_time; n++ ) { do_cycles( num, 1 ); print_rate( num ); } PAPI_stop( EventSet, &value ); retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval ); if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 ); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 ); if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 ); return ( NULL ); }
static int add_remove_event(int EventSet, int evt) { int retval; if((retval=PAPI_add_event(EventSet, evt)) != PAPI_OK) { printf("Error adding event.\n"); } else { if((retval=PAPI_remove_event(EventSet,evt))!=PAPI_OK) printf("Error removing event.\n"); } return(retval); }
void init_test(int SoftwareMPX, int KernelMPX, int* Events) { int i; int retval; PAPI_option_t option, itimer; if ( ( retval = PAPI_assign_eventset_component( SoftwareMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_assign_eventset_component( KernelMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_set_multiplex( KernelMPX ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); PAPI_get_opt(PAPI_DEF_ITIMER,&itimer); memset(&option,0x0,sizeof(option)); option.multiplex.flags = PAPI_MULTIPLEX_FORCE_SW; option.multiplex.eventset = SoftwareMPX; option.multiplex.ns = itimer.itimer.ns; PAPI_set_opt( PAPI_MULTIPLEX, &option ); for (i = 0; i < options.min - 1; i++) { if ( options.kernel_mpx ) { if ( ( retval = PAPI_add_event( KernelMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } if ( options.force_sw ) { if ( ( retval = PAPI_add_event( SoftwareMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } } }
void start_EVENTPAPI(int ind, int EventCode) { /* Create the Event Set */ if (PAPI_create_eventset(&oscrData_timerPAPIEventSet[ind]) != PAPI_OK) OSCR_error("PAPI create eventset error!\n", -1); /* Add Total Instructions Executed to our EventSet */ if (PAPI_add_event(&oscrData_timerPAPIEventSet[ind], EventCode) != PAPI_OK) OSCR_error("PAPI add events error!\n", -1); if (PAPI_start(oscrData_timerPAPIEventSet[ind]) != PAPI_OK) OSCR_error("PAPI start init error!\n", -1); }
/* CheckInOrder Check if we can add all the counters in the order given. This will just iterate through all counters trying to add them in the eventset. */ void CheckInOrder (int ncounters, unsigned *counters) { int rc; int i; int naddedcounters; int EventSet = PAPI_NULL; char EventName[PAPI_MAX_STR_LEN]; #if 0 fprintf (stdout, "\n** Checking in order the following counters: "); for (i = 0; i < ncounters; i++) { rc = PAPI_event_code_to_name (counters[i], EventName); if (rc == PAPI_OK) fprintf (stdout, "%s%s", i>0?",":"", EventName); else fprintf (stdout, "%s%08x", i>0?",":"", counters[i]); } fprintf (stdout, "\n"); #endif if (PAPI_create_eventset(&EventSet) != PAPI_OK) { fprintf (stderr, "Error! Failed to create the eventset!\n"); return; } fprintf (stdout, "Suggested compatible counters preserving the given priority:\n"); for (naddedcounters = 0, i = 0; i < ncounters; i++) { if (PAPI_add_event (EventSet, counters[i]) == PAPI_OK) { rc = PAPI_event_code_to_name (counters[i], EventName); if (rc == PAPI_OK) fprintf (stdout, "%s%s", i>0?",":"", EventName); else fprintf (stdout, "%s%08x", i>0?",":"", counters[i]); naddedcounters++; } } if (naddedcounters > 0) fprintf (stdout, " (set of %d counters)\n\n", naddedcounters); else fprintf (stdout, "NONE!\n\n"); if (PAPI_cleanup_eventset(EventSet) != PAPI_OK) fprintf (stderr, "Error! Failed to cleanup the eventset\n"); if (PAPI_destroy_eventset (&EventSet) != PAPI_OK) fprintf (stderr, "Error! Failed to destroy the eventset\n"); }
perf_t* perf_init() { int retval; int EventSet = PAPI_NULL; retval = PAPI_create_eventset(&EventSet); assert(retval == PAPI_OK); retval = PAPI_assign_eventset_component(EventSet, 0); assert(retval == PAPI_OK); /* By default, the counter is inherited. */ PAPI_option_t opt; memset(&opt, 0x0, sizeof(PAPI_option_t)); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = EventSet; retval = PAPI_set_opt(PAPI_INHERIT, &opt); assert(retval == PAPI_OK); /* Add events by names */ for (int i = 0; i < NUM_EVENTS; i++) { int EventCode; if ((retval = PAPI_event_name_to_code(PERF_EVENT_NAMES[i], &EventCode)) != PAPI_OK) { fprintf(stderr, "Event name %s not found, skipped.\n", PERF_EVENT_NAMES[i]); continue; } if ((retval = PAPI_query_event(EventCode)) != PAPI_OK) { fprintf(stderr, "Event %s not supported on this hardware, skipped.\n", PERF_EVENT_NAMES[i]); continue; } if ((retval = PAPI_add_event(EventSet, EventCode)) != PAPI_OK) { assert(retval == PAPI_ECNFLCT); fprintf(stderr, "%s conflicts, skipped.\n", PERF_EVENT_NAMES[i]); } } perf_t *perf = (perf_t*)malloc(sizeof(perf_t)); perf->EventSet = EventSet; /* perf->values = (counter_t*)malloc(sizeof(counter_t) * NUM_EVENTS); */ /* memset(perf->values, 0x0, sizeof(counter_t) * NUM_EVENTS); */ return perf; }
void Timing::setPapiEvents(std::vector<std::string> names){ #ifdef KRIPKE_USE_PAPI static bool papi_initialized = false; if(!papi_initialized){ //printf("PAPI INIT\n"); int retval = PAPI_library_init(PAPI_VER_CURRENT); papi_initialized = true; if(retval != PAPI_VER_CURRENT){ fprintf(stderr, "ERROR INITIALIZING PAPI\n"); exit(1); } } //printf("PAPI VERSION=%x\n", // PAPI_VERSION); papi_set = PAPI_NULL; PAPI_create_eventset(&papi_set); for(int i = 0;i < names.size();++ i){ // Convert text string to PAPI id int event_code; PAPI_event_name_to_code( const_cast<char*>(names[i].c_str()), &event_code); // TODO: error checking? // Add to our list of PAPI events papi_names.push_back(names[i]); papi_event.push_back(event_code); int retval = PAPI_add_event(papi_set, event_code); if(retval != PAPI_OK){ fprintf(stderr, "ERROR ADDING %s, retval=%d, ID=0x%-10x\n", names[i].c_str(), retval, event_code); } //printf("EVT=%s, ID=0x%-10x\n", names[i].c_str(), event_code); } PAPI_start(papi_set); #else if(names.size() > 0){ fprintf(stderr, "WARNING: PAPI NOT ENABLED, IGNORING PAPI EVENTS\n"); } #endif }
struct esd_metv* esd_metric_create() { struct esd_metv* metv; int retval, i, /* KF */ comp; if ( nmetrics == 0 ) return NULL; metv = malloc(sizeof(struct esd_metv)); if ( metv == NULL ) elg_error(); /* create event set */ /* KF: create one per component */ for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { metv->EventSet[i] = PAPI_NULL; metv->NumEvents[i] = 0; retval = PAPI_create_eventset(&metv->EventSet[i]); if ( retval != PAPI_OK) esd_metric_error(retval, "PAPI_create_eventset"); } for ( i = 0; i < nmetrics; i++ ) { /* add event to event set */ /* KF: figure out the right component and track mapping*/ comp = PAPI_COMPONENT_INDEX( metricv[i]->papi_code ); metv->Comp2Metr[comp][metv->NumEvents[comp]]=i; retval = PAPI_add_event(metv->EventSet[comp], metricv[i]->papi_code); if ( retval != PAPI_OK ) esd_metric_error(retval, "PAPI_add_event"); else /* KF: success */ metv->NumEvents[comp]++; } /* KF: start only those event sets with events added */ for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { if( metv->NumEvents[i]>0 ) { retval = PAPI_start(metv->EventSet[i]); if ( retval != PAPI_OK ) esd_metric_error(retval, "PAPI_start"); } } elg_cntl_msg("Counters started"); return metv; }
int MBStartPAPI(void) { system("rm -f *.mbo"); #ifdef EXETIME gettimeofday(&MB_Start, NULL); #else MB_EventSet = PAPI_NULL; PAPI_library_init(PAPI_VER_CURRENT); PAPI_create_eventset(&MB_EventSet); PAPI_add_event(MB_EventSet, PAPI_TOT_CYC); PAPI_start(MB_EventSet); #endif return 0; }
void start_record_cache_access() { int retVal = PAPI_library_init(PAPI_VER_CURRENT); assert(retVal == PAPI_VER_CURRENT); EventSet = PAPI_NULL; retVal = PAPI_create_eventset(&g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_add_event(g_event_set, PAPI_L1_TCM); assert(retVal == PAPI_OK); retVal = PAPI_start(g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_read(g_event_set, startRecords); assert(retVal == PAPI_OK); }
void event_create_eventList(int *eventSet, int eventCodeSetSize, int *eventCodeSet, int threadID) { int retval, i, maxNumberHwCounters, eventCodeSetMaxSize; PAPI_event_info_t info; maxNumberHwCounters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ); printf("Max number of hardware counters = %d \n", maxNumberHwCounters); eventCodeSetMaxSize = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); printf("Max number of multiplexed counters = %d \n", eventCodeSetMaxSize); if ( eventCodeSetMaxSize < eventCodeSetSize) test_fail( __FILE__, __LINE__, "eventCodeSetMaxSize < eventCodeSetSize, too many performance events defined! ", retval ); retval = PAPI_register_thread(); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); retval = PAPI_create_eventset( eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_assign_eventset_component( *eventSet, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); retval = PAPI_set_multiplex( *eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); for (i = 0; i < eventCodeSetSize; i++) { retval = PAPI_get_event_info(eventCodeSet[i], &info); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); retval = PAPI_add_event( *eventSet, info.event_code); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); else printf("Adding %s \n", info.symbol); } printf("event_create_eventList done \n"); }
void inline papi_init() { int papi_version = PAPI_library_init(PAPI_VER_CURRENT); check(papi_version != PAPI_VER_CURRENT && papi_version > 0, ERR_PAPI_INIT); check(papi_version < 0, ERR_PAPI_INIT2); event_set = PAPI_NULL; papi_safe(PAPI_create_eventset(&event_set), ERR_PAPI_EVENT_SET); //PAPI_event_info_t inf; papi_safe(PAPI_get_event_info(papi_events[current_event], &inf),ERR_PAPI_GET_EVENT_INFO); papi_safe(PAPI_add_event(event_set, papi_events[current_event]), ERR_PAPI_ADD_EVENT); start_time = PAPI_get_virt_usec(); }
int main() { /*@ prologue @*/ long long orio_total_cycles = 0; long long orio_avg_cycles; int orio_i; for (orio_i=0; orio_i<REPS; orio_i++) { int err, EventSet = PAPI_NULL; long long CtrValues[1]; err = PAPI_library_init(PAPI_VER_CURRENT); if (err != PAPI_VER_CURRENT) { printf("PAPI library initialization error!\n"); exit(1); } if (PAPI_create_eventset(&EventSet) != PAPI_OK) { printf("Failed to create PAPI Event Set\n"); exit(1); } if (PAPI_query_event(PAPI_TOT_CYC) == PAPI_OK) err = PAPI_add_event(EventSet, PAPI_TOT_CYC); if (err != PAPI_OK) { printf("Failed to add PAPI event\n"); exit(1); } PAPI_start(EventSet); /*@ tested code @*/ PAPI_stop(EventSet, &CtrValues[0]); orio_total_cycles += CtrValues[0]; } orio_avg_cycles = orio_total_cycles / REPS; printf("%ld\n", orio_avg_cycles); printf("{'/*@ coordinate @*/' : %ld}", orio_avg_cycles); /*@ epilogue @*/ return y[0]; // to avoid the dead code elimination }
void flops_init() { #ifdef HAVE_PAPI int err = PAPI_library_init( PAPI_VER_CURRENT ); if ( err != PAPI_VER_CURRENT ) { fprintf( stderr, "Error: PAPI couldn't initialize: %s (%d)\n", PAPI_strerror(err), err ); } // read flops err = PAPI_create_eventset( &gPAPI_flops_set ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_create_eventset failed\n" ); } err = PAPI_assign_eventset_component( gPAPI_flops_set, 0 ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_assign_eventset_component failed: %s (%d)\n", PAPI_strerror(err), err ); } PAPI_option_t opt; memset( &opt, 0, sizeof(PAPI_option_t) ); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = gPAPI_flops_set; err = PAPI_set_opt( PAPI_INHERIT, &opt ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_set_opt failed: %s (%d)\n", PAPI_strerror(err), err ); } err = PAPI_add_event( gPAPI_flops_set, PAPI_FP_OPS ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_add_event failed: %s (%d)\n", PAPI_strerror(err), err ); } err = PAPI_start( gPAPI_flops_set ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_start failed: %s (%d)\n", PAPI_strerror(err), err ); } #endif // HAVE_PAPI }