void init_test(int SoftwareMPX, int KernelMPX, int* Events) { int i; int retval; PAPI_option_t option, itimer; if ( ( retval = PAPI_assign_eventset_component( SoftwareMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_assign_eventset_component( KernelMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_set_multiplex( KernelMPX ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); PAPI_get_opt(PAPI_DEF_ITIMER,&itimer); memset(&option,0x0,sizeof(option)); option.multiplex.flags = PAPI_MULTIPLEX_FORCE_SW; option.multiplex.eventset = SoftwareMPX; option.multiplex.ns = itimer.itimer.ns; PAPI_set_opt( PAPI_MULTIPLEX, &option ); for (i = 0; i < options.min - 1; i++) { if ( options.kernel_mpx ) { if ( ( retval = PAPI_add_event( KernelMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } if ( options.force_sw ) { if ( ( retval = PAPI_add_event( SoftwareMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } } }
perf_t* perf_init() { int retval; int EventSet = PAPI_NULL; retval = PAPI_create_eventset(&EventSet); assert(retval == PAPI_OK); retval = PAPI_assign_eventset_component(EventSet, 0); assert(retval == PAPI_OK); /* By default, the counter is inherited. */ PAPI_option_t opt; memset(&opt, 0x0, sizeof(PAPI_option_t)); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = EventSet; retval = PAPI_set_opt(PAPI_INHERIT, &opt); assert(retval == PAPI_OK); /* Add events by names */ for (int i = 0; i < NUM_EVENTS; i++) { int EventCode; if ((retval = PAPI_event_name_to_code(PERF_EVENT_NAMES[i], &EventCode)) != PAPI_OK) { fprintf(stderr, "Event name %s not found, skipped.\n", PERF_EVENT_NAMES[i]); continue; } if ((retval = PAPI_query_event(EventCode)) != PAPI_OK) { fprintf(stderr, "Event %s not supported on this hardware, skipped.\n", PERF_EVENT_NAMES[i]); continue; } if ((retval = PAPI_add_event(EventSet, EventCode)) != PAPI_OK) { assert(retval == PAPI_ECNFLCT); fprintf(stderr, "%s conflicts, skipped.\n", PERF_EVENT_NAMES[i]); } } perf_t *perf = (perf_t*)malloc(sizeof(perf_t)); perf->EventSet = EventSet; /* perf->values = (counter_t*)malloc(sizeof(counter_t) * NUM_EVENTS); */ /* memset(perf->values, 0x0, sizeof(counter_t) * NUM_EVENTS); */ return perf; }
void 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 flops_init() { #ifdef HAVE_PAPI int err = PAPI_library_init( PAPI_VER_CURRENT ); if ( err != PAPI_VER_CURRENT ) { fprintf( stderr, "Error: PAPI couldn't initialize: %s (%d)\n", PAPI_strerror(err), err ); } // read flops err = PAPI_create_eventset( &gPAPI_flops_set ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_create_eventset failed\n" ); } err = PAPI_assign_eventset_component( gPAPI_flops_set, 0 ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_assign_eventset_component failed: %s (%d)\n", PAPI_strerror(err), err ); } PAPI_option_t opt; memset( &opt, 0, sizeof(PAPI_option_t) ); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = gPAPI_flops_set; err = PAPI_set_opt( PAPI_INHERIT, &opt ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_set_opt failed: %s (%d)\n", PAPI_strerror(err), err ); } err = PAPI_add_event( gPAPI_flops_set, PAPI_FP_OPS ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_add_event failed: %s (%d)\n", PAPI_strerror(err), err ); } err = PAPI_start( gPAPI_flops_set ); if ( err != PAPI_OK ) { fprintf( stderr, "Error: PAPI_start failed: %s (%d)\n", PAPI_strerror(err), err ); } #endif // HAVE_PAPI }
int main(int argc, char **argv) { PAPI_event_info_t info; int i, j, retval; int iters = NUM_FLOPS; 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]; int nevents = MAXEVENTS; int eventset = PAPI_NULL; int events[MAXEVENTS]; events[0] = PAPI_FP_INS; events[1] = PAPI_TOT_INS; events[2] = PAPI_INT_INS; events[3] = PAPI_TOT_CYC; events[4] = PAPI_STL_CCY; events[5] = PAPI_BR_INS; events[6] = PAPI_SR_INS; events[7] = PAPI_LD_INS; events[8] = PAPI_TOT_IIS; events[9] = PAPI_FAD_INS; events[10] = PAPI_BR_TKN; events[11] = PAPI_BR_MSP; events[12] = PAPI_L1_ICA; events[13] = PAPI_L1_DCA; 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 multiplexing routines.\n"); printf("Comparing a multiplex 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); decide_which_events(events, &nevents); init_multiplex(); /* 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); y = dummy3(x, iters); /* Measure one run */ t1 = PAPI_get_real_usec(); y = dummy3(x, iters); t1 = PAPI_get_real_usec() - t1; if (t1 < 1000000) /* Scale up execution time to match t2 */ { iters = iters * (1000000/t1); printf("Modified iteration count to %d\n\n",iters); } /* Now loop through the items one at a time */ ref_measurements(iters, &eventset, events, nevents, refvalues); /* Now check multiplexed */ if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(eventset, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); if ((retval = PAPI_add_events(eventset, events, nevents))) test_fail(__FILE__, __LINE__, "PAPI_add_events", retval); printf("\nPAPI multiplexed measurements:\n"); 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, values))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); 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"); } } check_values(eventset, events, nevents, values, refvalues); if ((retval = PAPI_remove_events(eventset, events, nevents))) test_fail(__FILE__, __LINE__, "PAPI_remove_events", retval); 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; /* Now loop through the items one at a time */ ref_measurements(iters, &eventset, events, nevents, refvalues); check_values(eventset, events, nevents, values, refvalues); test_pass(__FILE__, NULL, 0); return 0; }
int main(int argc, char **argv) { PAPI_event_info_t info; char name2[PAPI_MAX_STR_LEN]; int i, j, retval, idx, repeats; int iters = NUM_FLOPS; double x = 1.1, y, dtmp; long long t1, t2; long long values[MAXEVENTS], refvals[MAXEVENTS]; int nsamples[MAXEVENTS], truelist[MAXEVENTS], ntrue; #ifdef STARTSTOP long long dummies[MAXEVENTS]; #endif int sleep_time = SLEEPTIME; double valsample[MAXEVENTS][REPEATS]; double valsum[MAXEVENTS]; double avg[MAXEVENTS]; double spread[MAXEVENTS]; int nevents = MAXEVENTS, nev1; int eventset = PAPI_NULL; int events[MAXEVENTS]; int eventidx[MAXEVENTS]; int eventmap[MAXEVENTS]; int fails; events[0] = PAPI_FP_INS; events[1] = PAPI_TOT_CYC; events[2] = PAPI_TOT_INS; events[3] = PAPI_TOT_IIS; events[4] = PAPI_INT_INS; events[5] = PAPI_STL_CCY; events[6] = PAPI_BR_INS; events[7] = PAPI_SR_INS; events[8] = PAPI_LD_INS; for (i = 0; i < MAXEVENTS; i++) { values[i] = 0; valsum[i] = 0; nsamples[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("\nFunctional check of multiplexing routines.\n"); printf("Adding and removing events from an event set.\n\n"); } if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); #ifdef MPX init_multiplex(); #endif if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); #ifdef MPX /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(eventset, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); #endif nevents = MAXEVENTS; for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(eventset, events[i]))) { for (j = i; j < MAXEVENTS; j++) events[j] = events[j + 1]; nevents--; i--; } } if (nevents < 3) 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); j = nevents; for (i = 1; i < nevents; i = i + 2) eventidx[--j] = i; for (i = 0; i < nevents; i = i + 2) eventidx[--j] = i; assert(j == 0); for (i = 0; i < nevents; i++) eventmap[i] = i; x = 1.0; if (!TESTS_QUIET) printf("\nReference run:\n"); t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); PAPI_read(eventset, refvals); t2 = PAPI_get_real_usec(); ntrue = nevents; PAPI_list_events(eventset, truelist, &ntrue); if (!TESTS_QUIET) { printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("%20s %16s %-15s %-15s\n", "PAPI measurement:", "Acquired count", "Expected event", "PAPI_list_events"); } if (!TESTS_QUIET) { for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); PAPI_event_code_to_name(truelist[j], name2); if (!TESTS_QUIET) printf("%20s = %16lld %-15s %-15s %s\n", info.short_descr, refvals[j], info.symbol, name2, strcmp(info.symbol, name2) ? "*** MISMATCH ***" : ""); } printf("\n"); } nev1 = nevents; repeats = nevents * 4; for (i = 0; i < repeats; i++) { if ((i % nevents) + 1 == nevents) continue; if (!TESTS_QUIET) printf("\nTest %d (of %d):\n", i + 1 - i / nevents, repeats - 4); if ((retval = PAPI_stop(eventset, values))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); j = eventidx[i % nevents]; if ((i / nevents) % 2 == 0) { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) printf("Removing event[%d]: %s\n", j, info.short_descr); if ((retval = PAPI_remove_event(eventset, events[j]))) test_fail(__FILE__, __LINE__, "PAPI_remove_event", retval); nev1--; for (idx = 0; eventmap[idx] != j; idx++); for (j = idx; j < nev1; j++) eventmap[j] = eventmap[j + 1]; } else { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) printf("Adding event[%d]: %s\n", j, info.short_descr); if ((retval = PAPI_add_event(eventset, events[j]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); eventmap[nev1] = j; nev1++; } if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); x = 1.0; #ifndef STARTSTOP if ((retval = PAPI_reset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_reset", retval); #else if ((retval = PAPI_stop(eventset, dummies))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); #endif t1 = PAPI_get_real_usec(); y = dummy3(x, iters); PAPI_read(eventset, values); t2 = PAPI_get_real_usec(); if (!TESTS_QUIET) { printf("\n(calculated independent of PAPI)\n"); printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("%20s %16s %-15s %-15s\n", "PAPI measurement:", "Acquired count", "Expected event", "PAPI_list_events"); } ntrue = nev1; PAPI_list_events(eventset, truelist, &ntrue); for (j = 0; j < nev1; j++) { idx = eventmap[j]; /* printf("Mapping: Counter %d -> slot %d.\n",j,idx); */ PAPI_get_event_info(events[idx], &info); PAPI_event_code_to_name(truelist[j], name2); if (!TESTS_QUIET) printf("%20s = %16lld %-15s %-15s %s\n", info.short_descr, values[j], info.symbol, name2, strcmp(info.symbol, name2) ? "*** MISMATCH ***" : ""); dtmp = (double) values[j]; valsum[idx] += dtmp; valsample[idx][nsamples[idx]] = dtmp; nsamples[idx]++; } if (!TESTS_QUIET) printf("\n"); } if (!TESTS_QUIET) { printf("\n\nEstimated variance relative to average counts:\n"); for (j = 0; j < nev1; j++) printf(" Event %.2d", j); printf("\n"); } fails = nevents; /* Due to limited precision of floating point cannot really use typical standard deviation compuation for large numbers with very small variations. Instead compute the std devation problems with precision. */ for (j = 0; j < nev1; j++) { avg[j] = valsum[j] / nsamples[j]; spread[j] = 0; for (i=0; i < nsamples[j]; ++i) { double diff = (valsample[j][i] - avg[j]); spread[j] += diff * diff; } spread[j] = sqrt(spread[j] / nsamples[j]) / avg[j]; if (!TESTS_QUIET) printf("%9.2g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) fails--; else if (values[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ fails--; } if (!TESTS_QUIET) { printf("\n\n"); for (j = 0; j < nev1; j++) { PAPI_get_event_info(events[j], &info); printf("Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n", j, avg[j], spread[j], nsamples[j], info.short_descr); } printf("\n\n"); } if (fails) test_fail(__FILE__, __LINE__, "Values differ from reference", fails); else test_pass(__FILE__, NULL, 0); return 0; }
int main() { double *a; double *b; double *c; int i = 0, j = 0, k = 0; int *events; // Array of events long long *values; // Array of values events int EventSet = PAPI_NULL; // Handle for a PAPI event set as created by PAPI_create_eventset (3) int retval; // Test fail function int num_event = 0; // Number of events int max_event; // Number of available events int EventCode = 0; // Event code PAPI_event_info_t pset; // PAPI_event_info_t Struct Reference char evname[PAPI_MAX_STR_LEN]; // Symbol event /* Memory asignament to matrixs*/ if((a = (double *)malloc(mrows * ncolumns * sizeof(double))) == NULL) printf("Error malloc matrix a[%d]\n",mrows * ncolumns); if((b = (double *)malloc(ncolumns * pcolumns * sizeof(double))) == NULL) printf("Error malloc matrix b[%d]\n",mrows * ncolumns); if((c = (double *)malloc(mrows * pcolumns * sizeof(double))) == NULL) printf("Error malloc matrix c[%d]\n",mrows * ncolumns); /* Initialize the Matrix arrays */ initmat(a, b, mrows, ncolumns, pcolumns); /* Initialize the PAPI library */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); /* Enable and initialize multiplex support */ retval = PAPI_multiplex_init(); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval ); /* Create an EventSet */ retval = PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* Assign it to the CPU component */ retval = PAPI_assign_eventset_component(EventSet, 0); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); /* Convert the EventSet to a multiplexed event set */ retval = PAPI_set_multiplex(EventSet); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); /* Obtaining the number of available events */ max_event = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); printf("\nNumber of available events: %d", max_event ); /* Fill up the event set with as many non-derived events as we can */ EventCode = PAPI_PRESET_MASK; do { if ( PAPI_get_event_info( EventCode, &pset ) == PAPI_OK ) { if ( pset.count && ( strcmp( pset.derived, "NOT_DERIVED" ) == 0 ) ) { retval = PAPI_add_event( EventSet, ( int ) pset.event_code ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); else { //printf( "Added %s\n", pset.symbol ); num_event++; } } } } while ( ( PAPI_enum_event( &EventCode, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) && ( num_event < max_event ) ); /* Memory asignament to values and events*/ events = ( int * ) malloc( ( size_t ) num_event * sizeof ( int ) ); if ( events == NULL ) test_fail( __FILE__, __LINE__, "Error malloc events", 0 ); values = ( long long * ) malloc( ( size_t ) num_event * sizeof ( long long ) ); if ( values == NULL ) test_fail( __FILE__, __LINE__, "Erro malloc values", 0 ); /* Start counting events */ if ((retval=PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); /* Matrix-Matrix multiply */ matmul(a, b, c, mrows, ncolumns, pcolumns); /* Read the counters */ if ((retval=PAPI_read( EventSet, values )) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read_counters", retval); /* Stop counting events */ if ((retval=PAPI_stop( EventSet, values )) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop_counters", retval); /* List the events in the event set */ retval = PAPI_list_events( EventSet, events, &num_event ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_list_events", retval ); /* Print results */ printf("\nNumber of non-zero events: %d\n", num_event ); printf( "\nCounts of non-zero available events........................................................\n" ); printf("Name: \t\t\t Value: \t Description:\n"); for ( i = 0; i < num_event; i++ ) { PAPI_event_code_to_name( events[i], evname ); // Obtaining name of available events PAPI_get_event_info(events[i], &pset); if ( values[i] != 0 ) printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr); } printf( "\nCounts of zero available events............................................................\n" ); printf("Name: \t\t\t Value: \t Description:\n"); for ( i = 0; i < num_event; i++ ) { PAPI_event_code_to_name( events[i], evname ); // Obtaining name of available events PAPI_get_event_info(events[i], &pset); if ( values[i] == 0 ) printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr); } /* Check if counter pair(s) had identical values */ for ( i = 0; i < num_event; i++ ) { for ( i = j+1; j < num_event; j++ ) { if ( ( i != j ) && ( values[i] == values[j] ) ) k++; } } if ( k != 0 ) { printf( "\nCaution: %d counter pair(s) had identical values\n", k ); } printf("\n"); /* Free memory */ free( events ); free( values ); free( a ); free( b ); free( c ); /* Cleaning events */ retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); /* Destroying events */ retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); return 0; }
int main( int argc, char **argv ) { int retval,i,j; int EventSet[EVENTS_TO_TRY][MAX_PACKAGES]; long long values[EVENTS_TO_TRY][MAX_PACKAGES]; char event_name[BUFSIZ]; char uncore_base[BUFSIZ]; char uncore_event[BUFSIZ]; int uncore_cidx=-1; int max_cbox=0; int core_to_use=0; const PAPI_hw_info_t *hwinfo; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init the PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Find the uncore PMU */ uncore_cidx=PAPI_get_component_index("perf_event_uncore"); if (uncore_cidx<0) { test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0); } /* Get hardware info */ hwinfo = PAPI_get_hardware_info(); if ( hwinfo == NULL ) { test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval); } /* Get event to use */ if (hwinfo->vendor == PAPI_VENDOR_INTEL) { if ( hwinfo->cpuid_family == 6) { switch(hwinfo->cpuid_model) { case 45: /* SandyBridge EP */ strncpy(event_name,"UNC_C_TOR_OCCUPANCY:ALL",BUFSIZ); strncpy(uncore_base,"snbep_unc_cbo",BUFSIZ); break; case 58: /* IvyBridge */ strncpy(event_name,"UNC_CBO_CACHE_LOOKUP:STATE_I:ANY_FILTER",BUFSIZ); strncpy(uncore_base,"ivb_unc_cbo",BUFSIZ); break; default: test_skip( __FILE__, __LINE__, "We only support IVB and SNB-EP for now", PAPI_ENOSUPP ); } } else { test_skip( __FILE__, __LINE__, "We only support IVB and SNB-EP for now", PAPI_ENOSUPP ); } } else { test_skip( __FILE__, __LINE__, "This test only supported Intel chips", PAPI_ENOSUPP ); } if (!TESTS_QUIET) { printf("Trying for %d sockets\n",hwinfo->sockets); printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores, hwinfo->ncpu); } for(i=0;i < hwinfo->sockets; i++) { /* perf_event provides which to use in "cpumask" */ /* but libpfm4 doesn't report this back to us (yet) */ core_to_use=i*hwinfo->threads*hwinfo->cores; if (!TESTS_QUIET) { printf("Using core %d for socket %d\n",core_to_use,i); } for(j=0;j<EVENTS_TO_TRY;j++) { /* Create an eventset */ EventSet[j][i]=PAPI_NULL; retval = PAPI_create_eventset(&EventSet[j][i]); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } /* Set a component for the EventSet */ retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx); if (retval!=PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval); } /* we need to set to a certain cpu for uncore to work */ PAPI_cpu_option_t cpu_opt; cpu_opt.eventset=EventSet[j][i]; cpu_opt.cpu_num=core_to_use; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to PAPI_CPU_ATTACH; need to run as root", retval); } /* Default Granularity should work */ /* Default domain should work */ /* Add our uncore event */ sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name); retval = PAPI_add_named_event(EventSet[j][i], uncore_event); if (retval != PAPI_OK) { max_cbox=j; break; } if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i); } } for(i=0;i < hwinfo->sockets; i++) { for(j=0;j<max_cbox;j++) { if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]); /* Start PAPI */ retval = PAPI_start( EventSet[j][i] ); if ( retval != PAPI_OK ) { printf("Error starting socket %d cbox %d\n",i,j); test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } } } /* our work code */ do_flops( NUM_FLOPS ); /* Stop PAPI */ for(i=0;i < hwinfo->sockets; i++) { for(j=0;j<max_cbox;j++) { retval = PAPI_stop( EventSet[j][i],&values[j][i] ); if ( retval != PAPI_OK ) { printf("Error stopping socket %d cbox %d\n",i,j); test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } } } /* Print Results */ if ( !TESTS_QUIET ) { for(i=0;i < hwinfo->sockets; i++) { printf("Socket %d\n",i); for(j=0;j<max_cbox;j++) { printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]); } } } PAPI_shutdown(); test_pass( __FILE__, NULL, 0 ); return 0; }
/* ** GPTLcreate_and_start_events: Create and start the PAPI eventset. ** Threaded routine to create the "event set" (PAPI terminology) and start ** the counters. This is only done once, and is called from get_thread_num ** for the first time for the thread. ** ** Input args: ** t: thread number ** ** Return value: 0 (success) or GPTLerror (failure) */ int GPTLcreate_and_start_events (const int t) /* thread number */ { int ret; /* return code */ int n; /* loop index over events */ char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ static const char *thisfunc = "GPTLcreate_and_start_events"; /* ** Set the domain to count all contexts. Only needs to be set once for all threads */ if ((ret = PAPI_set_domain (PAPI_DOM_ALL)) != PAPI_OK) return GPTLerror ("%s: thread %d failure setting PAPI domain: %s\n", thisfunc, t, PAPI_strerror (ret)); /* Create the event set */ if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: thread %d failure creating eventset: %s\n", thisfunc, t, PAPI_strerror (ret)); if (verbose) printf ("%s: successfully created eventset for thread %d\n", thisfunc, t); /* Add requested events to the event set */ for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { if (verbose) { fprintf (stderr, "%s\n", PAPI_strerror (ret)); ret = PAPI_event_code_to_name (papieventlist[n], eventname); fprintf (stderr, "%s: failure adding event:%s\n", thisfunc, eventname); } if (enable_multiplexing) { if (verbose) printf ("Trying multiplexing...\n"); is_multiplexed = true; break; } else return GPTLerror ("enable_multiplexing is false: giving up\n"); } } if (is_multiplexed) { /* Cleanup the eventset for multiplexing */ if ((ret = PAPI_cleanup_eventset (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_destroy_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failure creating eventset: %s\n", thisfunc, PAPI_strerror (ret)); /* ** Assign EventSet to component 0 (cpu). This step is MANDATORY in recent PAPI releases ** in order to enable event multiplexing */ if ((ret = PAPI_assign_eventset_component (EventSet[t], 0)) != PAPI_OK) return GPTLerror ("%s: thread %d failure in PAPI_assign_eventset_component: %s\n", thisfunc, t, PAPI_strerror (ret)); if ((ret = PAPI_multiplex_init ()) != PAPI_OK) return GPTLerror ("%s: failure from PAPI_multiplex_init%s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_set_multiplex (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failure from PAPI_set_multiplex: %s\n", thisfunc, PAPI_strerror (ret)); for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { ret = PAPI_event_code_to_name (papieventlist[n], eventname); return GPTLerror ("%s: failure adding event:%s Error was: %s\n", thisfunc, eventname, PAPI_strerror (ret)); } } } /* Start the event set. It will only be read from now on--never stopped */ if ((ret = PAPI_start (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failed to start event set: %s\n", thisfunc, PAPI_strerror (ret)); return 0; }
int main( int argc, char **argv ) { int retval, pid, status, EventSet = PAPI_NULL; long long int values[] = {0,0}; PAPI_option_t opt; tests_quiet( argc, argv ); if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval ); if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); memset( &opt, 0x0, sizeof ( PAPI_option_t ) ); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = EventSet; if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) { if ( retval == PAPI_ECMP) { test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval ); } else { test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval ); } } if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_query_event( PAPI_FP_INS ); if ( retval == PAPI_ENOEVNT ) { test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval); values[1] = NUM_FLOPS; /* fake a return value to pass the test */ } else if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); else if ( ( retval = PAPI_add_event( EventSet, PAPI_FP_INS ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); pid = fork( ); if ( pid == 0 ) { do_flops( NUM_FLOPS ); exit( 0 ); } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); if (!TESTS_QUIET) { printf( "Test case inherit: parent starts, child works, parent stops.\n" ); printf( "------------------------------------------------------------\n" ); printf( "Test run : \t1\n" ); printf( "PAPI_FP_INS : \t%lld\n", values[1] ); printf( "PAPI_TOT_CYC: \t%lld\n", values[0] ); printf( "------------------------------------------------------------\n" ); printf( "Verification:\n" ); printf( "Row 1 at least %d\n", NUM_FLOPS ); printf( "Row 2 greater than row 1\n"); } if ( values[1] < NUM_FLOPS) { test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 ); } if ( values[0] < values[1]) { test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC < PAPI_FP_INS", 1 ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
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; int EventSet1 = PAPI_NULL; int EventSet2 = PAPI_NULL; int EventSet3 = PAPI_NULL; int EventSet4 = PAPI_NULL; int EventSet5 = PAPI_NULL; int EventSet6 = PAPI_NULL; int EventSet7 = PAPI_NULL; int EventSet8 = PAPI_NULL; int EventSet9 = PAPI_NULL; int EventSet10 = PAPI_NULL; PAPI_domain_option_t domain_opt; PAPI_granularity_option_t gran_opt; PAPI_cpu_option_t cpu_opt; cpu_set_t mask; long long dom_user_values[1],dom_userkernel_values[1],dom_all_values[1]; long long grn_thr_values[1],grn_proc_values[1]; long long grn_sys_values[1],grn_sys_cpu_values[1]; long long total_values[1],total_affinity_values[1]; long long total_all_values[1]; dom_user_values[0]=0; dom_userkernel_values[0]=0; dom_all_values[0]=0; grn_thr_values[0]=0; grn_proc_values[0]=0; grn_sys_values[0]=0; grn_sys_cpu_values[0]=0; total_values[0]=0; total_affinity_values[0]=0; total_all_values[0]=0; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init the PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /***************************/ /***************************/ /* Default, user events */ /***************************/ /***************************/ if (!TESTS_QUIET) { printf("\nTrying PAPI_TOT_CYC with different domains:\n"); } if (!TESTS_QUIET) { printf("\tPAPI_DOM_USER:\t\t\t"); } retval = PAPI_create_eventset(&EventSet1); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_add_named_event(EventSet1, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet1, dom_user_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",dom_user_values[0]); } /***************************/ /***************************/ /* User+Kernel events */ /***************************/ /***************************/ if (!TESTS_QUIET) { printf("\tPAPI_DOM_USER|PAPI_DOM_KERNEL:\t"); } retval = PAPI_create_eventset(&EventSet2); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet2, 0); /* we need to set domain to be as inclusive as possible */ domain_opt.def_cidx=0; domain_opt.eventset=EventSet2; domain_opt.domain=PAPI_DOM_USER|PAPI_DOM_KERNEL; retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt); if (retval != PAPI_OK) { if (retval==PAPI_EPERM) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_DOM_ALL; need to run as root", retval); } else { test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval); } } retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet2, dom_userkernel_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",dom_userkernel_values[0]); } /***************************/ /***************************/ /* DOMAIN_ALL events */ /***************************/ /***************************/ if (!TESTS_QUIET) { printf("\tPAPI_DOM_ALL:\t\t\t"); } retval = PAPI_create_eventset(&EventSet3); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet3, 0); /* we need to set domain to be as inclusive as possible */ domain_opt.def_cidx=0; domain_opt.eventset=EventSet3; domain_opt.domain=PAPI_DOM_ALL; retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt); if (retval != PAPI_OK) { if (retval==PAPI_EPERM) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_DOM_ALL; need to run as root", retval); } else { test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval); } } retval = PAPI_add_named_event(EventSet3, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet3 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet3, dom_all_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",dom_all_values[0]); } /***************************/ /***************************/ /* PAPI_GRN_THR events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\nTrying different granularities:\n"); } if ( !TESTS_QUIET ) { printf("\tPAPI_GRN_THR:\t\t\t"); } retval = PAPI_create_eventset(&EventSet4); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet4, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet4; gran_opt.granularity=PAPI_GRN_THR; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_GRN_THR", retval); } retval = PAPI_add_named_event(EventSet4, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet4 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet4, grn_thr_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",grn_thr_values[0]); } /***************************/ /***************************/ /* PAPI_GRN_PROC events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\tPAPI_GRN_PROC:\t\t\t"); } retval = PAPI_create_eventset(&EventSet5); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet5, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet5; gran_opt.granularity=PAPI_GRN_PROC; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_PROC\n"); } } else { retval = PAPI_add_named_event(EventSet5, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet5 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet5, grn_proc_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",grn_proc_values[0]); } } /***************************/ /***************************/ /* PAPI_GRN_SYS events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\tPAPI_GRN_SYS:\t\t\t"); } retval = PAPI_create_eventset(&EventSet6); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet6, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet6; gran_opt.granularity=PAPI_GRN_SYS; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_SYS\n"); } } else { retval = PAPI_add_named_event(EventSet6, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } } else { retval = PAPI_start( EventSet6 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet6, grn_sys_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("GRN_SYS PAPI_TOT_CYC: %lld\n",grn_sys_values[0]); } } } /****************************/ /****************************/ /* PAPI_GRN_SYS_CPU events */ /****************************/ /****************************/ if ( !TESTS_QUIET ) { printf("\tPAPI_GRN_SYS_CPU:\t\t"); } retval = PAPI_create_eventset(&EventSet7); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet7, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet7; gran_opt.granularity=PAPI_GRN_SYS_CPU; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_SYS_CPU\n"); } } else { retval = PAPI_add_named_event(EventSet7, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet7 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet7, grn_sys_cpu_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",grn_sys_cpu_values[0]); } } /***************************/ /***************************/ /* SYS and ATTACH events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\nPAPI_GRN_SYS plus CPU attach:\n"); } if ( !TESTS_QUIET ) { printf("\tGRN_SYS, DOM_USER, CPU 0 attach:\t"); } retval = PAPI_create_eventset(&EventSet8); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet8, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet8; gran_opt.granularity=PAPI_GRN_SYS; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_SYS\n"); } } else { /* we need to set to a certain cpu */ cpu_opt.eventset=EventSet8; cpu_opt.cpu_num=0; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { if (retval==PAPI_EPERM) { test_skip( __FILE__, __LINE__, "this test; trying to CPU_ATTACH; need to run as root", retval); } test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval); } retval = PAPI_add_named_event(EventSet8, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet8 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet8, total_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",total_values[0]); } } /***************************/ /***************************/ /* SYS and ATTACH, bind CPU events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\tGRN_SYS, DOM_USER, CPU 0 affinity:\t"); } /* Set affinity to CPU 0 */ CPU_ZERO(&mask); CPU_SET(0,&mask); retval=sched_setaffinity(0, sizeof(mask), &mask); if (retval<0) { if (!TESTS_QUIET) { printf("Setting affinity failed: %s\n",strerror(errno)); } } else { retval = PAPI_create_eventset(&EventSet9); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet9, 0); /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet9; gran_opt.granularity=PAPI_GRN_SYS; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_SYS\n"); } } else { /* we need to set to a certain cpu for uncore to work */ cpu_opt.eventset=EventSet9; cpu_opt.cpu_num=0; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval); } retval = PAPI_add_named_event(EventSet9, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet9 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet9, total_affinity_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",total_affinity_values[0]); } } } /***************************/ /***************************/ /* SYS and ATTACH, bind CPU events */ /***************************/ /***************************/ if ( !TESTS_QUIET ) { printf("\tGRN_SYS, DOM_ALL, CPU 0 affinity:\t"); } /* Set affinity to CPU 0 */ CPU_ZERO(&mask); CPU_SET(0,&mask); retval=sched_setaffinity(0, sizeof(mask), &mask); if (retval<0) { if (!TESTS_QUIET) { printf("Setting affinity failed: %s\n",strerror(errno)); } } else { retval = PAPI_create_eventset(&EventSet10); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } retval = PAPI_assign_eventset_component(EventSet10, 0); /* Set DOM_ALL */ domain_opt.def_cidx=0; domain_opt.eventset=EventSet10; domain_opt.domain=PAPI_DOM_ALL; retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt); if (retval != PAPI_OK) { if (retval==PAPI_EPERM) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_DOM_ALL; need to run as root", retval); } else { test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval); } } /* Set the granularity to system-wide */ gran_opt.def_cidx=0; gran_opt.eventset=EventSet10; gran_opt.granularity=PAPI_GRN_SYS; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { if (!TESTS_QUIET) { printf("Unable to set PAPI_GRN_SYS\n"); } } else { /* we need to set to a certain cpu for uncore to work */ cpu_opt.eventset=EventSet10; cpu_opt.cpu_num=0; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval); } retval = PAPI_add_named_event(EventSet10, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { printf("Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } retval = PAPI_start( EventSet10 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); retval = PAPI_stop( EventSet10, total_all_values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } if ( !TESTS_QUIET ) { printf("%lld\n",total_all_values[0]); } } } /**************/ /* Validation */ /**************/ if ( !TESTS_QUIET ) { printf("\n"); } if ( !TESTS_QUIET ) { printf("Validating:\n"); printf("\tDOM_USER|DOM_KERNEL (%lld) > DOM_USER (%lld)\n", dom_userkernel_values[0],dom_user_values[0]); } if (dom_user_values[0] > dom_userkernel_values[0]) { test_fail( __FILE__, __LINE__, "DOM_USER too high", 0 ); } if ( !TESTS_QUIET ) { printf("\n"); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int retval; int EventSet = PAPI_NULL; int EventSet2 = PAPI_NULL; long long values[1],values2[1]; char *uncore_event=NULL; char event_name[BUFSIZ]; int uncore_cidx=-1; const PAPI_component_info_t *info; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init the PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Find the uncore PMU */ uncore_cidx=PAPI_get_component_index("perf_event_uncore"); if (uncore_cidx<0) { test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0); } /* Check if component disabled */ info=PAPI_get_component_info(uncore_cidx); if (info->disabled) { test_skip(__FILE__,__LINE__,"uncore component disabled",0); } /* Get a relevant event name */ uncore_event=get_uncore_event(event_name, BUFSIZ); if (uncore_event==NULL) { test_skip( __FILE__, __LINE__, "PAPI does not support uncore on this processor", PAPI_ENOSUPP ); } /* Create an eventset */ retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } /* Create another eventset */ retval = PAPI_create_eventset(&EventSet2); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } /* Set a component for the EventSet */ retval = PAPI_assign_eventset_component(EventSet, uncore_cidx); /* we need to set to a certain cpu for uncore to work */ PAPI_cpu_option_t cpu_opt; cpu_opt.eventset=EventSet; cpu_opt.cpu_num=0; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to PAPI_CPU_ATTACH; need to run as root", retval); } /* we need to set the granularity to system-wide for uncore to work */ PAPI_granularity_option_t gran_opt; gran_opt.def_cidx=0; gran_opt.eventset=EventSet; gran_opt.granularity=PAPI_GRN_SYS; retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_GRN_SYS", retval); } /* we need to set domain to be as inclusive as possible */ PAPI_domain_option_t domain_opt; domain_opt.def_cidx=0; domain_opt.eventset=EventSet; domain_opt.domain=PAPI_DOM_ALL; retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to set PAPI_DOM_ALL; need to run as root", retval); } /* Add our uncore event */ retval = PAPI_add_named_event(EventSet, uncore_event); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to use event %s\n", uncore_event); } test_fail(__FILE__, __LINE__, "adding uncore event ",retval); } /* Add PAPI_TOT_CYC */ retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC"); if (retval != PAPI_OK) { if ( !TESTS_QUIET ) { fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n"); } test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval); } /* Start PAPI */ 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 ); } /* our work code */ do_flops( NUM_FLOPS ); /* Stop PAPI */ retval = PAPI_stop( EventSet, values ); 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 ); } if ( !TESTS_QUIET ) { printf("Uncore and regular event test:\n"); printf("Using uncore event %s\n",uncore_event); printf("\t%s: %lld\n",uncore_event,values[0]); printf("\t%s: %lld\n","PAPI_TOT_CYC",values2[0]); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int status, retval, num_tests = 1, tmp; int EventSet1 = PAPI_NULL; long long **values; long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc; char event_name[PAPI_MAX_STR_LEN];; const PAPI_hw_info_t *hw_info; const PAPI_component_info_t *cmpinfo; pid_t pid; /* Fork before doing anything with the PMU */ setbuf(stdout,NULL); pid = fork( ); if ( pid < 0 ) test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS ); if ( pid == 0 ) exit( wait_for_attach_and_loop( ) ); tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ /* Master only process below here */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 ); if ( cmpinfo->attach == 0 ) test_skip( __FILE__, __LINE__, "Platform does not support attaching", 0 ); hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 ); /* 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 */ retval = PAPI_create_eventset(&EventSet1); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); /* Force addition of component */ retval = PAPI_assign_eventset_component( EventSet1, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); /* The following call causes this test to fail for perf_events */ retval = PAPI_attach( EventSet1, ( unsigned long ) pid ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); sprintf(event_name,"PAPI_TOT_CYC"); retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_add_event(EventSet1, PAPI_FP_INS); if ( retval == PAPI_ENOEVNT ) { test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval); } else if ( retval != PAPI_OK ) { test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); } values = allocate_test_space( 1, 2); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); elapsed_virt_us = PAPI_get_virt_usec( ); elapsed_virt_cyc = PAPI_get_virt_cyc( ); printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace); pid_t child = wait( &status ); printf( "Debugger exited wait() with %d\n",child ); if (WIFSTOPPED( status )) { printf( "Child has stopped due to signal %d (%s)\n", WSTOPSIG( status ), strsignal(WSTOPSIG( status )) ); } if (WIFSIGNALED( status )) { printf( "Child %ld received signal %d (%s)\n", (long)child, WTERMSIG(status) , strsignal(WTERMSIG( status )) ); } printf("After %d\n",retval); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); printf("Continuing\n"); if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } do { child = wait( &status ); printf( "Debugger exited wait() with %d\n", child); if (WIFSTOPPED( status )) { printf( "Child has stopped due to signal %d (%s)\n", WSTOPSIG( status ), strsignal(WSTOPSIG( status )) ); } if (WIFSIGNALED( status )) { printf( "Child %ld received signal %d (%s)\n", (long)child, WTERMSIG(status) , strsignal(WTERMSIG( status )) ); } } while (!WIFEXITED( status )); printf("Child exited with value %d\n",WEXITSTATUS(status)); if (WEXITSTATUS(status) != 0) test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC); retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us; elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc; elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; retval = PAPI_cleanup_eventset(EventSet1); if (retval != PAPI_OK) test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset(&EventSet1); if (retval != PAPI_OK) test_fail_exit( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); printf( "Test case: 3rd party attach start, stop.\n" ); printf( "-----------------------------------------------\n" ); tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) ); tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); printf( "Default granularity is: %d (%s)\n", tmp, stringify_granularity( tmp ) ); printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); printf ( "-------------------------------------------------------------------------\n" ); printf( "Test type : \t 1\n" ); printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] ); printf( TAB1, "PAPI_FP_INS : \t", ( values[0] )[1] ); printf( TAB1, "Real usec : \t", elapsed_us ); printf( TAB1, "Real cycles : \t", elapsed_cyc ); printf( TAB1, "Virt usec : \t", elapsed_virt_us ); printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc ); printf ( "-------------------------------------------------------------------------\n" ); printf( "Verification: none\n" ); test_pass( __FILE__, values, num_tests ); exit( 1 ); }
/** * Called by the CBTF collector service in order to start data collection. */ void cbtf_collector_start(const CBTF_DataHeader* header) { /** * Start sampling. * * Starts hardware counter (HWC) sampling for the thread executing this * function. Initializes the appropriate thread-local data structures and * then enables the sampling counter. * * @param arguments Encoded function arguments. */ /* Create and access our thread-local storage */ #ifdef USE_EXPLICIT_TLS TLS* tls = malloc(sizeof(TLS)); Assert(tls != NULL); CBTF_SetTLS(TLSKey, tls); #else TLS* tls = &the_tls; #endif Assert(tls != NULL); tls->defer_sampling=false; #ifndef NDEBUG IsCollectorDebugEnabled = (getenv("CBTF_DEBUG_COLLECTOR") != NULL); IsCollectorDetailsDebugEnabled = (getenv("CBTF_DEBUG_COLLECTOR_DETAILS") != NULL); #if defined (HAVE_OMPT) IsOMPTDebugEnabled = (getenv("CBTF_DEBUG_COLLECTOR_OMPT") != NULL); #endif #endif /* Decode the passed function arguments */ // Need to handle the arguments... CBTF_hwcsamp_start_sampling_args args; memset(&args, 0, sizeof(args)); args.sampling_rate = 100; /* First set defaults */ int hwcsamp_rate = 100; char* hwcsamp_papi_event = "PAPI_TOT_CYC,PAPI_TOT_INS"; #if defined (CBTF_SERVICE_USE_OFFLINE) char* hwcsamp_event_param = getenv("CBTF_HWCSAMP_EVENTS"); if (hwcsamp_event_param != NULL) { hwcsamp_papi_event=hwcsamp_event_param; } const char* sampling_rate = getenv("CBTF_HWCSAMP_RATE"); if (sampling_rate != NULL) { hwcsamp_rate=atoi(sampling_rate); } args.collector = 1; args.experiment = 0; tls->data.interval = (uint64_t)(1000000000) / (uint64_t)(hwcsamp_rate);; #endif /* Initialize the actual data blob */ memcpy(&tls->header, header, sizeof(CBTF_DataHeader)); initialize_data(tls); /* We can not assign mpi rank in the header at this point as it may not * be set yet. assign an integer tid value. omp_tid is used regardless of * whether the application is using openmp threads. * libmonitor uses the same numbering scheme as openmp. */ tls->header.omp_tid = monitor_get_thread_num(); tls->header.id = strdup(cbtf_collector_unique_id); tls->header.time_begin = CBTF_GetTime(); #ifndef NDEBUG if (IsCollectorDebugEnabled) { fprintf(stderr,"[%ld,%d] ENTER cbtf_collector_start\n",tls->header.pid,tls->header.omp_tid); } #endif if(hwcsamp_papi_init_done == 0) { #ifndef NDEBUG if (IsCollectorDebugEnabled) { fprintf(stderr,"[%ld,%d] cbtf_collector_start: initialize papi\n",tls->header.pid,tls->header.omp_tid); } #endif CBTF_init_papi(); tls->EventSet = PAPI_NULL; tls->data.clock_mhz = (float) hw_info->mhz; hwcsamp_papi_init_done = 1; } else { tls->data.clock_mhz = (float) hw_info->mhz; } /* PAPI SETUP */ CBTF_Create_Eventset(&tls->EventSet); int rval = PAPI_OK; #ifndef NDEBUG if (IsCollectorDebugEnabled) { fprintf(stderr, "PAPI Version: %d.%d.%d.%d\n", PAPI_VERSION_MAJOR( PAPI_VERSION ), PAPI_VERSION_MINOR( PAPI_VERSION ), PAPI_VERSION_REVISION( PAPI_VERSION ), PAPI_VERSION_INCREMENT( PAPI_VERSION ) ); fprintf(stderr,"System has %d hardware counters.\n", PAPI_num_counters()); } #endif /* In Component PAPI, EventSets must be assigned a component index * before you can fiddle with their internals. 0 is always the cpu component */ #if (PAPI_VERSION_MAJOR(PAPI_VERSION)>=4) rval = PAPI_assign_eventset_component( tls->EventSet, 0 ); if (rval != PAPI_OK) { CBTF_PAPIerror(rval,"CBTF_Create_Eventset assign_eventset_component"); return; } #endif /* NOTE: if multiplex is turned on, papi internaly uses a SIGPROF handler. * Since we are sampling potentially with SIGPROF or now SIGRTMIN and we * prefer to limit our events to 6, we do not need multiplexing. */ if (getenv("CBTF_HWCSAMP_MULTIPLEX") != NULL) { #if !defined(RUNTIME_PLATFORM_BGP) rval = PAPI_set_multiplex( tls->EventSet ); if ( rval == PAPI_ENOSUPP) { fprintf(stderr,"CBTF_Create_Eventset: Multiplex not supported\n"); } else if (rval != PAPI_OK) { CBTF_PAPIerror(rval,"CBTF_Create_Eventset set_multiplex"); } #endif } /* TODO: check return values of direct PAPI calls * and handle them as needed. */ /* Rework the code here to call PAPI directly rather than * call any OPENSS helper functions due to inconsitent * behaviour seen on various lab systems */ int eventcode = 0; rval = PAPI_OK; if (hwcsamp_papi_event != NULL) { char *tfptr, *saveptr=NULL, *tf_token; tfptr = strdup(hwcsamp_papi_event); for (tf_token = strtok_r(tfptr, ",", &saveptr); tf_token != NULL; tf_token = strtok_r(NULL, ",", &saveptr) ) { PAPI_event_name_to_code(tf_token,&eventcode); rval = PAPI_add_event(tls->EventSet,eventcode); if (rval != PAPI_OK) { CBTF_PAPIerror(rval,"CBTF_Create_Eventset PAPI_event_name_to_code"); } } if (tfptr) free(tfptr); } else { PAPI_event_name_to_code("PAPI_TOT_CYC",&eventcode); rval = PAPI_add_event(tls->EventSet,eventcode); PAPI_event_name_to_code("PAPI_TOT_INS",&eventcode); rval = PAPI_add_event(tls->EventSet,eventcode); } #if defined (HAVE_OMPT) /* these are ompt specific.*/ /* initialize the flags and counts for idle,wait_barrier. */ tls->thread_idle = tls->thread_wait_barrier = tls->thread_barrier = false; #endif /* Begin sampling */ tls->header.time_begin = CBTF_GetTime(); CBTF_Start(tls->EventSet); CBTF_Timer(tls->data.interval, hwcsampTimerHandler); }
int main (int argc, char *argv[]) { int i, j; //papi init code begin long long s; long long e; int retval; int eventcode; PAPI_option_t opt; if(PAPI_VER_CURRENT != PAPI_library_init(PAPI_VER_CURRENT)){ printf("Can't initiate PAPI library!\n"); exit(-1); } if (PAPI_thread_init(pthread_self) != PAPI_OK) { printf("Can't thread init!\n"); exit(-1); } eventset = PAPI_NULL; if(PAPI_create_eventset(&eventset) != PAPI_OK){ printf("Can't create eventset!\n"); exit(-3); } if ( ( retval = PAPI_assign_eventset_component( eventset, 0 ) ) != PAPI_OK ) { printf("Can't assign_event_component!\n"); exit(-3); } memset( &opt, 0x0, sizeof ( PAPI_option_t ) ); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = eventset; if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) { printf("Can't set inherit!\n"); exit(-3); } PAPI_event_name_to_code("MEM_LOAD_MISC_RETIRED:LLC_MISS",&eventcode); events[1] = eventcode; PAPI_event_name_to_code("CPU_CLK_UNHALTED:THREAD_P",&eventcode); events[2] = eventcode; for(i=0;i<3;i++) { retval = PAPI_add_event(eventset, events[i]); if(retval != PAPI_OK){ printf("error %d\n",retval); exit(-4); } } //papi init code end /* create output file in gnuplot format */ gnuplotfile = fopen("test2_tcm.txt", "w"); fprintf(gnuplotfile,"#time(ms)\tMEM_LOAD_MISC_RETIRED:LLC_MISS\tCPU_CLK_UNHALTED:THREAD_P\n"); s = PAPI_get_real_usec(); PAPI_start(eventset); test(); PAPI_stop(eventset, values); e = PAPI_get_real_usec(); fclose(gnuplotfile); /*Print out PAPI reading*/ printf("Wallclock time: %lld usec\n",e-s); printf("Total Cycles\t%lld\n", values[0]); printf("MEM_LOAD_MISC_RETIRED:LLC_MISS\t%lld\n", values[1]); printf("CPU_CLK_UNHALTED:THREAD_P\t%lld\n", values[2]); return 0; }
void *watch_process(void* _pid) { pid_t pid = *((pid_t*)_pid); printf("%d\n", pid); int retval, EventSet = PAPI_NULL; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L1D_HIT", "MEM_LOAD_RETIRED:L2_HIT", "LLC_REFERENCES"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "L2_DATA_RQSTS:ANY" }; char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY", "BR_INST_RETIRED:ALL_BRANCHES", "BR_INST_EXEC:ANY", "BR_MISP_EXEC:ANY" }; unsigned int native_events[NB_EVENTS]; long long values[NB_EVENTS]; int err; /* Initialize the library */ if ( (err = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI library init error! %d\n", err); exit(1); } if ( (err = PAPI_multiplex_init()) != PAPI_OK) { fprintf(stderr, "PAPI multiplex init error! %d\n", err); exit(1); } if (PAPI_thread_init(pthread_self) != PAPI_OK) { fprintf(stderr, "PAPI thread init error! %d\n", err); exit(1); } //sched_setaffinity(0, 0); //if ((retval = PAPI_set_granularity(PAPI_GRN_MAX)) != PAPI_OK) { // fprintf(stderr, "PAPI set granurality error! %d, %d, %d, %d, %d\n", retval, PAPI_EINVAL, PAPI_ENOEVST, PAPI_ENOCMP, PAPI_EISRUN); // exit(1); //} // Traduction des string en code name_to_code(events_name, NB_EVENTS, native_events); // Vérification des évènements check_events(native_events, NB_EVENTS); if (PAPI_create_eventset(&EventSet) != PAPI_OK) { fprintf(stderr, "PAPI EventSet init error!\n"); exit(1); } if ( (err = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) { fprintf(stderr, "PAPI assign component error!\n%s\n", PAPI_strerror(err)); exit(1); } if ( ( err = PAPI_set_multiplex(EventSet) ) != PAPI_OK) { fprintf(stderr, "PAPI set multiplex error!\n%s\n", PAPI_strerror(err)); exit(1); } if ( (retval = PAPI_add_events(EventSet, native_events, NB_EVENTS) ) != PAPI_OK) { fprintf(stderr, "PAPI add events error!\n%s\n", PAPI_strerror(retval) ); exit(1); } if (PAPI_attach(EventSet, pid) != PAPI_OK) exit(1); while(while_watch) { /* Start counting */ if (PAPI_start(EventSet) != PAPI_OK) { fprintf(stderr, "PAPI start error!\n"); exit(1); } usleep(1000000); if (PAPI_stop(EventSet, values) != PAPI_OK) { fprintf(stderr, "PAPI stop error!\n"); exit(1); } print_values(events_name, values, NB_EVENTS); } return 0; }
void mainloop( int arg ) { int allvalid; long long *values; int EventSet = PAPI_NULL; int retval, i, j = 2, skipped_counters=0; PAPI_event_info_t pset; ( void ) arg; /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); init_multiplex( ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ 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_ENOSUPP) { test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); } else if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); if ( ( retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) ) != PAPI_OK ) { if ( retval == PAPI_ECMP ) test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval ); else test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval ); } retval = PAPI_add_event( EventSet, PAPI_TOT_INS ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( !TESTS_QUIET ) { printf( "Added %s\n", "PAPI_TOT_INS" ); } retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( !TESTS_QUIET ) { printf( "Added %s\n", "PAPI_TOT_CYC" ); } values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) ); if ( values == NULL ) test_fail( __FILE__, __LINE__, "malloc", 0 ); for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) { retval = PAPI_get_event_info( i | PAPI_PRESET_MASK, &pset ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); if ( pset.count ) { printf( "Adding %s\n", pset.symbol ); retval = PAPI_add_event( EventSet, ( int ) pset.event_code ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( retval == PAPI_OK ) { printf( "Added %s\n", pset.symbol ); } else { printf( "Could not add %s\n", pset.symbol ); } do_stuff( ); if ( retval == PAPI_OK ) { retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); if ( values[j] ) { if ( ++j >= MAX_TO_ADD ) break; } else { retval = PAPI_remove_event( EventSet, ( int ) pset.event_code ); if ( retval == PAPI_OK ) printf( "Removed %s\n", pset.symbol ); /* This added because the test */ /* can take a long time if mplexing */ /* is broken and all values are 0 */ skipped_counters++; if (skipped_counters>MAX_TO_ADD) break; } } } } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); test_print_event_header( "multiplex3_pthreads:\n", EventSet ); allvalid = 0; for ( i = 0; i < MAX_TO_ADD; i++ ) { printf( ONENUM, values[i] ); if ( values[i] != 0 ) allvalid++; } printf( "\n" ); if ( !allvalid ) test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 ); retval = PAPI_cleanup_eventset( EventSet ); /* JT */ 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( values ); PAPI_shutdown( ); }
int case1(void) { int retval, i, EventSet = PAPI_NULL, j = 0, k = 0, allvalid = 1; int max_mux, nev, *events; long long *values; PAPI_event_info_t pset; char evname[PAPI_MAX_STR_LEN]; init_papi(); init_multiplex(); retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ 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); max_mux = PAPI_get_opt(PAPI_MAX_MPX_CTRS, NULL); if (max_mux > 32) max_mux = 32; /* Fill up the event set with as many non-derived events as we can */ printf("\nFilling the event set with as many non-derived events as we can...\n"); i = PAPI_PRESET_MASK; do { if (PAPI_get_event_info(i, &pset) == PAPI_OK) { if (pset.count && (strcmp(pset.derived,"NOT_DERIVED") == 0)) { retval = PAPI_add_event(EventSet, pset.event_code); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); else { printf("Added %s\n", pset.symbol); j++; } } } } while ((PAPI_enum_event(&i, PAPI_PRESET_ENUM_AVAIL) == PAPI_OK) && (j < max_mux)); events = (int *) malloc(j * sizeof(int)); if (events == NULL) test_fail(__FILE__, __LINE__, "malloc events", 0); values = (long long *) malloc(j * sizeof(long long)); if (values == NULL) test_fail(__FILE__, __LINE__, "malloc values", 0); do_stuff(); if (PAPI_start(EventSet) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_stuff(); retval = PAPI_stop(EventSet, values); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); nev =j; retval = PAPI_list_events(EventSet, events, &nev); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_list_events", retval); printf("\nEvent Counts:\n"); for (i = 0, allvalid = 0; i < j; i++) { PAPI_event_code_to_name(events[i], evname); printf(TAB1, evname, values[i]); if (values[i] == 0) allvalid++; } printf("\n"); if (allvalid){ printf("Caution: %d counters had zero values\n", allvalid); } for (i = 0, allvalid = 0; i < j; i++) { for (k = i+1; k < j; k++) { if ((i != k) && (values[i] == values[k])) { allvalid++; break; } } } if (allvalid){ printf("Caution: %d counter pair(s) had identical values\n", allvalid); } free(events); free(values); 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); return (SUCCESS); }
/* *______________________________________________ * *InitCmd -- * * This function is to add events to papi event set. * A list of events is taken as argument. * * Results: * The eventset is initialized. *________________________________________________ */ int InitCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if(objc!=2) { fprintf(stderr,"Usage: perft::init listOfEvents"); return 1; } int retval,eventCode; char* arg=Tcl_GetString(objv[1]); int argc, eventList; const char **argv; eventList= Tcl_SplitList(interp, arg, &argc, &argv); char **index=(char **)argv; if(papiState.eventsData==NULL) { AllocateStringArray(PAPI_MAX_EVENTS,PAPI_MAX_STRING_LENGTH,&papiState.eventsData); } else { retval=PAPI_cleanup_eventset(papiState.eventSet); if ( retval!= PAPI_OK) { HandlePapiError(retval); return 1; } // Free all memory and data structures, EventSet must be empty retval=PAPI_destroy_eventset(&papiState.eventSet); if ( retval!= PAPI_OK) { HandlePapiError(retval); return 1; } } papiState.eventSet=PAPI_NULL; papiState.numberOfEvents=0; retval=InitPapi(); if(retval==1) { return 1; } retval=InitPapiMultiplexing(); if(retval==1) { return 1; } retval=PAPI_assign_eventset_component(papiState.eventSet, 0); if ( retval!= PAPI_OK) { printf("Error in subroutine PAPI_assign_eventset_component"); HandlePapiError(retval); return 1; } retval=PAPI_set_multiplex(papiState.eventSet); if ( retval!= PAPI_OK) { printf("Error in subroutine PAPI_set_multiplex"); HandlePapiError(retval); return 1; } while(papiState.numberOfEvents<argc) { retval=PAPI_event_name_to_code(*index,&eventCode); if ( retval!= PAPI_OK) { printf("Error in getting information about event name: %s\n",*index); HandlePapiError(retval); return 1; } papiState.eventsData[papiState.numberOfEvents]=*index; retval=PAPI_add_event(papiState.eventSet, eventCode); if(retval!=PAPI_OK) { printf("Error in adding event: %s\n",*index); HandlePapiError(retval); return 1; } index+=1; papiState.numberOfEvents+=1; } Tcl_SetObjResult(interp, Tcl_NewStringObj("Hardware counters initialized", -1)); return TCL_OK; }
int main( int argc, char **argv ) { int retval; const PAPI_exe_info_t *prginfo = NULL; const PAPI_hw_info_t *hw_info; #if !defined(ITANIUM2) && !defined(ITANIUM3) test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 ); exit( 1 ); #endif tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ init_array( ); printf( "Malloc'd array pointers: %p %p %p\n", &parray1, &parray2, &parray3 ); printf( "Malloc'd array addresses: %p %p %p\n", parray1, parray2, parray3 ); printf( "Static array addresses: %p %p %p\n", &array1, &array2, &array3 ); 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 ); hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 ); #if defined(linux) && defined(__ia64__) sprintf( event_name[0], "loads_retired" ); sprintf( event_name[1], "stores_retired" ); PAPI_event_name_to_code( event_name[0], &PAPI_event[0] ); PAPI_event_name_to_code( event_name[1], &PAPI_event[1] ); #else test_fail( __FILE__, __LINE__, "only works for Itanium", PAPI_ESBSTR ); #endif if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_assign_eventset_component( EventSet, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); /***************************************************************************************/ printf ( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" ); printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 ); printf ( "These loads result from accessing the pointers to compute array addresses.\n" ); printf ( "They will likely disappear with higher levels of optimization.\n" ); measure_load_store( ( caddr_t ) & parray1, ( caddr_t ) ( &parray1 + 1 ) ); measure_load_store( ( caddr_t ) & parray2, ( caddr_t ) ( &parray2 + 1 ) ); measure_load_store( ( caddr_t ) & parray3, ( caddr_t ) ( &parray3 + 1 ) ); /***************************************************************************************/ printf ( "\n\nMeasure loads and stores on the allocated arrays themselves\n" ); printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM ); measure_load_store( ( caddr_t ) parray1, ( caddr_t ) ( parray1 + NUM ) ); measure_load_store( ( caddr_t ) parray2, ( caddr_t ) ( parray2 + NUM ) ); measure_load_store( ( caddr_t ) parray3, ( caddr_t ) ( parray3 + NUM ) ); /***************************************************************************************/ printf( "\n\nMeasure loads and stores on the static arrays\n" ); printf ( "These values will differ from the expected values by the size of the offsets.\n" ); printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM ); measure_load_store( ( caddr_t ) array1, ( caddr_t ) ( array1 + NUM ) ); measure_load_store( ( caddr_t ) array2, ( caddr_t ) ( array2 + NUM ) ); measure_load_store( ( caddr_t ) array3, ( caddr_t ) ( array3 + NUM ) ); /***************************************************************************************/ retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy", retval ); free( parray1 ); free( parray2 ); free( parray3 ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main( int argc, char **argv ) { int num_tests=1; int num_events=1; int retval; int cpu_num = 1; int EventSet1 = PAPI_NULL; long long **values; char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_CYC"; PAPI_option_t opts; // user can provide cpu number on which to count events as arg 1 if (argc > 1) { retval = atoi(argv[1]); if (retval >= 0) { cpu_num = retval; } } retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_create_eventset(&EventSet1); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); // Force event set to be associated with component 0 (perf_events component provides all core events) retval = PAPI_assign_eventset_component( EventSet1, 0 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); // Attach this event set to cpu 1 opts.cpu.eventset = EventSet1; opts.cpu.cpu_num = cpu_num; retval = PAPI_set_opt( PAPI_CPU_ATTACH, &opts ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval ); retval = PAPI_add_named_event(EventSet1, event_name); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_named_event", retval ); // get space for counter values (this needs to do this call because it malloc's space that test_pass and friends free) values = allocate_test_space( num_tests, num_events); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); // do some work do_flops(NUM_FLOPS); retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); printf ("Event: %s: %8lld on Cpu: %d\n", event_name, values[0][0], cpu_num); PAPI_shutdown( ); test_pass( __FILE__, values, 1 ); return PAPI_OK; }
int main(int argc, char **argv) { PAPI_event_info_t info; int i, j, retval; int iters = NUM_FLOPS; double x = 1.1, y, dtmp; long long t1, t2; long long values[MAXEVENTS]; int sleep_time = SLEEPTIME; #ifdef STARTSTOP long long dummies[MAXEVENTS]; #endif double valsample[MAXEVENTS][REPEATS]; double valsum[MAXEVENTS]; double avg[MAXEVENTS]; double spread[MAXEVENTS]; int nevents = MAXEVENTS; int eventset = PAPI_NULL; int events[MAXEVENTS]; int fails; events[0] = PAPI_FP_INS; events[1] = PAPI_TOT_INS; events[2] = PAPI_INT_INS; events[3] = PAPI_TOT_CYC; events[4] = PAPI_STL_CCY; events[5] = PAPI_BR_INS; events[6] = PAPI_SR_INS; events[7] = PAPI_LD_INS; events[8] = PAPI_TOT_IIS; for (i = 0; i < MAXEVENTS; i++) { values[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 multiplexing routines.\n"); printf("Investigating the variance of multiplexed measurements.\n\n"); } if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); #ifdef MPX init_multiplex(); #endif if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); #ifdef MPX /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(eventset, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); #endif nevents = MAXEVENTS; for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(eventset, events[i]))) { for (j = i; j < MAXEVENTS; j++) events[j] = events[j + 1]; nevents--; i--; } } if (nevents < 2) 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); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); for (i = 1; i <= REPEATS; i++) { x = 1.0; #ifndef STARTSTOP if ((retval = PAPI_reset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_reset", retval); #else if ((retval = PAPI_stop(eventset, dummies))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); #endif if (!TESTS_QUIET) printf("\nTest %d (of %d):\n", i, REPEATS); t1 = PAPI_get_real_usec(); y = dummy3(x, iters); PAPI_read(eventset, values); t2 = PAPI_get_real_usec(); if (!TESTS_QUIET) { printf("\n(calculated independent of PAPI)\n"); printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("PAPI measurements:\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"); } dtmp = (double) values[j]; valsum[j] += dtmp; valsample[j][i-1] = dtmp; } if (!TESTS_QUIET) printf("\n"); } if (!TESTS_QUIET) { printf("\n\nEstimated variance relative to average counts:\n"); for (j = 0; j < nevents; j++) printf(" Event %.2d", j); printf("\n"); } fails = nevents; /* Due to limited precision of floating point cannot really use typical standard deviation compuation for large numbers with very small variations. Instead compute the std devation problems with precision. */ for (j = 0; j < nevents; j++) { avg[j] = valsum[j] / REPEATS; spread[j] = 0; for (i=0; i < REPEATS; ++i) { double diff = (valsample[j][i] - avg[j]); spread[j] += diff * diff; } spread[j] = sqrt(spread[j] / REPEATS) / avg[j]; if (!TESTS_QUIET) printf("%9.2g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) --fails; else if (valsum[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ --fails; } if (!TESTS_QUIET) { printf("\n\n"); for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); printf("Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n", j, avg[j], spread[j], REPEATS, info.short_descr); } printf("\n\n"); } if (fails) test_fail(__FILE__, __LINE__, "Values outside threshold", fails); else test_pass(__FILE__, NULL, 0); return 0; }
void * thread( void *arg ) { ( void ) arg; /*unused */ int eventset = PAPI_NULL; long long values[PAPI_MPX_DEF_DEG]; int ret = PAPI_register_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret ); ret = PAPI_create_eventset( &eventset ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret ); printf( "Event set %d created\n", eventset ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ ret = PAPI_assign_eventset_component( eventset, 0 ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret ); } ret = PAPI_set_multiplex( eventset ); if ( ret == PAPI_ENOSUPP) { test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 ); } else if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret ); } ret = PAPI_add_events( eventset, events, numevents ); if ( ret < PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events", ret ); } ret = PAPI_start( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", ret ); } do_stuff( ); ret = PAPI_stop( eventset, values ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", ret ); } ret = PAPI_cleanup_eventset( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret ); } ret = PAPI_destroy_eventset( &eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret ); } ret = PAPI_unregister_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret ); return ( NULL ); }
static int refresh_metrics(int log) { int sts = 0; int state = 0; int i; int number_of_active_counters = 0; time_t now; now = time(NULL); /* Shut down, save previous state. */ state = check_papi_state(); if (state & PAPI_RUNNING) { sts = PAPI_stop(EventSet, values); if (sts != PAPI_OK) { /* futile to continue */ handle_papi_error(sts, log); return PM_ERR_VALUE; } /* Save previous values */ for (i = 0; i < number_of_events; i++){ if(papi_info[i].position >= 0) { papi_info[i].prev_value += values[papi_info[i].position]; papi_info[i].position = -1; } } /* Clean up eventset */ sts = PAPI_cleanup_eventset(EventSet); if (sts != PAPI_OK) { handle_papi_error(sts, log); /* FALLTHROUGH */ } sts = PAPI_destroy_eventset(&EventSet); /* sets EventSet=NULL */ if (sts != PAPI_OK) { handle_papi_error(sts, log); /* FALLTHROUGH */ } } /* Initialize new EventSet */ EventSet = PAPI_NULL; if ((sts = PAPI_create_eventset(&EventSet)) != PAPI_OK) { handle_papi_error(sts, log); return PM_ERR_GENERIC; } if ((sts = PAPI_assign_eventset_component(EventSet, 0 /*CPU*/)) != PAPI_OK) { handle_papi_error(sts, log); return PM_ERR_GENERIC; } if (enable_multiplexing && (sts = PAPI_set_multiplex(EventSet)) != PAPI_OK) { handle_papi_error(sts, log); /* not fatal - FALLTHROUGH */ } /* Add all survivor events to new EventSet */ number_of_active_counters = 0; for (i = 0; i < number_of_events; i++) { if (papi_info[i].metric_enabled == METRIC_ENABLED_FOREVER || papi_info[i].metric_enabled >= now) { sts = PAPI_add_event(EventSet, papi_info[i].info.event_code); if (sts != PAPI_OK) { if (pmDebug & DBG_TRACE_APPL0) { char eventname[PAPI_MAX_STR_LEN]; PAPI_event_code_to_name(papi_info[i].info.event_code, eventname); __pmNotifyErr(LOG_DEBUG, "Unable to add: %s due to error: %s\n", eventname, PAPI_strerror(sts)); } handle_papi_error(sts, log); /* * We may be called to make drastic changes to the PAPI * eventset. Partial successes/failures are quite reasonable, * as a user may be asking to activate a mix of good and bad * counters. Diagnosing the partial failure is left to the * caller, by examining the papi_info[i].position value * after this function returns. */ continue; } papi_info[i].position = number_of_active_counters++; } } /* Restart counting. */ if (number_of_active_counters > 0) { sts = PAPI_start(EventSet); if (sts != PAPI_OK) { handle_papi_error(sts, log); return PM_ERR_VALUE; } } return 0; }