/* 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"); }
int GPTLevent_code_to_name (const int code, char *name) { int ret; /* return code */ int n; /* loop over derived entries */ /* ** First check derived events */ for (n = 0; n < nderivedentries; ++n) { if (code == derivedtable[n].counter) { strcpy (name, derivedtable[n].namestr); return 0; } } /* ** Next check PAPI events--note that PAPI must be initialized before the ** code_to_name function can be invoked. */ if ((ret = GPTL_PAPIlibraryinit ()) < 0) return GPTLerror ("GPTL_event_code_to_name: GPTL_PAPIlibraryinit failure\n"); if (PAPI_event_code_to_name (code, name) != PAPI_OK) return GPTLerror ("GPTL_event_code_to_name: PAPI_event_code_to_name failure\n"); return 0; }
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"); } }
void *Thread(void *arg) { int retval, num_tests = 1; int EventSet1=PAPI_NULL; int mask1, papi_event; int num_events1; long long **values; long long elapsed_us, elapsed_cyc; char event_name[PAPI_MAX_STR_LEN]; /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depends on the availability of the event on the platform */ EventSet1 = add_two_nonderived_events(&num_events1, &papi_event, hw_info, &mask1); expected[EventSet1] = *(int *)arg / mythreshold; myid[EventSet1] = PAPI_thread_id(); values = allocate_test_space(num_tests, num_events1); elapsed_us = PAPI_get_real_usec(); elapsed_cyc = PAPI_get_real_cyc(); if ((retval = PAPI_overflow(EventSet1, papi_event, mythreshold, 0, handler)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_overflow", retval); /* start_timer(1); */ if ((retval = PAPI_start(EventSet1)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_stuff(); if ((retval = PAPI_stop(EventSet1, values[0])) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); elapsed_us = PAPI_get_real_usec() - elapsed_us; elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc; if ((retval = PAPI_overflow(EventSet1, papi_event, 0, 0, NULL)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_overflow", retval); remove_test_events(&EventSet1, mask1); if ((retval = PAPI_event_code_to_name(papi_event, event_name)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval); if (!TESTS_QUIET) { printf("Thread 0x%x %s : \t%lld\n", (int) pthread_self(), event_name, (values[0])[0]); printf("Thread 0x%x PAPI_TOT_CYC: \t%lld\n", (int) pthread_self(), (values[0])[1]); printf("Thread 0x%x Real usec : \t%lld\n", (int) pthread_self(), elapsed_us); printf("Thread 0x%x Real cycles : \t%lld\n", (int) pthread_self(), elapsed_cyc); } free_test_space(values, num_tests); pthread_exit(NULL); return (NULL); }
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 test_print_event_header( char *call, int evset ) { int *ev_ids; int i, nev; int retval; char evname[PAPI_MAX_STR_LEN]; if ( *call ) fprintf( stdout, "%s", call ); if ((nev = PAPI_get_cmp_opt(PAPI_MAX_MPX_CTRS,NULL,0)) <= 0) { fprintf( stdout, "Can not list event names.\n" ); return; } if ((ev_ids = calloc(nev,sizeof(int))) == NULL) { fprintf( stdout, "Can not list event names.\n" ); return; } retval = PAPI_list_events( evset, ev_ids, &nev ); if ( retval == PAPI_OK ) { for ( i = 0; i < nev; i++ ) { PAPI_event_code_to_name( ev_ids[i], evname ); printf( ONEHDR, evname ); } } else { fprintf( stdout, "Can not list event names." ); } fprintf( stdout, "\n" ); free(ev_ids); }
// // This method should be placed at the start of instrumented code // void startPapiCounters(){ initializeCounters(0); #ifdef DBG printGEvents(); printf("********* STARTING COUNTERS *************\n"); //assert(NUM_EVENTS == _G_EVENT_COUNT); #endif // initialize papi library and assert that it's successful _CALL_PAPI(PAPI_library_init( PAPI_VER_CURRENT )); // check that all the events can be counted at once. int numCounters = PAPI_num_counters() ; assert( NUM_EVENTS <= numCounters ); #ifdef DBG printf("Number of hardware counters available on this machine: %d", numCounters); #endif for ( int i = 0; i < NUM_EVENTS; i++ ) { char name[PAPI_MAX_STR_LEN]; (void) _CALL_PAPI(PAPI_event_code_to_name( _G_EVENTS[i], name )); if(PAPI_query_event( _G_EVENTS[i] ) < PAPI_OK) { fprintf(stderr, "Event %s could not be counted on this machine.\n", name); abort(); } } //******* Start Counters ****** (void) _CALL_PAPI(PAPI_start_counters(_G_EVENTS, NUM_EVENTS)); }
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 printGEvents(){ int i; for(i=0; i<NUM_EVENTS; i++){ char name[PAPI_MAX_STR_LEN]; (void) PAPI_event_code_to_name( _G_EVENTS[i], name ); printf("Event %d: %s\n",i ,name); } }
void Thread( int t, int n ) { int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int PAPI_event, mask1; int num_events1; long long **values; long long elapsed_us, elapsed_cyc; char event_name[PAPI_MAX_STR_LEN]; /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); retval = PAPI_event_code_to_name( PAPI_event, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); values = allocate_test_space( num_tests, num_events1 ); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); do_flops( n ); elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { printf( "Thread %#x %-12s : \t%lld\n", t, event_name, values[0][1] ); printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t, values[0][0] ); } free_test_space( values, num_tests ); if ( !TESTS_QUIET ) { printf( "Thread %#x Real usec : \t%lld\n", t, elapsed_us ); printf( "Thread %#x Real cycles : \t%lld\n", t, elapsed_cyc ); } PAPI_unregister_thread( ); }
int canenable2 (int counter1, int counter2) { char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ if (npapievents+2 > MAX_AUX) return false; if (PAPI_query_event (counter1) != PAPI_OK) { (void) PAPI_event_code_to_name (counter1, eventname); return false; } if (PAPI_query_event (counter2) != PAPI_OK) { (void) PAPI_event_code_to_name (counter2, eventname); return false; } return true; }
void Thread( int n ){ int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int PAPI_event, mask1; int num_events1; long long **values; long long elapsed_us, elapsed_cyc, L1_DCM; char event_name[PAPI_MAX_STR_LEN]; printf( "Thread %#x started\n", omp_get_thread_num( ) ); num_events1 = 2; EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); retval = PAPI_event_code_to_name( PAPI_event, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); values = allocate_test_space( num_tests, num_events1 ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); retval = PAPI_start( EventSet1 ); do_flops( n ); retval = PAPI_stop( EventSet1, values[0] ); elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { printf( "Thread %#x %-12s : \t%lld\n", omp_get_thread_num( ), event_name, values[0][1] ); printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num( ), values[0][0] ); printf( "Thread %#x Real usec : \t%lld\n", omp_get_thread_num( ), elapsed_us ); printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num( ), elapsed_cyc ); } free_test_space( values, num_tests ); PAPI_unregister_thread( ); printf( "Thread %#x finished\n", omp_get_thread_num( ) ); }
int canenable (int counter) { char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ if (npapievents+1 > MAX_AUX) return false; if (PAPI_query_event (counter) != PAPI_OK) { (void) PAPI_event_code_to_name (counter, eventname); fprintf (stderr, "canenable: event %s not available on this arch\n", eventname); return false; } return true; }
int main() { int EventCode, retval; char EventCodeStr[PAPI_MAX_STR_LEN]; /* Initialize the library */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI library init error!\n"); exit(1); } EventCode = 0 | 0x40000000; do { /* Translate the integer code to a string */ if (PAPI_event_code_to_name(EventCode, EventCodeStr) == PAPI_OK) /* Print all the native events for this platform */ printf("Name: %s\nCode: %x\n", EventCodeStr, EventCode); } while (PAPI_enum_event(&EventCode, 0) == PAPI_OK); }
void test_print_event_header( char *call, int evset ) { int ev_ids[PAPI_MAX_HWCTRS + PAPI_MPX_DEF_DEG]; int i, nev; int retval; char evname[PAPI_MAX_STR_LEN]; nev = PAPI_MAX_HWCTRS + PAPI_MPX_DEF_DEG; retval = PAPI_list_events( evset, ev_ids, &nev ); if ( *call ) fprintf( stdout, "%s", call ); if ( retval == PAPI_OK ) { for ( i = 0; i < nev; i++ ) { PAPI_event_code_to_name( ev_ids[i], evname ); printf( ONEHDR, evname ); } } else { fprintf( stdout, "Can not list event names." ); } fprintf( stdout, "\n" ); }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long values0[2],values1[2],values2[2]; int num_flops = 3000000, retval; int mythreshold = 1000000; char event_name1[PAPI_MAX_STR_LEN]; int PAPI_event; int cid,numcmp,rapl_cid; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); quiet=TESTS_QUIET; /* Init PAPI */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init",retval); } 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,"linux-rapl")) { rapl_cid=cid; if (!TESTS_QUIET) printf("Found rapl component at cid %d\n", rapl_cid); if (cmpinfo->num_native_events==0) { test_skip(__FILE__,__LINE__,"No rapl events found",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* add PAPI_TOT_CYC and PAPI_TOT_INS */ retval=PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_CYC); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_INS); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } /* Add some RAPL events */ retval=PAPI_create_eventset(&EventSet2); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } PAPI_event=PAPI_TOT_CYC; /* arbitrary */ mythreshold = 2000000; if (!TESTS_QUIET) { printf("Using %x for the overflow event, threshold %d\n", PAPI_event,mythreshold); } /* Start the run calibration run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( 3000000 ); /* stop the calibration run */ retval = PAPI_stop( EventSet, values0 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } /* set up overflow handler */ retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } /* Start overflow run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( num_flops ); /* stop overflow run */ retval = PAPI_stop( EventSet, values1 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_stop( EventSet2, values2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } retval = PAPI_event_code_to_name( PAPI_event, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]); } retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]); } 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); } if (rapl_backward) { test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0); } test_pass( __FILE__, NULL, 0 ); return 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_Init_Thread (UINT64 time, int threadid, int forked) { int i, j, rc; PAPI_option_t options; if (HWC_num_sets <= 0) return FALSE; if (forked) { PAPI_stop (HWCEVTSET(threadid), NULL); for (i = 0; i < HWC_num_sets; i++) { rc = PAPI_cleanup_eventset (HWC_sets[i].eventsets[threadid]); if (rc == PAPI_OK) PAPI_destroy_eventset (&HWC_sets[i].eventsets[threadid]); HWC_sets[i].eventsets[threadid] = PAPI_NULL; } } //if (!forked) { memset (&options, 0, sizeof(options)); for (i = 0; i < HWC_num_sets; i++) { /* Create the eventset. Each thread will create its own eventset */ rc = PAPI_create_eventset (&(HWC_sets[i].eventsets[threadid])); if (PAPI_OK != rc) { fprintf (stderr, PACKAGE_NAME": Error! Unable to create eventset (%d of %d) in thread %d\n", i+1, HWC_num_sets, threadid); continue; } /* Add the selected counters */ for (j = 0; j < HWC_sets[i].num_counters; j++) { if (HWC_sets[i].counters[j] != NO_COUNTER) { rc = PAPI_add_event (HWC_sets[i].eventsets[threadid], HWC_sets[i].counters[j]); if (rc != PAPI_OK) { char EventName[PAPI_MAX_STR_LEN]; PAPI_event_code_to_name (HWC_sets[i].counters[j], EventName); fprintf (stderr, PACKAGE_NAME": Error! Hardware counter %s (0x%08x) cannot be added in set %d (thread %d)\n", EventName, HWC_sets[i].counters[j], i+1, threadid); HWC_sets[i].counters[j] = NO_COUNTER; /* break; */ } } } /* Set the domain for these eventsets */ options.domain.eventset = HWC_sets[i].eventsets[threadid]; options.domain.domain = HWC_sets[i].domain; rc = PAPI_set_opt (PAPI_DOMAIN, &options); if (rc != PAPI_OK) fprintf (stderr, PACKAGE_NAME": Error when setting domain for eventset %d\n", i+1); } } /* forked */ HWC_Thread_Initialized[threadid] = HWCBE_PAPI_Start_Set (0, time, HWC_current_set[threadid], threadid); return HWC_Thread_Initialized[threadid]; }
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 retval,i; int EventSet=PAPI_NULL; int event_code=PAPI_TOT_INS; /* By default monitor total instructions */ char errstring[PAPI_MAX_STR_LEN]; char event_name[PAPI_MAX_STR_LEN]; float a[1000],b[1000],c[1000]; long long values; /* This initializes the library and checks the version number of the * header file, to the version of the library, if these don't match * then it is likely that PAPI won't work correctly. */ if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ){ /* This call loads up what the error means into errstring * if retval == PAPI_ESYS then it might be beneficial * to call perror as well to see what system call failed */ PAPI_perror("PAPI_library_init"); exit(-1); } /* Create space for the EventSet */ if ( (retval=PAPI_create_eventset( &EventSet ))!=PAPI_OK){ PAPI_perror(retval, errstring, PAPI_MAX_STR_LEN); exit(-1); } /* After this call if the environment variable PAPI_EVENT is set, * event_code may contain something different than total instructions. */ if ( (retval=PAPI_add_env_event(&EventSet, &event_code, "PAPI_EVENT"))!=PAPI_OK){ PAPI_perror("PAPI_add_env_event"); exit(-1); } /* Now lets start counting */ if ( (retval = PAPI_start(EventSet)) != PAPI_OK ){ PAPI_perror("PAPI_start"); exit(-1); } /* Some work to take up some time, the PAPI_start/PAPI_stop (and/or * PAPI_read) should surround what you want to monitor. */ for ( i=0;i<1000;i++){ a[i] = b[i]-c[i]; c[i] = a[i]*1.2; } if ( (retval = PAPI_stop(EventSet, &values) ) != PAPI_OK ){ PAPI_perror("PAPI_stop"); exit(-1); } if ( (retval=PAPI_event_code_to_name( event_code, event_name))!=PAPI_OK){ PAPI_perror("PAPI_event_code_to_name"); exit(-1); } printf("Ending values for %s: %lld\n", event_name,values); /* Remove PAPI instrumentation, this is necessary on platforms * that need to release shared memory segments and is always * good practice. */ PAPI_shutdown(); exit(0); }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long value; int code; char event_name[PAPI_MAX_STR_LEN]; int total_events=0; int r; const PAPI_component_info_t *cmpinfo = NULL; /* 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 net 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",-1); } if (!TESTS_QUIET) { printf("Component %d - %d events - %s\n", cid, cmpinfo->num_native_events, cmpinfo->name); } if ( strstr(cmpinfo->name, "infiniband") == NULL) { continue; } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!TESTS_QUIET) { printf("%#x %-24s = ", code, event_name); } EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } if (strcmp(event_name, "_recv") == 0) { /* XXX figure out a general method to generate some traffic * for infiniband * the operation should take more than one second in order * to guarantee that the network counters are updated */ retval = system("ping -c 4 " PINGADDR " > /dev/null"); if (retval < 0) { test_fail(__FILE__, __LINE__, "Unable to start ping", retval); } } retval = PAPI_stop( EventSet, &value ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } if (!TESTS_QUIET) printf("%lld\n", value); 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); } total_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } if (total_events==0) { test_skip(__FILE__,__LINE__,"No net events found", 0); } test_pass( __FILE__, NULL, 0 ); return 0; }
void mainloop( int arg ) { int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int mask1 = 0x0; int num_events1; long long **values; int PAPI_event; char event_name[PAPI_MAX_STR_LEN]; ( void ) arg; if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ EventSet1 = add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 ); values = allocate_test_space( num_tests, num_events1 ); if ( ( retval = PAPI_overflow( EventSet1, PAPI_event, THRESHOLD, 0, handler ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); do_stuff( ); if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); /* clear the papi_overflow event */ if ( ( retval = PAPI_overflow( EventSet1, PAPI_event, 0, 0, NULL ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); if ( !TESTS_QUIET ) { printf( "Thread %#x %s : \t%lld\n", ( int ) pthread_self( ), event_name, ( values[0] )[0] ); printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ), ( values[0] )[1] ); } retval = PAPI_cleanup_eventset( EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset( &EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); free_test_space( values, num_tests ); PAPI_shutdown( ); }
int main(int argc, char **argv) { int EventSet=PAPI_NULL; long long values[2] = { 0, 0 }; long long min, max; int num_flops=NUM_FLOPS, retval; int PAPI_event=0, mythreshold; char event_name[PAPI_MAX_STR_LEN]; const PAPI_hw_info_t *hw_info = NULL; 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); hw_info = PAPI_get_hardware_info(); if (hw_info == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); if((!strncmp(hw_info->model_string, "UltraSPARC", 10) && !(strncmp(hw_info->vendor_string, "SUN", 3))) || (!strncmp(hw_info->model_string, "AMD K7", 6)) || (!strncmp(hw_info->vendor_string, "Cray", 4)) || (strstr(hw_info->model_string, "POWER3"))) { /* query and set up the right instruction to monitor */ if (PAPI_query_event(PAPI_TOT_INS) == PAPI_OK) { PAPI_event = PAPI_TOT_INS; } else { test_fail(__FILE__, __LINE__, "PAPI_TOT_INS not available on this Sun platform!", 0); } } else { /* query and set up the right instruction to monitor */ if (PAPI_query_event(PAPI_FP_INS) == PAPI_OK) { PAPI_event = PAPI_FP_INS; } else { if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) PAPI_event = PAPI_FP_OPS; else PAPI_event = PAPI_TOT_INS; } } if ( PAPI_event == PAPI_FP_INS ) mythreshold = THRESHOLD ; else #if defined(linux) mythreshold = hw_info->mhz*10000*2; #else mythreshold = THRESHOLD*2; #endif retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); retval = PAPI_add_event(EventSet, PAPI_event); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet, &values[0]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_overflow(EventSet, PAPI_event, mythreshold, 0, handler); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_overflow", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet, &values[1]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); #if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4) num_flops *= 2; #endif if (!TESTS_QUIET) { if ((retval = PAPI_event_code_to_name(PAPI_event, event_name)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval); printf("Test case: Overflow dispatch of 1st event in set with 1 event.\n"); printf("--------------------------------------------------------------\n"); printf("Threshold for overflow is: %d\n", mythreshold); printf("Using %d iterations of c += a*b\n", NUM_FLOPS); printf("-----------------------------------------------\n"); printf("Test type : %16d%16d\n", 1, 2); printf(OUT_FMT, event_name, values[0], values[1]); printf("Overflows : %16s%16d\n", "", total); printf("-----------------------------------------------\n"); printf("Verification:\n"); /* if (PAPI_event == PAPI_FP_INS) printf("Row 1 approximately equals %d %d\n", num_flops, num_flops); printf("Column 1 approximately equals column 2\n"); */ printf("Row 3 approximately equals %u +- %u %%\n", (unsigned) ((values[0]) / (long long) mythreshold), (unsigned) (OVR_TOLERANCE * 100.0)); } /* min = (long long)(values[0]*(1.0-TOLERANCE)); max = (long long)(values[0]*(1.0+TOLERANCE)); if ( values[1] > max || values[1] < min ) test_fail(__FILE__, __LINE__, event_name, 1); */ min = (long long) ((values[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold); max = (long long) ((values[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold); if (total > max || total < min) test_fail(__FILE__, __LINE__, "Overflows", 1); test_pass(__FILE__, NULL, 0); exit(1); }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long values[MAX_EVENTS]; int i,code,enum_retval; const PAPI_component_info_t *cmpinfo = NULL; long long start_time,write_start_time,write_end_time,read_start_time,read_end_time; char event_name[BUFSIZ]; union { long long ll; double dbl; } event_value_union; static int num_events=0; FILE *fileout; /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { fprintf(stderr,"PAPI_library_init failed\n"); exit(1); } /* Find the libmsr component */ numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { fprintf(stderr,"PAPI_get_component_info failed\n"); exit(1); } if (strstr(cmpinfo->name,"libmsr")) { rapl_cid=cid; printf("Found libmsr component at cid %d\n", rapl_cid); if (cmpinfo->disabled) { fprintf(stderr,"No libmsr events found: %s\n", cmpinfo->disabled_reason); exit(1); } break; } } /* Component not found */ if (cid==numcmp) { fprintf(stderr,"No libmsr component found\n"); exit(1); } /* Find events in the component */ code = PAPI_NATIVE_MASK; enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( enum_retval == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); exit(1); } printf("Found: %s\n",event_name); strncpy(events[num_events],event_name,BUFSIZ); sprintf(filenames[num_events],"results.%s",event_name); num_events++; if (num_events==MAX_EVENTS) { printf("Too many events! %d\n",num_events); exit(1); } enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } if (num_events==0) { printf("Error! No libmsr events found!\n"); exit(1); } /* Open output file */ char fileoutname[]="libmsr_write_test_output.txt"; fileout=fopen( fileoutname ,"w" ); if ( fileout==NULL) { fprintf( stderr,"Could not open %s\n",fileoutname ); exit(1); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { fprintf(stderr,"Error creating eventset!\n"); } for(i=0;i<num_events;i++) { retval = PAPI_add_named_event( EventSet, events[i] ); if (retval != PAPI_OK) fprintf(stderr,"Error adding event %s\n",events[i]); } start_time=PAPI_get_real_nsec(); /* Grab the initial values for the events */ retval = PAPI_start( EventSet); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_start() failed\n"); exit(1); } /* Initial checking read */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } /* Write a header line */ fprintf( fileout, "ACTION TIME-STAMP TIME-FOR-UNIT-WORK TIME-OVERHEAD-RW\t" ); for(i=0; i<num_events; i++) fprintf( fileout, "%s ", events[i]+9 ); fprintf( fileout, "\n" ); /* Read the initial values */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "INIT %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", 0.0); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); int rpt=0; int limit1base=10; int limit2base=10; while(rpt++<200) { //printf("rpt %d\n", rpt); if ( rpt % 10 == 0 ) { for (i=0; i<num_events; i++) { event_value_union.ll = values[i]; if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=1.0; else event_value_union.dbl=PAPI_NULL; values[i]=event_value_union.ll; } write_start_time=PAPI_get_real_nsec(); retval = PAPI_write( EventSet, values ); write_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_write() failed\n"); exit(1); } fprintf( fileout, "SET %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", ((double)(write_end_time-write_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } /* DO SOME WORK TO USE ENERGY */ //usleep(100000); double work_start_time=PAPI_get_real_nsec(); ompcpuloadprimes( 100000 ); double work_time=PAPI_get_real_nsec()-work_start_time; //printf("primescount %d\n", primescount); /* Read and output the values */ read_start_time=PAPI_get_real_nsec(); retval = PAPI_read( EventSet, values ); read_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "READ %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, work_time/1.0e9 ); fprintf( fileout, "%8.3e ", ((double)(read_end_time-read_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } retval = PAPI_stop( EventSet, values); return 0; }
void * Thread( void *arg ) { int retval, num_tests = 1, i; int EventSet1 = PAPI_NULL, mask1, PAPI_event; int num_events1; long long **values; long long elapsed_us, elapsed_cyc; unsigned short *profbuf; char event_name[PAPI_MAX_STR_LEN]; retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); profbuf = ( unsigned short * ) malloc( length * sizeof ( unsigned short ) ); if ( profbuf == NULL ) exit( 1 ); memset( profbuf, 0x00, length * sizeof ( unsigned short ) ); /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depends on the availability of the event on the platform */ EventSet1 = add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 ); values = allocate_test_space( num_tests, num_events1 ); if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); retval = PAPI_profil( profbuf, length, my_start, 65536, EventSet1, PAPI_event, THR, PAPI_PROFIL_POSIX ); if ( retval ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( *( int * ) arg ); if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; /* to remove the profile flag */ retval = PAPI_profil( profbuf, length, my_start, 65536, EventSet1, PAPI_event, 0, PAPI_PROFIL_POSIX ); if ( retval ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { if ( mask1 == 0x3 ) { printf( "Thread 0x%x PAPI_TOT_INS : \t%lld\n", ( int ) pthread_self( ), ( values[0] )[0] ); } else { printf( "Thread 0x%x PAPI_FP_INS : \t%lld\n", ( int ) pthread_self( ), ( values[0] )[0] ); } printf( "Thread 0x%x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ), ( values[0] )[1] ); printf( "Thread 0x%x Real usec : \t%lld\n", ( int ) pthread_self( ), elapsed_us ); printf( "Thread 0x%x Real cycles : \t%lld\n", ( int ) pthread_self( ), elapsed_cyc ); printf( "Test case: PAPI_profil() for pthreads\n" ); printf( "----Profile buffer for Thread 0x%x---\n", ( int ) pthread_self( ) ); for ( i = 0; i < ( int ) length; i++ ) { if ( profbuf[i] ) printf( "0x%lx\t%d\n", ( unsigned long ) ( my_start + 2 * i ), profbuf[i] ); } } for ( i = 0; i < ( int ) length; i++ ) if ( profbuf[i] ) break; if ( i >= ( int ) length ) test_fail( __FILE__, __LINE__, "No information in buffers", 1 ); free_test_space( values, num_tests ); retval = PAPI_unregister_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval ); return ( NULL ); }
int main(int argc, char **argv) { int EventSet=PAPI_NULL; long long(values[2])[2]; long long min, max; int num_flops = NUM_FLOPS, retval; int PAPI_event, mythreshold=THRESHOLD; char event_name[PAPI_MAX_STR_LEN]; const PAPI_hw_info_t *hw_info = NULL; int num_events, mask; 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); hw_info = PAPI_get_hardware_info(); if (hw_info == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ EventSet = add_two_nonderived_events(&num_events, &PAPI_event, hw_info, &mask); if ( PAPI_event == PAPI_FP_INS ) mythreshold = THRESHOLD ; else #if defined(linux) mythreshold = hw_info->mhz*10000*2; #else mythreshold = THRESHOLD*2; #endif retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet, values[0]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_overflow(EventSet, PAPI_event, mythreshold, 0, handler); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_overflow", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(num_flops); retval = PAPI_stop(EventSet, values[1]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_overflow(EventSet, PAPI_event, 0, 0, handler); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_overflow", retval); if (!TESTS_QUIET) { if ((retval = PAPI_event_code_to_name(PAPI_event, event_name)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval); printf("Test case: Overflow dispatch of 2nd event in set with 2 events.\n"); printf("---------------------------------------------------------------\n"); printf("Threshold for overflow is: %d\n", mythreshold); printf("Using %d iterations of c += a*b\n", num_flops); printf("-----------------------------------------------\n"); printf("Test type : %16d%16d\n", 1, 2); printf(OUT_FMT, event_name, (values[0])[0], (values[1])[0]); printf(OUT_FMT, "PAPI_TOT_CYC", (values[0])[1], (values[1])[1]); printf("Overflows : %16s%16d\n", "", total); printf("-----------------------------------------------\n"); } 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); if (!TESTS_QUIET) { printf("Verification:\n"); #if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4) num_flops *= 2; #endif if (PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS){ printf("Row 1 approximately equals %d %d\n", num_flops, num_flops); } printf("Column 1 approximately equals column 2\n"); printf("Row 3 approximately equals %u +- %u %%\n", (unsigned) ((values[0])[0] / (long long) mythreshold), (unsigned) (OVR_TOLERANCE * 100.0)); } /* min = (long long)((values[0])[1]*(1.0-TOLERANCE)); max = (long long)((values[0])[1]*(1.0+TOLERANCE)); if ( (values[0])[1] > max || (values[0])[1] < min ) test_fail(__FILE__, __LINE__, event_name, 1); */ min = (long long) (((values[0])[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold); max = (long long) (((values[0])[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold); printf("Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) ", total, max, total, min); if (total > max || total < min) test_fail(__FILE__, __LINE__, "Overflows", 1); test_pass(__FILE__, NULL, 0); exit(1); }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long values[NUM_EVENTS]; int code; char event_name[PAPI_MAX_STR_LEN]; int total_events=0; int r; const PAPI_component_info_t *cmpinfo = NULL; /* 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); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if (!TESTS_QUIET) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } printf("\tComponent %d - %s\n", cid, cmpinfo->name); } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!strncmp(event_name,"micpower",8)) { if (!TESTS_QUIET) printf("0x%x %s ",code,event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } if (!TESTS_QUIET) printf(" value: %lld\n",values[0]); 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); } total_events++; } r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } if (total_events==0) { test_skip(__FILE__,__LINE__,"No coretemp events found",0); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long *values; int num_flops, retval, i, j; int *events, mythreshold; char **names; const PAPI_hw_info_t *hw_info = NULL; int num_events, *ovt; char name[PAPI_MAX_STR_LEN]; const PAPI_component_info_t *comp_info = NULL; int using_perfmon = 0; int using_aix = 0; int numcmp, cid; 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 ); } hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval ); } numcmp = PAPI_num_components( ); for ( cid = 0; cid < numcmp; cid++ ) { comp_info = PAPI_get_component_info( cid ); if ( comp_info == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", retval ); } if ( strstr( comp_info->name, "perfmon.c" ) ) { using_perfmon = 1; } if ( strstr( comp_info->name, "aix.c" ) ) { using_aix = 1; } } /* add PAPI_TOT_CYC and one of the events in */ /* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS, */ /* depending on the availability of the event*/ /* on the platform */ EventSet = enum_add_native_events( &num_events, &events, 1 , 1); if (!TESTS_QUIET) printf("Trying %d events\n",num_events); names = ( char ** ) calloc( ( unsigned int ) num_events, sizeof ( char * ) ); for ( i = 0; i < num_events; i++ ) { if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) { test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval); } else { names[i] = strdup( name ); if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]); } } values = ( long long * ) calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ), sizeof ( long long ) ); ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) ); #if defined(linux) { char *tmp = getenv( "THRESHOLD" ); if ( tmp ) { mythreshold = atoi( tmp ); } else if (hw_info->mhz!=0) { mythreshold = ( int ) hw_info->mhz * 20000; if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold); } else { if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD); mythreshold = THRESHOLD; } } #else mythreshold = THRESHOLD; #endif num_flops = NUM_FLOPS * 2; /* initial test to make sure they all work */ if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n"); retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( num_flops ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } /* done with initial test */ /* keep adding events? */ for ( i = 0; i < num_events; i++ ) { /* Enable overflow */ if (!TESTS_QUIET) printf("Testing with overflow set on %s\n", names[i]); retval = PAPI_overflow( EventSet, events[i], mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( num_flops ); retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } /* Disable overflow */ retval = PAPI_overflow( EventSet, events[i], 0, 0, handler ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); } ovt[i] = total; total = 0; } if ( !TESTS_QUIET ) { printf("\nResults in Matrix-view:\n"); printf( "Test Overflow on %d counters with %d events.\n", num_events,num_events ); printf( "-----------------------------------------------\n" ); printf( "Threshold for overflow is: %d\n", mythreshold ); printf( "Using %d iterations of c += a*b\n", num_flops ); printf( "-----------------------------------------------\n" ); printf( "Test type : " ); for ( i = 0; i < num_events + 1; i++ ) { printf( "%16d", i ); } printf( "\n" ); for ( j = 0; j < num_events; j++ ) { printf( "%-27s : ", names[j] ); for ( i = 0; i < num_events + 1; i++ ) { printf( "%16lld", *( values + j + num_events * i ) ); } printf( "\n" ); } printf( "Overflows : %16s", "" ); for ( i = 0; i < num_events; i++ ) { printf( "%16d", ovt[i] ); } printf( "\n" ); printf( "-----------------------------------------------\n" ); } /* validation */ if ( !TESTS_QUIET ) { printf("\nResults broken out for validation\n"); } if (!TESTS_QUIET) { for ( j = 0; j < num_events+1; j++ ) { if (j==0) { printf("Test results, no overflow:\n\t"); } else { printf("Overflow of event %d, %s\n\t",j-1,names[j-1]); } for(i=0; i < num_events; i++) { if (i==j-1) { printf("*%lld* ",values[(num_events*j)+i]); } else { printf("%lld ",values[(num_events*j)+i]); } } printf("\n"); if (j!=0) { printf("\tOverflow should be %lld / %d = %lld\n", values[(num_events*j)+(j-1)], mythreshold, values[(num_events*j)+(j-1)]/mythreshold); printf("\tOverflow was %d\n",ovt[j-1]); } } } for ( j = 0; j < num_events; j++ ) { //printf("Validation: %lld / %d != %d (%lld)\n", // *( values + j + num_events * (j+1) ) , // mythreshold, // ovt[j], // *(values+j+num_events*(j+1))/mythreshold); if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) { char error_string[BUFSIZ]; if ( using_perfmon ) test_warn( __FILE__, __LINE__, "perfmon substrate handles overflow differently than perf_events", 1 ); else if ( using_aix ) test_warn( __FILE__, __LINE__, "AIX (pmapi) substrate handles overflow differently than various other substrates", 1 ); else { sprintf( error_string, "Overflow value differs from expected %lld / %d != %d (%lld)", *( values + j + num_events * ( j + 1 ) ), mythreshold, ovt[j], *( values + j + num_events * ( j + 1 ) ) / mythreshold ); test_fail( __FILE__, __LINE__, error_string, 1 ); } } } 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 ); free( ovt ); for ( i = 0; i < num_events; i++ ) free( names[i] ); free( names ); free( events ); free( values ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long ( values[3] )[2]; int retval; int PAPI_event, k, idx[4]; char event_name[3][PAPI_MAX_STR_LEN]; int num_events1; int threshold = THRESHOLD; 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 ); /* decide which of PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS to add, depending on the availability and derived status of the event on this platform */ if ( ( PAPI_event = find_nonderived_event( ) ) == 0 ) test_fail( __FILE__, __LINE__, "no PAPI_event", 0 ); if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( NUM_FLOPS ); if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); /* Set both overflows after adding both events (batch) */ if ( ( retval = PAPI_overflow( EventSet, PAPI_event, threshold, 0, handler_batch ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0, handler_batch ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet, values[1] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); num_events1 = 1; retval = PAPI_get_overflow_event_index( EventSet, 1, &idx[0], &num_events1 ); if ( retval != PAPI_OK ) printf( "PAPI_get_overflow_event_index error: %s\n", PAPI_strerror( retval ) ); num_events1 = 1; retval = PAPI_get_overflow_event_index( EventSet, 2, &idx[1], &num_events1 ); if ( retval != PAPI_OK ) printf( "PAPI_get_overflow_event_index error: %s\n", PAPI_strerror( retval ) ); if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); /* Add each event and set its overflow (interleaved) */ if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( ( retval = PAPI_overflow( EventSet, PAPI_event, threshold, 0, handler_interleaf ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( ( retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0, handler_interleaf ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( NUM_FLOPS ); if ( ( retval = PAPI_stop( EventSet, values[2] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); num_events1 = 1; retval = PAPI_get_overflow_event_index( EventSet, 1, &idx[2], &num_events1 ); if ( retval != PAPI_OK ) printf( "PAPI_get_overflow_event_index error: %s\n", PAPI_strerror( retval ) ); num_events1 = 1; retval = PAPI_get_overflow_event_index( EventSet, 2, &idx[3], &num_events1 ); if ( retval != PAPI_OK ) printf( "PAPI_get_overflow_event_index error: %s\n", PAPI_strerror( retval ) ); if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); if ( ( retval = PAPI_event_code_to_name( PAPI_TOT_CYC, event_name[1] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); strcpy( event_name[2], "Unknown" ); printf ( "Test case: Overflow dispatch of both events in set with 2 events.\n" ); printf ( "---------------------------------------------------------------\n" ); printf( "Threshold for overflow is: %d\n", threshold ); printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); printf( "-----------------------------------------------\n" ); printf( "Test type : %18s%18s%18s\n", "1 (no overflow)", "2 (batch)", "3 (interleaf)" ); printf( OUT_FMT, event_name[0], ( values[0] )[0], ( values[1] )[0], ( values[2] )[0] ); printf( OUT_FMT, event_name[1], ( values[0] )[1], ( values[1] )[1], ( values[2] )[1] ); printf( "\n" ); printf( "Predicted overflows at event %-12s : %6d\n", event_name[0], ( int ) ( ( values[0] )[0] / threshold ) ); printf( "Predicted overflows at event %-12s : %6d\n", event_name[1], ( int ) ( ( values[0] )[1] / threshold ) ); printf( "\nBatch overflows (add, add, over, over):\n" ); for ( k = 0; k < 2; k++ ) { if ( overflow_counts[0][k].mask ) { printf( VEC_FMT, ( long long ) overflow_counts[0][k].mask, event_name[idx[k]], overflow_counts[0][k].count ); } } printf( "\nInterleaved overflows (add, over, add, over):\n" ); for ( k = 0; k < 2; k++ ) { if ( overflow_counts[1][k].mask ) printf( VEC_FMT, ( long long ) overflow_counts[1][k].mask, event_name[idx[k + 2]], overflow_counts[1][k].count ); } printf( "\nCases 2+3 Unknown overflows: %d\n", total_unknown ); printf( "-----------------------------------------------\n" ); if ( overflow_counts[0][0].count == 0 || overflow_counts[0][1].count == 0 ) test_fail( __FILE__, __LINE__, "a batch counter had no overflows", 1 ); if ( overflow_counts[1][0].count == 0 || overflow_counts[1][1].count == 0 ) test_fail( __FILE__, __LINE__, "an interleaved counter had no overflows", 1 ); if ( total_unknown > 0 ) test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main () { int EventSet = PAPI_NULL; /* must be set to null before calling PAPI_create_eventset */ char errstring[PAPI_MAX_STR_LEN]; long long (values[2])[2]; int retval, i; double tmp = 0; int PAPI_event; /* a place holder for an event preset */ char event_name[PAPI_MAX_STR_LEN]; /**************************************************************************** * This part initializes the library and compares the version number of the * * header file, to the version of the library, if these don't match then it * * is likely that PAPI won't work correctly.If there is an error, retval * * keeps track of the version number. * ****************************************************************************/ if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { printf("Library initialization error! \n"); exit(1); } /* Here we create the eventset */ if ((retval=PAPI_create_eventset (&EventSet)) != PAPI_OK) ERROR_RETURN(retval); PAPI_event = PAPI_TOT_INS; /* Here we are querying for the existence of the PAPI presets */ if (PAPI_query_event (PAPI_TOT_INS) != PAPI_OK) { PAPI_event = PAPI_TOT_CYC; if ((retval=PAPI_query_event (PAPI_TOT_INS)) != PAPI_OK) ERROR_RETURN(retval); printf ("PAPI_TOT_INS not available on this platform."); printf (" so subst PAPI_event with PAPI_TOT_CYC !\n\n"); } /* PAPI_event_code_to_name is used to convert a PAPI preset from its integer value to its string name. */ if ((retval = PAPI_event_code_to_name (PAPI_event, event_name)) != PAPI_OK) ERROR_RETURN(retval); /* add event to the event set */ if ((retval = PAPI_add_event (EventSet, PAPI_event)) != PAPI_OK) ERROR_RETURN(retval); /* register overflow and set up threshold */ /* The threshold "THRESHOLD" was set to 100000 */ if ((retval = PAPI_overflow (EventSet, PAPI_event, THRESHOLD, 0, handler)) != PAPI_OK) ERROR_RETURN(retval); printf ("Here are the addresses at which overflows occured and overflow vectors \n"); printf ("--------------------------------------------------------------\n"); /* Start counting */ if ( (retval=PAPI_start (EventSet)) != PAPI_OK) ERROR_RETURN(retval); for (i = 0; i < 2000000; i++) { tmp = 1.01 + tmp; tmp++; } /* Stops the counters and reads the counter values into the values array */ if ( (retval=PAPI_stop (EventSet, values[0])) != PAPI_OK) ERROR_RETURN(retval); printf ("The total no of overflows was %d\n", total); /* clear the overflow status */ if ((retval = PAPI_overflow (EventSet, PAPI_event, 0, 0, handler)) != PAPI_OK) ERROR_RETURN(retval); /************************************************************************ * PAPI_cleanup_eventset can only be used after the counter has been * * stopped then it remove all events in the eventset * ************************************************************************/ if ( (retval=PAPI_cleanup_eventset (EventSet)) != PAPI_OK) ERROR_RETURN(retval); /* Free all memory and data structures, EventSet must be empty. */ if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK) ERROR_RETURN(retval); /* free the resources used by PAPI */ PAPI_shutdown(); exit(0); }