void dump_avail(char * (*get_avail(unsigned *))) { unsigned n_avail, i; char *ptr, ** avail = get_avail(&n_avail); int eventcode = PAPI_NULL, retval; PAPI_event_info_t info; for(i=0;i<n_avail;i++){ if(get_avail == get_native_avail_papi_counters || get_avail == get_preset_avail_papi_counters){ PAPI_event_name_to_code(avail[i],&eventcode); PAPI_get_event_info(eventcode, &info); printf("\t%s%*s, %s\n",info.symbol, (int)(40-strlen(info.symbol))," ", info.long_descr); if(get_avail == get_native_avail_papi_counters && PAPI_enum_event(&eventcode, PAPI_NTV_ENUM_UMASKS) == PAPI_OK){ printf("\t\t%s%*s, %s\n","Masks", (int)(20-strlen("Masks"))," ", "Mask description"); do{ retval = PAPI_get_event_info(eventcode, &info); if (retval == PAPI_OK){ if(parse_unit_masks(&info)){ printf("\t\t%s%*s, %s\n",info.symbol, (int)(20-strlen(info.symbol))," ",info.long_descr); } } } while ( PAPI_enum_event( &eventcode, PAPI_NTV_ENUM_UMASKS) == PAPI_OK ); } } else printf("%s\n",avail[i]); free(avail[i]); } free(avail); }
void decide_which_events(int *events, int *nevents) { int i, j = 0; PAPI_event_info_t info; int newevents[MAXEVENTS]; for (i = 0; i < MAXEVENTS; i++) { if (PAPI_get_event_info(events[i], &info) == PAPI_OK) { if (info.count && (strcmp(info.derived,"NOT_DERIVED") == 0)) { printf("Added %s\n", info.symbol); newevents[j++] = events[i]; } } } if (j < 2) test_skip(__FILE__, __LINE__, "Not enough events to multiplex...", 0); *nevents = j; memcpy(events,newevents,sizeof(newevents)); printf("Using %d events\n\n",*nevents); }
void GPTL_PAPIprintenabled (FILE *fp) { int n, nn; PAPI_event_info_t info; /* returned from PAPI_get_event_info */ char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ if (nevents > 0) { fprintf (fp, "Description of printed events (PAPI and derived):\n"); for (n = 0; n < nevents; n++) { if (strncmp (pr_event[n].event.namestr, "GPTL", 4) == 0) { fprintf (fp, " %s: %s\n", pr_event[n].event.namestr, pr_event[n].event.longstr); } else { nn = pr_event[n].event.counter; if (PAPI_get_event_info (nn, &info) == PAPI_OK) { fprintf (fp, " %s\n", info.short_descr); fprintf (fp, " %s\n", info.note); } } } fprintf (fp, "\n"); fprintf (fp, "PAPI events enabled (including those required for derived events):\n"); for (n = 0; n < npapievents; n++) if (PAPI_event_code_to_name (papieventlist[n], eventname) == PAPI_OK) fprintf (fp, " %s\n", eventname); fprintf (fp, "\n"); } }
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; }
/* Get metric descriptions */ static void metric_descriptions(void) { int i, j, k, retval; PAPI_event_info_t info; for (i=0; i < nmetrics; i++) { memset(&info, 0, sizeof(PAPI_event_info_t)); retval = PAPI_get_event_info(metricv[i]->papi_code, &info); if (retval != PAPI_OK) metric_error(retval, "PAPI_get_event_info"); if (strcmp(info.long_descr, metricv[i]->name) != 0) { strncpy(metricv[i]->descr, info.long_descr, sizeof(metricv[i]->descr)); /* tidy description if necessary */ j=strlen(metricv[i]->descr)-1; if (metricv[i]->descr[j] == '\n') metricv[i]->descr[j]='\0'; j=strlen(metricv[i]->descr)-1; if (metricv[i]->descr[j] != '.') strncat(metricv[i]->descr, ".", sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); } if (metricv[i]->papi_code & PAPI_PRESET_MASK) { /* PAPI preset */ char *postfix_chp = info.postfix; char derive_ch = strcmp(info.derived,"DERIVED_SUB")?'+':'-'; strncat(metricv[i]->descr, " [ ", sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); strncat(metricv[i]->descr, info.name[0], sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); for (k=1; k<(int)info.count; k++) { char op[4]; postfix_chp = postfix_chp?strpbrk(++postfix_chp, "+-*/"):NULL; sprintf(op, " %c ", (postfix_chp?*postfix_chp:derive_ch)); strncat(metricv[i]->descr, op, sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); strncat(metricv[i]->descr, info.name[k], sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); } strncat(metricv[i]->descr, " ]", sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); if (strcmp(info.symbol, metricv[i]->name) != 0) { /* add preset name */ strncat(metricv[i]->descr, " = ", sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); strncat(metricv[i]->descr, info.symbol, sizeof(metricv[i]->descr)-strlen(metricv[i]->descr)); } } /*printf("Metric %d: <%s>\n<<%s>>\n", i, metricv[i]->name, metricv[i]->descr);*/ } }
void check_events(int *events, int nb_events) { int i, retval; if ( nb_events > PAPI_num_counters() ) { fprintf(stderr, "Too many counters: %d\nMaximum available %d\n", nb_events, PAPI_num_counters()); } for (i=0; i < nb_events; i++) { if ( (retval = PAPI_query_event(events[i])) != PAPI_OK) { PAPI_event_info_t info; PAPI_get_event_info(events[i], &info); fprintf(stderr,"No instruction counter for \"%s\" event\n%s\n", info.short_descr, PAPI_strerror(retval)); } } }
// Stops the papi counters and prints results void counter_stop( int * eventset, int num_papi_events ) { int * events = malloc(num_papi_events * sizeof(int)); int n = num_papi_events; PAPI_list_events( *eventset, events, &n ); PAPI_event_info_t info; long_long * values = malloc( num_papi_events * sizeof(long_long)); PAPI_stop(*eventset, values); int thread = omp_get_thread_num(); static long long accum_vals[5] = {0}; #pragma omp critical (papi) { printf("Thread %d\n", thread); for( int i = 0; i < num_papi_events; i++ ) { accum_vals[i] += values[i]; PAPI_get_event_info(events[i], &info); printf("%-15lld\t%s\t%s\n", values[i],info.symbol,info.long_descr); } } { #pragma omp barrier } #pragma omp master { printf("Aummulated totals!\n"); for( int i = 0; i < num_papi_events; i++ ) { PAPI_get_event_info(events[i], &info); printf("%-15lld\t%s\n", accum_vals[i], info.symbol); } printf("GFLOPs: %lf\n", (double)accum_vals[0] / (double)accum_vals[1] * 32.); } free(events); free(values); }
int main(int argc, char **argv) { int i,j; int retval; int print_avail_only = 0; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ for (i = 0; i < argc; i++) if (argv[i]) { if (strstr(argv[i], "-a")) print_avail_only = PAPI_PRESET_ENUM_AVAIL; if (strstr(argv[i], "-h")) { print_help(); exit(1); } } retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if (!TESTS_QUIET) { retval = PAPI_set_debug(PAPI_VERB_ECONT); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval); } if ((hwinfo = PAPI_get_hardware_info()) == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); i = PAPI_PRESET_MASK; printf("name,derived,postfix,short_descr,long_descr,note,[native,...]\n\n"); do { if (PAPI_get_event_info(i, &info) == PAPI_OK) { printf("%s,%s,%s,", info.symbol, info.derived, info.postfix); if (info.short_descr[0]) { printf("\"%s\",", info.short_descr); } else { printf(","); } if (info.long_descr[0]) { printf("\"%s\",", info.long_descr); } else { printf(","); } if (info.note[0]) printf("\"%s\"", info.note); for (j=0;j<(int)info.count;j++) printf(",%s",info.name[j]); printf("\n"); } } while (PAPI_enum_event(&i, print_avail_only) == PAPI_OK); exit(1); }
void check_events(int *events, int nb_events) { int i; //if ( nb_events > PAPI_num_counters() ) { // fprintf(stderr, "Too many counters: %d\nMaximum available %d\n", nb_events, PAPI_num_counters()); // exit(1); //} for (i=0; i < nb_events; i++) { if (PAPI_query_event(events[i]) != PAPI_OK) { PAPI_event_info_t info; PAPI_get_event_info(events[i], &info); fprintf(stderr,"No instruction counter for \"%s\" event\n", info.short_descr); exit(1); } } }
int is_event_derived(unsigned int event) { PAPI_event_info_t info; if (event & PAPI_PRESET_MASK) { PAPI_get_event_info(event,&info); if (strcmp(info.derived,"NOT_DERIVED")) { // printf("%x is derived\n",event); return 1; } } return 0; }
int add_two_events( int *num_events, int *papi_event, int *mask ) { /* query and set up the right event to monitor */ int EventSet = PAPI_NULL; PAPI_event_info_t info; unsigned int potential_evt_to_add[3][2] = { {( unsigned int ) PAPI_FP_INS, MASK_FP_INS}, {( unsigned int ) PAPI_FP_OPS, MASK_FP_OPS}, {( unsigned int ) PAPI_TOT_INS, MASK_TOT_INS} }; int i = 0; int counters, event_found = 0; *mask = 0; counters = PAPI_num_hwctrs( ); if (counters<=0) { test_fail(__FILE__,__LINE__,"Zero Counters Available! PAPI Won't like this!\n",0); } /* This code tries to ensure that the event generated will fit in the */ /* number of available counters. It doesn't account for the number */ /* of counters used by the cycle counter. */ for(i=0;i<3;i++) { if ( PAPI_query_event( (int) potential_evt_to_add[i][0] ) == PAPI_OK ) { if ( PAPI_get_event_info( (int) potential_evt_to_add[i][0], &info ) == PAPI_OK ) { if ( ( info.count > 0 ) && ( (unsigned) counters > info.count ) ) { event_found = 1; break; } } } } if ( event_found ) { *papi_event = ( int ) potential_evt_to_add[i][0]; *mask = ( int ) potential_evt_to_add[i][1] | MASK_TOT_CYC; EventSet = add_test_events( num_events, mask, 1 ); } else { test_fail( __FILE__, __LINE__, "Not enough room to add an event!", 0 ); } return EventSet; }
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(); }
static int show_event_info( int evt ) { int k; int retval; PAPI_event_info_t info; if ( ( retval = PAPI_get_event_info( evt, &info ) ) == PAPI_OK ) { printf( "%s\t0x%x\n |%s|\n", info.symbol, info.event_code, info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) if ( strlen( info.name[k] ) ) printf( " |Register Value[%d]: 0x%-10x %s|\n", k, info.code[k], info.name[k] ); } return ( retval ); }
int find_nonderived_event( void ) { /* query and set up the right event to monitor */ PAPI_event_info_t info; int potential_evt_to_add[3] = { PAPI_FP_OPS, PAPI_FP_INS, PAPI_TOT_INS }; int i; for ( i = 0; i < 3; i++ ) { if ( PAPI_query_event( potential_evt_to_add[i] ) == PAPI_OK ) { if ( PAPI_get_event_info( potential_evt_to_add[i], &info ) == PAPI_OK ) { if ( ( info.count > 0 ) && !strcmp( info.derived, "NOT_DERIVED" ) ) return ( potential_evt_to_add[i] ); } } } return ( 0 ); }
void ref_measurements(int iters, int *eventset, int *events, int nevents, long long *refvalues) { PAPI_event_info_t info; int i, retval; double x = 1.1, y; long long t1, t2; printf("PAPI reference measurements:\n"); if ((retval = PAPI_create_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(*eventset, events[i]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); x = 1.0; t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(*eventset, &refvalues[i]))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); #if 0 printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); #endif PAPI_get_event_info(events[i], &info); printf("%20s = ", info.short_descr); printf(LLDFMT, refvalues[i]); printf("\n"); if ((retval = PAPI_cleanup_eventset(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } if ((retval = PAPI_destroy_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); *eventset = PAPI_NULL; }
void check_values(int eventset, int *events, int nevents, long long *values, long long *refvalues) { double spread[MAXEVENTS]; int i = nevents, j = 0; if (!TESTS_QUIET) { printf("\nRelative accuracy:\n"); for (j = 0; j < nevents; j++) printf(" Event %.2d", j+1); printf("\n"); } for (j = 0; j < nevents; j++) { spread[j] = abs((int)(refvalues[j] - values[j])); if (values[j]) spread[j] /= (double) values[j]; if (!TESTS_QUIET) printf("%10.3g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) i--; else if (refvalues[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ i--; } printf("\n\n"); #if 0 if (!TESTS_QUIET) { for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); printf("Event %.2d: ref=", j); printf(LLDFMT10, refvalues[j]); printf(", diff/ref=%7.2g -- %s\n", spread[j], info.short_descr); printf("\n"); } printf("\n"); } #endif if (i) test_fail(__FILE__, __LINE__, "Values outside threshold", i); }
// // This method should be placed at the end of instrumented code // void stopPapiCounters(){ #ifdef DBG printf("********* STOPING COUNTERS *************\n"); #endif long long _G_COUNTERS[NUM_EVENTS]; int i; //******* Stop Counters ****** assert(PAPI_stop_counters(_G_COUNTERS, NUM_EVENTS) >= PAPI_OK); // get the counter information for each event. // currently printing on stdout. for( i = 0; i < NUM_EVENTS; ++i ) { PAPI_event_info_t info; PAPI_get_event_info(_G_EVENTS[i], &info); #ifdef DBG printf("%20lld %-15s %s\n", _G_COUNTERS[i], info.symbol, info.long_descr); #else fprintf(stderr, "%lld ", _G_COUNTERS[i]); #endif } }
void printAllAvailableCounters(){ // initialize papi library and assert that it's successful assert( PAPI_library_init( PAPI_VER_CURRENT ) == PAPI_VER_CURRENT ); // print header printf( "--- Available events ---\n" ); printf( "%-15s %s\n", "Name", "Description" ); // loop through all PAPI events supported on this plattform int event = 0 | PAPI_PRESET_MASK; // the first event do { // ignore unsupported events if ( PAPI_query_event( event ) != PAPI_OK ) continue; // get event info PAPI_event_info_t info; (void) PAPI_get_event_info( event, &info); // print printf( "%-15s %s\n", info.symbol, info.long_descr ); } while ( PAPI_enum_event( &event, PAPI_ENUM_ALL ) == PAPI_OK ); }
// Stops the papi counters and prints results void counter_stop( int * eventset, int num_papi_events ) { int * events = malloc(num_papi_events * sizeof(int)); int n = num_papi_events; PAPI_list_events( *eventset, events, &n ); PAPI_event_info_t info; long_long * values = malloc( num_papi_events * sizeof(long_long)); PAPI_stop(*eventset, values); int thread = omp_get_thread_num(); #pragma omp critical (papi) { printf("Thread %d\n", thread); for( int i = 0; i < num_papi_events; i++ ) { PAPI_get_event_info(events[i], &info); printf("%-15lld\t%s\t%s\n", values[i],info.symbol,info.long_descr); } free(events); free(values); } }
void check_map_event_obj(hwloc_topology_t topology, char * obj_name, char * event_name) { PAPI_event_info_t info; int err, eventcode; hwloc_obj_t obj; unsigned depth = hwloc_get_obj_depth_by_name(topology,obj_name); if((err = PAPI_event_name_to_code(event_name,&eventcode))!=PAPI_OK){ handle_error(err); fprintf(stderr,"could not get \"%s\" event infos\n",event_name); } PAPI_get_event_info(eventcode,&info); switch(info.location){ case PAPI_LOCATION_UNCORE: if(depth >= hwloc_get_type_depth(topology, HWLOC_OBJ_CORE)){ fprintf(stderr,"event %s is an UNCORE event and is actually mapped on %s which is under HWLOC_OBJ_CORE\n", event_name, obj_name); } break; case PAPI_LOCATION_CPU: if(depth > hwloc_get_type_depth(topology, HWLOC_OBJ_MACHINE)){ fprintf(stderr,"event %s is a CPU event and is actually mapped on %s which is strictly under HWLOC_OBJ_MACHINE\n", event_name, obj_name); } break; case PAPI_LOCATION_PACKAGE: if(depth > hwloc_get_type_depth(topology, HWLOC_OBJ_SOCKET)){ fprintf(stderr,"event %s is a PACKAGE event and is actually mapped on %s which is strictly under HWLOC_OBJ_SOCKET\n", event_name, obj_name); } break; default: break; } }
int main( int argc, char **argv ) { int nthreads = 8, ret, i; PAPI_event_info_t info; pthread_t *threads; const PAPI_hw_info_t *hw_info; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( !TESTS_QUIET ) { if ( argc > 1 ) { int tmp = atoi( argv[1] ); if ( tmp >= 1 ) nthreads = tmp; } } ret = PAPI_library_init( PAPI_VER_CURRENT ); if ( ret != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", ret ); } hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) { ret = PAPI_set_domain( PAPI_DOM_ALL ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret ); } } ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret ); } ret = PAPI_multiplex_init( ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret ); } /* Fill up the event set with as many non-derived events as we can */ i = PAPI_PRESET_MASK; do { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { if ( info.count == 1 ) { events[numevents++] = ( int ) info.event_code; printf( "Added %s\n", info.symbol ); } else { printf( "Skipping derived event %s\n", info.symbol ); } } } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) && ( numevents < PAPI_MPX_DEF_DEG ) ); printf( "Found %d events\n", numevents ); do_stuff( ); printf( "Creating %d threads:\n", nthreads ); threads = ( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) ); if ( threads == NULL ) { test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM ); } /* Create the threads */ for ( i = 0; i < nthreads; i++ ) { ret = pthread_create( &threads[i], NULL, thread, NULL ); if ( ret != 0 ) { test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS ); } } /* Wait for thread completion */ for ( i = 0; i < nthreads; i++ ) { ret = pthread_join( threads[i], NULL ); if ( ret != 0 ) { test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS ); } } printf( "Done." ); test_pass( __FILE__, NULL, 0 ); pthread_exit( NULL ); exit( 0 ); }
int vt_metric_open() { int retval; char* env; char* env_sep; char* var; char* token; char* saveptr; PAPI_event_info_t info; metricmap_t* mapv = NULL; metricmap_t* map; /* read environment variable "VT_METRICS". Return if uset and no PAPI timer used. */ env = vt_env_metrics(); if( env == NULL ) { #if TIMER != TIMER_PAPI_REAL_CYC && TIMER != TIMER_PAPI_REAL_USEC return nmetrics; #endif } env_sep = vt_env_metrics_sep(); mapv = vt_metricmap_init( (metmap_t)(METMAP_MEASURE|METMAP_AGGROUP)); metricmap_dump(mapv); /* initialize PAPI */ retval = PAPI_library_init(PAPI_VER_CURRENT); if ( retval != PAPI_VER_CURRENT ) metric_error(retval, "PAPI_library_init"); /* return if environment variable is unset */ if ( env == NULL ) return nmetrics; var = strdup(env); vt_cntl_msg(2, "VT_METRICS=%s", var); /* read metrics from specification string */ token = strtok_r(var, env_sep, &saveptr); while ( token && (nmetrics < VT_METRIC_MAXNUM) ) { /* set counter properties */ uint32_t props; if (token[0]=='!') { props = VT_CNTR_ABS | VT_CNTR_NEXT; token++; } else { props = VT_CNTR_ACC; } /* search metricmap for a suitable definition */ map = mapv; /*printf("Token%d: <%s>\n", nmetrics, token);*/ while (map != NULL) { if ( strcmp(map->event_name, token) == 0 ) { /*printf("Definition %s = <%s>\n", token, map->alias_name);*/ /* expand definition and set components */ char* c_token = map->alias_name; int len = strcspn(c_token, " \t"); /* first token */ int got_valid_match = 1; /* to be verified */ int k = 0; do { /* verify each component of definition is available */ char component[64]; int code = -1; strncpy(component, c_token, len); component[len] = '\0'; /*printf("Comp[%d] <%s>\n", k, component);*/ c_token += len + strspn(c_token+len, " \t"); len = strcspn(c_token, " \t"); /* next token */ PAPI_event_name_to_code(component, &code); memset(&info, 0, sizeof(PAPI_event_info_t)); retval = PAPI_get_event_info(code, &info); /*printf("v[%d] %s [0x%X] %d\n", k, component, code, info.count);*/ if (info.count == 0) { /*printf("Event %s *N/A*\n", component);*/ got_valid_match = 0; } else if ((k==0) && (len==0)) { /* use provided event name */ metricv_add(token, code, props); } else { /* use alias component name */ metricv_add(component, code, props); } k++; } while (got_valid_match && (len > 0)); if (got_valid_match) { /*printf("Definition %s = <%s> OK\n", map->event_name, map->alias_name);*/ break; /* accept this event definition */ } } map = map->next; } if (map == NULL) { /* no map match, so try given name */ int code = -1; char* component = token; /*printf("Comp[X] <%s>\n", component);*/ retval = PAPI_event_name_to_code(component, &code); if (retval != PAPI_OK || code == -1) vt_error_msg("Metric <%s> not supported\n", component); memset(&info, 0, sizeof(PAPI_event_info_t)); retval = PAPI_get_event_info(code, &info); /*printf("v[%d] %s [0x%X] %d\n", nmetrics, component, code, info.count);*/ if (retval != PAPI_OK) vt_error_msg("Metric <%s> not available\n", component); metricv_add(component, code, props); } token = strtok_r(NULL, env_sep, &saveptr); } /*printf("nmetrics=%d\n", nmetrics);*/ /* clean up */ metricmap_free(mapv); free(var); /* Check whether event combination is valid. This is done here to avoid errors when creating the event set for each thread, which would multiply the error messages. */ metric_test(); metric_descriptions(); return nmetrics; }
int main(int argc, char **argv) { int retval,max_multiplex,i,EventSet=PAPI_NULL; PAPI_event_info_t info; int added=0; int events_tried=0; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = PAPI_multiplex_init( ); if ( retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "Multiplex not supported", 1); } max_multiplex=PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); if (!TESTS_QUIET) { printf("Maximum multiplexed counters=%d\n",max_multiplex); } if (!TESTS_QUIET) { printf("Trying to multiplex as many as possible:\n"); } 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_create_multiplex", retval ); } i = 0 | PAPI_PRESET_MASK; PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); if (retval==PAPI_OK) { if (!TESTS_QUIET) printf("Adding %s: ",info.symbol); } retval = PAPI_add_event( EventSet, info.event_code ); if (retval!=PAPI_OK) { if (!TESTS_QUIET) printf("Fail!\n"); } else { if (!TESTS_QUIET) printf("Success!\n"); added++; } events_tried++; } while (PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ); PAPI_shutdown( ); if (!TESTS_QUIET) { printf("Added %d of theoretical max %d\n",added,max_multiplex); } if (events_tried<max_multiplex) { if (!TESTS_QUIET) { printf("Ran out of events before we ran out of room\n"); } } else if (added!=max_multiplex) { test_fail(__FILE__, __LINE__, "Couldn't max out multiplexed events", 1); } test_pass( __FILE__, NULL, 0 ); exit( 0 ); }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long *values; int num_events=0; int code; char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN]; char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN]; int r,i; const PAPI_component_info_t *cmpinfo = NULL; PAPI_event_info_t evinfo; long long before_time,after_time; double elapsed_time; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all RAPL events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"rapl")) { rapl_cid=cid; if (!TESTS_QUIET) { printf("Found rapl component at cid %d\n",rapl_cid); } if (cmpinfo->disabled) { if (!TESTS_QUIET) { printf("RAPL component disabled: %s\n", cmpinfo->disabled_reason); } test_skip(__FILE__,__LINE__,"RAPL component disabled",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } /* Add all events */ code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_names[num_events] ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } retval = PAPI_get_event_info(code,&evinfo); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "Error getting event info\n",retval); } strncpy(units[num_events],evinfo.units,PAPI_MIN_STR_LEN); retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { break; /* We've hit an event limit */ } num_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid ); } values=calloc(num_events,sizeof(long long)); if (values==NULL) { test_fail(__FILE__, __LINE__, "No memory",retval); } if (!TESTS_QUIET) { printf("\nStarting measurements...\n\n"); } /* Start Counting */ before_time=PAPI_get_real_nsec(); retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } /* Run test */ run_test(TESTS_QUIET); /* Stop Counting */ after_time=PAPI_get_real_nsec(); retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } elapsed_time=((double)(after_time-before_time))/1.0e9; if (!TESTS_QUIET) { printf("\nStopping measurements, took %.3fs, gathering results...\n\n", elapsed_time); printf("Energy measurements:\n"); for(i=0;i<num_events;i++) { if (strstr(units[i],"nJ")) { printf("%s\t%.6fJ\t(Average Power %.1fW)\n", event_names[i], (double)values[i]/1.0e9, ((double)values[i]/1.0e9)/elapsed_time); } } printf("\n"); printf("Fixed values:\n"); for(i=0;i<num_events;i++) { if (!strstr(units[i],"nJ")) { union { long long ll; double fp; } result; result.ll=values[i]; printf("%s\t%0.3f%s\n", event_names[i], result.fp, units[i]); } } } /* Done, clean up */ retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } test_pass( __FILE__, NULL, 0 ); return 0; }
int HWCBE_PAPI_Add_Set (int pretended_set, int rank, int ncounters, char **counters, char *domain, char *change_at_globalops, char *change_at_time, int num_overflows, char **overflow_counters, unsigned long long *overflow_values) { int i, rc, num_set = HWC_num_sets; PAPI_event_info_t info; #if !defined(PAPI_SAMPLING_SUPPORT) UNREFERENCED_PARAMETER(num_overflows); UNREFERENCED_PARAMETER(overflow_counters); UNREFERENCED_PARAMETER(overflow_values); #endif if (ncounters == 0 || counters == NULL) return 0; if (ncounters > MAX_HWC) { fprintf (stderr, PACKAGE_NAME": You cannot provide more HWC counters than %d (see set %d)\n", MAX_HWC, pretended_set); ncounters = MAX_HWC; } HWC_sets = (struct HWC_Set_t *) realloc (HWC_sets, sizeof(struct HWC_Set_t)* (HWC_num_sets+1)); if (HWC_sets == NULL) { fprintf (stderr, PACKAGE_NAME": Cannot allocate memory for HWC_set (rank %d)\n", rank); return 0; } /* Initialize this set */ HWC_sets[num_set].num_counters = 0; HWC_sets[num_set].eventsets = NULL; #if defined(PAPI_SAMPLING_SUPPORT) HWC_sets[num_set].OverflowCounter = NULL; HWC_sets[num_set].OverflowValue = NULL; HWC_sets[num_set].NumOverflows = 0; #endif for (i = 0; i < ncounters; i++) { /* counter_last_position will hold the address of the end of the counter[i] string This shall be compared with strtoul_check to know if the hex is correct or not */ char *counter_last_position = &(counters[i][strlen(counters[i])]); char *strtoul_check; HWC_sets[num_set].counters[HWC_sets[num_set].num_counters] = strtoul (counters[i], &strtoul_check, 16); if (strtoul_check != counter_last_position) { int EventCode; if (PAPI_event_name_to_code(counters[i], &EventCode) != PAPI_OK) { if (rank == 0) fprintf (stderr, PACKAGE_NAME": Cannot parse HWC %s in set %d, skipping\n", counters[i], pretended_set); } else { HWC_sets[num_set].counters[HWC_sets[num_set].num_counters] = EventCode; } } rc = PAPI_get_event_info (HWC_sets[num_set].counters[HWC_sets[num_set].num_counters], &info); if (rc != PAPI_OK) { if (rank == 0) fprintf (stderr, PACKAGE_NAME": Error! Cannot query information for hardware counter %s (0x%08x). Check set %d.\n", counters[i], HWC_sets[num_set].counters[HWC_sets[num_set].num_counters], pretended_set); HWC_sets[num_set].counters[HWC_sets[num_set].num_counters] = NO_COUNTER; } /* Native events seem that could have info.count = 0! */ else if (rc == PAPI_OK && info.count == 0 && (HWC_sets[num_set].counters[HWC_sets[num_set].num_counters] & PAPI_NATIVE_MASK) == 0) { if (rank == 0) fprintf (stderr, PACKAGE_NAME": Error! Hardware counter %s (0x%08x) is not available. Check set %d.\n", counters[i], HWC_sets[num_set].counters[HWC_sets[num_set].num_counters], pretended_set); HWC_sets[num_set].counters[HWC_sets[num_set].num_counters] = NO_COUNTER; } else { if (rank == 0) HWCBE_PAPI_AddDefinition (HWC_sets[num_set].counters[HWC_sets[num_set].num_counters], info.symbol, (info.event_code & PAPI_PRESET_MASK)?info.short_descr:info.long_descr); HWC_sets[num_set].num_counters++; } } if (HWC_sets[num_set].num_counters == 0) { if (rank == 0) fprintf (stderr, PACKAGE_NAME": Set %d of counters seems to be empty/invalid, skipping\n", pretended_set); return 0; } /* Just check if the user wants us to change the counters in some manner */ if (change_at_time != NULL) { HWC_sets[num_set].change_at = getTimeFromStr (change_at_time, "change-at-time", rank); HWC_sets[num_set].change_type = (HWC_sets[num_set].change_at == 0)?CHANGE_NEVER:CHANGE_TIME; } else if (change_at_globalops != NULL) { HWC_sets[num_set].change_at = strtoul (change_at_globalops, (char **) NULL, 10); HWC_sets[num_set].change_type = (HWC_sets[num_set].change_at == 0)?CHANGE_NEVER:CHANGE_GLOPS; } else HWC_sets[num_set].change_type = CHANGE_NEVER; if (domain != NULL) { if (!strcasecmp(domain, "all")) { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to ALL for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_ALL; } else if (!strcasecmp(domain, "kernel")) { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to KERNEL for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_KERNEL; } else if (!strcasecmp(domain, "user")) { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to USER for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_USER; } else if (!strcasecmp(domain, "other")) { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to OTHER for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_OTHER; } else { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to USER for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_USER; } } /* domain != NULL */ else { if (rank == 0) fprintf (stdout, PACKAGE_NAME": PAPI domain set to USER for HWC set %d\n", pretended_set); HWC_sets[num_set].domain = PAPI_DOM_USER; } HWCBE_PAPI_Allocate_eventsets_per_thread (num_set, 0, Backend_getNumberOfThreads()); /* We validate this set */ HWC_num_sets++; if (rank == 0) { fprintf (stdout, PACKAGE_NAME": HWC set %d contains following counters < ", pretended_set); for (i = 0; i < HWC_sets[num_set].num_counters; i++) { if (HWC_sets[num_set].counters[i] != NO_COUNTER) { char counter_name[PAPI_MAX_STR_LEN]; PAPI_event_code_to_name (HWC_sets[num_set].counters[i], counter_name); fprintf (stdout, "%s (0x%08x) ", counter_name, HWC_sets[num_set].counters[i]); } } fprintf (stdout, ">"); if (HWC_sets[num_set].change_type == CHANGE_TIME) fprintf (stdout, " - changing every %lld nanoseconds\n", HWC_sets[num_set].change_at); else if (HWC_sets[num_set].change_type == CHANGE_GLOPS) fprintf (stdout, " - changing every %lld global operations\n", HWC_sets[num_set].change_at); else fprintf (stdout, " - never changes\n"); fflush (stdout); } #if defined(PAPI_SAMPLING_SUPPORT) if (num_overflows > 0) Add_Overflows_To_Set (rank, num_set, pretended_set, num_overflows, overflow_counters, overflow_values); #endif return HWC_sets[num_set].num_counters; }
int main( int argc, char **argv ) { int retval; int num_events; long long *values; char *success; PAPI_event_info_t info; int EventSet = PAPI_NULL; int i, j, data_type, event; int u_format = 0; int hex_format = 0; 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 ); /* Automatically pass if no events, for run_tests.sh */ if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) { test_pass( __FILE__, NULL, 0 ); } values = ( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc ); success = ( char * ) malloc( ( size_t ) argc ); if ( success == NULL || values == NULL ) test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS ); for ( num_events = 0, i = 1; i < argc; i++ ) { if ( !strcmp( argv[i], "-h" ) ) { print_help( argv ); exit( 1 ); } else if ( !strcmp( argv[i], "-u" ) ) { u_format = 1; } else if ( !strcmp( argv[i], "-x" ) ) { hex_format = 1; } else { if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) { printf( "Failed adding: %s\nbecause: %s\n", argv[i], PAPI_strerror(retval)); } else { success[num_events++] = i; printf( "Successfully added: %s\n", argv[i] ); } } } /* Automatically pass if no events, for run_tests.sh */ if ( num_events == 0 ) { test_pass( __FILE__, NULL, 0 ); } printf( "\n" ); do_flops( 1 ); do_flush( ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) { test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); do_misses( 1, L1_MISS_BUFFER_SIZE_INTS ); if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); for ( j = 0; j < num_events; j++ ) { i = success[j]; if (! (u_format || hex_format) ) { retval = PAPI_event_name_to_code( argv[i], &event ); if (retval == PAPI_OK) { retval = PAPI_get_event_info(event, &info); if (retval == PAPI_OK) data_type = info.data_type; else data_type = PAPI_DATATYPE_INT64; } switch (data_type) { case PAPI_DATATYPE_UINT64: printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] ); break; case PAPI_DATATYPE_FP64: printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) ); j++; break; case PAPI_DATATYPE_BIT64: printf( "%s : \t0x%llX", argv[i], values[j] ); break; case PAPI_DATATYPE_INT64: default: printf( "%s : \t%lld", argv[i], values[j] ); break; } if (retval == PAPI_OK) printf( " %s", info.units ); printf( "\n" ); } if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] ); if (hex_format) printf( "%s : \t0x%llX\n", argv[i], values[j] ); } printf( "\n----------------------------------\n" ); printf ( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main( int argc, char **argv ) { int retval, i; int EventSet = PAPI_NULL, count = 0, err_count = 0; long long values; PAPI_event_info_t info; char errstring[PAPI_MAX_STR_LEN]; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) { if ( PAPI_get_event_info( PAPI_PRESET_MASK | i, &info ) != PAPI_OK ) continue; if ( !( info.count ) ) continue; printf( "Adding %-14s", info.symbol ); retval = PAPI_add_event( EventSet, ( int ) info.event_code ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error: %s\n", errstring ); err_count++; } else { retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error Starting: %s\n", errstring ); err_count++; } else { retval = PAPI_stop( EventSet, &values ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error Stopping: %s\n", errstring ); err_count++; } else { printf( "successful\n" ); count++; } } retval = PAPI_remove_event( EventSet, ( int ) info.event_code ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval ); } } retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); printf( "Successfully added, started and stopped %d events.\n", count ); if ( err_count ) printf( "Failed to add, start or stop %d events.\n", err_count ); if ( count > 0 ) test_pass( __FILE__, NULL, 0 ); else test_fail( __FILE__, __LINE__, "No events added", 1 ); exit( 1 ); }
int main( int argc, char **argv ) { int i, j = 0, k; int retval; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; command_flags_t flags; int enum_modifier; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize before parsing the input arguments */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Parse the command-line arguments */ parse_args( argc, argv, &flags ); /* Set enum modifier mask */ if ( flags.dear ) enum_modifier = PAPI_NTV_ENUM_DEAR; else if ( flags.darr ) enum_modifier = PAPI_NTV_ENUM_DARR; else if ( flags.iear ) enum_modifier = PAPI_NTV_ENUM_IEAR; else if ( flags.iarr ) enum_modifier = PAPI_NTV_ENUM_IARR; else if ( flags.opcm ) enum_modifier = PAPI_NTV_ENUM_OPCM; else enum_modifier = PAPI_ENUM_EVENTS; if ( !TESTS_QUIET ) { retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } } retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } /* Do this code if an event name was specified on the commandline */ if ( flags.named ) { if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { printf( "%-30s%s\n%-30s%d\n", "Event name:", info.symbol, "Number of Register Values:", info.count ); printf( "%-29s|%s|\n", "Description:", info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: |%s|\n", k, info.name[k] ); /* if unit masks exist but none specified, process all */ if ( !strchr( flags.name, ':' ) ) { if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { printf( "\nUnit Masks:\n" ); do { retval = PAPI_get_event_info( i, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) { printf( "%-29s|%s|%s|\n", " Mask Info:", info.symbol, info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: 0x%08x |%s|\n", k, info.code[k], info.name[k] ); } } } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } } } else { printf("Sorry, an event by the name '%s' could not be found.\n", flags.name); printf("Is it typed correctly?\n\n"); exit( 1 ); } } else { /* Print *ALL* available events */ numcmp = PAPI_num_components( ); j = 0; for ( cid = 0; cid < numcmp; cid++ ) { const PAPI_component_info_t *component; component=PAPI_get_component_info(cid); /* Skip if requested enumeration not available */ if (( flags.dear ) && !( component->cntr_DEAR_events )) { continue; } if (( flags.darr ) && !( component->data_address_range)) { continue; } if (( flags.iear ) && !( component->cntr_IEAR_events )) { continue; } if (( flags.iarr ) && !( component->instr_address_range )) { continue; } if (( flags.opcm ) && !( component->cntr_OPCM_events )) { continue; } printf( "===============================================================================\n" ); printf( " Events in Component: %s\n",component->name); printf( "===============================================================================\n" ); /* Always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); /* UGH PAPI_enum_event() really needs a component field */ PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { memset( &info, 0, sizeof ( info ) ); retval = PAPI_get_event_info( i, &info ); /* This event may not exist */ if ( retval != PAPI_OK ) continue; /* count only events that as supported by host cpu */ j++; print_event( &info, 0 ); /* Does this matter on anything but perfctr? */ if ( flags.details ) { for ( k = 0; k < ( int ) info.count; k++ ) { if ( strlen( info.name[k] ) ) { printf( " Register[%d] Name: %-20s Value: 0x%-28x|\n", k, info.name[k], info.code[k] ); } } } /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a groups id for each group in which this native event lives, in bits 16 - 23 of event code terminating with PAPI_ENOEVNT at the end of the list. */ /* This is an IBM Power issue */ if ( flags.groups ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) { printf( "Groups: " ); do { printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >> PAPI_NTV_GROUP_SHIFT ) - 1 ); } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK ); printf( "\n" ); } } /* Print umasks */ /* components that don't have them can just ignore */ if ( flags.umask ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) print_event( &info, 2 ); } } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } printf( "--------------------------------------------------------------------------------\n" ); } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK ); }
int main(int argc, char **argv) { PAPI_event_info_t info; int i, j, retval; int iters = 10000000; double x = 1.1, y; long long t1, t2; long long values[MAXEVENTS], refvalues[MAXEVENTS]; int sleep_time = SLEEPTIME; double valsqsum[MAXEVENTS]; double valsum[MAXEVENTS]; double spread[MAXEVENTS]; int nevents = MAXEVENTS; int eventset = PAPI_NULL; int events[MAXEVENTS]; events[0] = PAPI_BR_NTK; events[1] = PAPI_BR_PRC; events[2] = PAPI_BR_INS; events[3] = PAPI_BR_MSP; /* events[3]=PAPI_BR_CN; events[4]=PAPI_BR_UCN;*/ /*events[5]=PAPI_BR_TKN; */ for (i = 0; i < MAXEVENTS; i++) { values[i] = 0; valsqsum[i] = 0; valsum[i] = 0; } if (argc > 1) { if (!strcmp(argv[1], "TESTS_QUIET")) tests_quiet(argc, argv); else { sleep_time = atoi(argv[1]); if (sleep_time <= 0) sleep_time = SLEEPTIME; } } if (!TESTS_QUIET) { printf("\nAccuracy check of branch presets.\n"); printf("Comparing a measurement with separate measurements.\n\n"); } 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))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); #ifdef MPX if ((retval = PAPI_multiplex_init())) test_fail(__FILE__, __LINE__, "PAPI_multiplex_init", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); #endif nevents = 0; for (i = 0; i < MAXEVENTS; i++) { if (PAPI_query_event(events[i]) != PAPI_OK) continue; if (PAPI_add_event(eventset, events[i]) == PAPI_OK) { events[nevents] = events[i]; nevents++; } } if (nevents < 1) test_skip(__FILE__, __LINE__, "Not enough events left...", 0); /* Find a reasonable number of iterations (each * event active 20 times) during the measurement */ t2 = 10000 * 20 * nevents; /* Target: 10000 usec/multiplex, 20 repeats */ if (t2 > 30e6) test_skip(__FILE__, __LINE__, "This test takes too much time", retval); /* Measure one run */ t1 = PAPI_get_real_usec(); y = dummy3(x, iters); t1 = PAPI_get_real_usec() - t1; if (t2 > t1) /* Scale up execution time to match t2 */ iters = iters * (int)(t2 / t1); else if (t1 > 30e6) /* Make sure execution time is < 30s per repeated test */ test_skip(__FILE__, __LINE__, "This test takes too much time", retval); x = 1.0; if (!TESTS_QUIET) printf("\nFirst run: Together.\n"); t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(eventset, values))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); if (!TESTS_QUIET) { printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("PAPI grouped measurement:\n"); } for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) { printf("%20s = ", info.short_descr); printf(LLDFMT, values[j]); printf("\n"); } } if (!TESTS_QUIET) printf("\n"); if ((retval = PAPI_remove_events(eventset, events, nevents))) test_fail(__FILE__, __LINE__, "PAPI_remove_events", retval); if ((retval = PAPI_destroy_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); eventset = PAPI_NULL; if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); for (i = 0; i < nevents; i++) { if ((retval = PAPI_cleanup_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval); if ((retval = PAPI_add_event(eventset, events[i]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); x = 1.0; if (!TESTS_QUIET) printf("\nReference measurement %d (of %d):\n", i + 1, nevents); t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(eventset, &refvalues[i]))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); if (!TESTS_QUIET) { printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); } PAPI_get_event_info(events[i], &info); if (!TESTS_QUIET) { printf("PAPI results:\n%20s = ", info.short_descr); printf(LLDFMT, refvalues[i]); printf("\n"); } } if (!TESTS_QUIET) printf("\n"); if (!TESTS_QUIET) { printf("\n\nRelative accuracy:\n"); for (j = 0; j < nevents; j++) printf(" Event %.2d", j); printf("\n"); } for (j = 0; j < nevents; j++) { spread[j] = abs((int)(refvalues[j] - values[j])); if (values[j]) spread[j] /= (double) values[j]; if (!TESTS_QUIET) printf("%10.3g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) i--; else if (refvalues[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ i--; } if (!TESTS_QUIET) printf("\n\n"); if (i) test_fail(__FILE__, __LINE__, "Values outside threshold", i); else test_pass(__FILE__, NULL, 0); return 0; }