void free_energy_data(pwr_ctx_t *ctx) { if (ctx == NULL) { return; } if (!pwr_is_initialized(ctx, PWR_MODULE_ENERGY)) { ctx->error = PWR_UNINITIALIZED; return; } if (ctx->emeas_running) { pwr_stop_energy_count(ctx); } PAPI_cleanup_eventset(ctx->event_set); PAPI_destroy_eventset(&ctx->event_set); PAPI_shutdown(); for (unsigned int i = 0; i < ctx->emeas->nbValues; ++i) { free(ctx->emeas->units[i]); free(ctx->emeas->names[i]); } free(ctx->emeas->values); free(ctx->emeas->units); free(ctx->emeas->names); free(ctx->emeas); ctx->error = PWR_OK; }
void GPTL_PAPIfinalize (int maxthreads) { int t; /* thread index */ int ret; /* return code */ for (t = 0; t < maxthreads; t++) { ret = PAPI_stop (EventSet[t], papicounters[t]); free (papicounters[t]); ret = PAPI_cleanup_eventset (EventSet[t]); ret = PAPI_destroy_eventset (&EventSet[t]); } free (EventSet); free (papicounters); /* Reset initial values */ npapievents = 0; nevents = 0; is_multiplexed = false; narrowprint = true; persec = true; enable_multiplexing = false; verbose = false; }
void vt_metric_free(struct vt_metv* metv) { int retval; long_long papi_vals[VT_METRIC_MAXNUM]; if ( metv == NULL ) return; /* treat PAPI failures at this point as non-fatal */ retval = PAPI_stop(metv->EventSet, papi_vals); if ( retval != PAPI_OK ) { vt_metric_warning(retval, "PAPI_stop"); } else { /* cleanup/destroy require successful PAPI_stop */ retval = PAPI_cleanup_eventset(metv->EventSet); if ( retval != PAPI_OK ) vt_metric_warning(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&metv->EventSet); if ( retval != PAPI_OK ) vt_metric_warning(retval, "PAPI_destroy_eventset"); free(metv); /*vt_cntl_msg("Counters stopped");*/ } }
/** Remove events that are not used any longer from the run * list of events to multiplex by the handler * MUST BE CALLED WITH THE SIGNAL HANDLER DISABLED */ static void mpx_remove_unused( MasterEvent ** head ) { MasterEvent *mev, *lastmev = NULL, *nextmev; Threadlist *thr = ( *head == NULL ) ? NULL : ( *head )->mythr; int retval; /* Clean up and remove unused master events. */ for ( mev = *head; mev != NULL; mev = nextmev ) { nextmev = mev->next; /* get link before mev is freed */ if ( !mev->uses ) { if ( lastmev == NULL ) { /* this was the head event */ *head = nextmev; } else { lastmev->next = nextmev; } retval=PAPI_cleanup_eventset( mev->papi_event ); retval=PAPI_destroy_eventset( &( mev->papi_event ) ); if (retval!=PAPI_OK) PAPIERROR("Error destroying event\n"); papi_free( mev ); } else { lastmev = mev; } } /* Always be sure the head master event points to the thread */ if ( *head != NULL ) { ( *head )->mythr = thr; } }
static void vt_metric_test(void) { int i; int retval; int EventSet = PAPI_NULL; /* create event set */ retval = PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK) vt_metric_error(retval, "PAPI_create_eventset"); for ( i = 0; i < nmetrics; i++ ) { /* add event to event set */ retval = PAPI_add_event(EventSet, metricv[i]->papi_code); if ( retval != PAPI_OK ) { char errstring[PAPI_MAX_STR_LEN]; sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name); vt_metric_error(retval, errstring); } vt_cntl_msg("Event %s added to event set", metricv[i]->name); } retval = PAPI_cleanup_eventset(EventSet); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&EventSet); if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_destroy_eventset"); vt_cntl_msg("Event set tested OK"); }
void esd_metric_free(struct esd_metv* metv) { int retval, i; long_long papi_vals[ELG_METRIC_MAXNUM]; if ( metv == NULL ) return; /* treat PAPI failures at this point as non-fatal */ /* KF: do everything for all components with counters */ for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { if( metv->NumEvents[i]==0 ) continue; retval = PAPI_stop(metv->EventSet[i], papi_vals); if ( retval != PAPI_OK ) { esd_metric_warning(retval, "PAPI_stop"); } else { /* cleanup/destroy require successful PAPI_stop */ retval = PAPI_cleanup_eventset(metv->EventSet[i]); if ( retval != PAPI_OK ) esd_metric_warning(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&metv->EventSet[i]); if ( retval != PAPI_OK ) esd_metric_warning(retval, "PAPI_destroy_eventset"); free(metv); elg_cntl_msg("Counters stopped"); } } }
void vt_metric_free(struct vt_metv* metv, uint32_t tid) { int retval, i; long_long papi_vals[VT_METRIC_MAXNUM]; if ( metv == NULL ) return; /* treat PAPI failures at this point as non-fatal */ VT_SUSPEND_IO_TRACING(tid); /* foreach used eventset */ for (i=0; i < VT_METRIC_MAXNUM && metv->EventSet[i]!=NULL; i++) { retval = PAPI_stop(metv->EventSet[i]->EventId, papi_vals); if ( retval != PAPI_OK ) { metric_warning(retval, "PAPI_stop"); } else { /* cleanup/destroy require successful PAPI_stop */ retval = PAPI_cleanup_eventset(metv->EventSet[i]->EventId); if ( retval != PAPI_OK ) metric_warning(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&metv->EventSet[i]->EventId); if ( retval != PAPI_OK ) metric_warning(retval, "PAPI_destroy_eventset"); } free(metv->EventSet[i]); } VT_RESUME_IO_TRACING(tid); free(metv); }
int check_papi_counter(char * counter_name) { PAPI_event_info_t * info; int EventSet = PAPI_NULL; unsigned int event_code = 0x0; int err; if ((err=PAPI_create_eventset (&EventSet)) != PAPI_OK){ fprintf(stderr,"Failed to create a PAPI eventset\n"); exit(1); } if((err = PAPI_event_name_to_code(counter_name,&event_code)) != PAPI_OK){ return err; } if((err = PAPI_add_event (EventSet, event_code)) != PAPI_OK) { return err; } PAPI_remove_named_event (EventSet, counter_name); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ){ printf("********** Call to destroy eventset failed when trying to validate event '%s' **********\n", counter_name); } return err; }
void PAPI_HW_COUNTER_close(int tid){ int retval; #ifdef MEASURE_TIME #endif #ifdef MEASURE_HW_COUNTER retval = PAPI_stop( thr_vars[tid].EventSet, thr_vars[tid].values); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } retval = PAPI_cleanup_eventset( thr_vars[tid].EventSet ); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &(thr_vars[tid].EventSet) ); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } #endif #ifdef MEASURE_ENERGY retval = PAPI_stop( thr_vars[tid].EnergyEventSet, thr_vars[tid].energy_values); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } retval = PAPI_cleanup_eventset( thr_vars[tid].EnergyEventSet ); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &(thr_vars[tid].EnergyEventSet) ); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } #endif }
/* Test whether requested event combination valid */ static void metric_test(void) { int i, j; int retval; int component; struct eventmap_t * EventSet[VT_METRIC_MAXNUM]; for (i=0; i<VT_METRIC_MAXNUM; i++) EventSet[i] = NULL; for (i=0; i < nmetrics; i++) { #ifdef PAPIC /* Preset-counter belong to Component 0! */ component = PAPI_COMPONENT_INDEX(metricv[i]->papi_code); #else component = 0; #endif /* search for the eventset that matches the counter */ j=0; while (EventSet[j]!=NULL && j < VT_METRIC_MAXNUM && EventSet[j]->ComponentId!=component){ j++; } if (EventSet[j]==NULL) /* create eventset, if no matching found */ { EventSet[j] = malloc(sizeof(eventmap_t)); EventSet[j]->EventId=PAPI_NULL; retval = PAPI_create_eventset(&(EventSet[j]->EventId)); if ( retval != PAPI_OK) metric_error(retval, "PAPI_create_eventset"); EventSet[j]->ComponentId=component; } /* add event to event set */ retval = PAPI_add_event(EventSet[j]->EventId, metricv[i]->papi_code); if ( retval != PAPI_OK ) { char errstring[PAPI_MAX_STR_LEN]; sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name); metric_error(retval, errstring); } vt_cntl_msg(2, "Event %s added to event set", metricv[i]->name); } /* foreach used eventset */ for (i=0; i < VT_METRIC_MAXNUM && EventSet[i]!=NULL; i++) { retval = PAPI_cleanup_eventset(EventSet[i]->EventId); if ( retval != PAPI_OK ) metric_error(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&(EventSet[i]->EventId)); if ( retval != PAPI_OK ) metric_error(retval, "PAPI_destroy_eventset"); free(EventSet[i]); } vt_cntl_msg(2, "Event set tested OK"); }
static int check_event( int event_code, char *name ) { int retval; char errstring[PAPI_MAX_STR_LEN]; long long values; int EventSet = PAPI_NULL; /* Is there an issue with older machines? */ /* Disable for now, add back once we can reproduce */ // if ( PENTIUM4 ) { // if ( strcmp( name, "REPLAY_EVENT:BR_MSP" ) == 0 ) { // return 1; // } // } retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_add_event( EventSet, event_code ); if ( retval != PAPI_OK ) { printf( "Error adding %s\n", name ); return 0; } else { // printf( "Added %s successfully ", name ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error starting %s : %s\n", name, errstring ); } else { retval = PAPI_stop( EventSet, &values ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error stopping %s: %s\n", name, errstring ); return 0; } else { printf( "Added and Stopped %s successfully.\n", name ); } } retval=PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } retval=PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_destroy_eventset", retval); } return ( 1 ); }
void destroy() { int ret; ret = PAPI_cleanup_eventset(eventSet); CHECK_PAPI_ERROR(ret, "PAPI_cleanup_eventset"); ret = PAPI_destroy_eventset(&eventSet); CHECK_PAPI_ERROR(ret, "PAPI_destroy_eventset"); PAPI_shutdown(); }
void * my_thread( void *v ) { long num = ( long ) v; int n; int EventSet = PAPI_NULL; long long value; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); pthread_setspecific( key, v ); count[num] = 0; iter[num] = 0; last[num] = start; if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 ); if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 ); if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 ); if ( PAPI_start( EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 ); printf( "launched timer in thread %ld\n", num ); for ( n = 1; n <= program_time; n++ ) { do_cycles( num, 1 ); print_rate( num ); } PAPI_stop( EventSet, &value ); retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval ); if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 ); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 ); if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 ); return ( NULL ); }
void perf_destroy(perf_t *perf) { int retval; retval = PAPI_cleanup_eventset(perf->EventSet); assert(retval == PAPI_OK); retval = PAPI_destroy_eventset(&perf->EventSet); assert(retval == PAPI_OK); free(perf); }
void end_record_cache_access(RRecord & rr) { int retVal; retVal = PAPI_stop(g_event_set, endRecords); assert(retVal == PAPI_OK); retVal = PAPI_cleanup_eventset(g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_destroy_eventset(&g_event_set); assert(retVal == PAPI_OK); PAPI_shutdown(); rr.put("L1-cache-misss", endRecords[0] - startRecords[0]); rr.put("L1-cache-access", endRecords[1] - startRecords[1]); }
void test_papi_destroy(struct test_statistics_t *test_stat) { int retval; if ((retval = PAPI_stop(test_stat->event_set, test_stat->counters)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); if ((retval = PAPI_cleanup_eventset(test_stat->event_set)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if ((retval = PAPI_destroy_eventset(&(test_stat->event_set))) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); }
/* 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"); }
static void papiEnd() { int rv; /* get the values */ if ((rv = PAPI_stop(papiEventSet, papiResults)) != PAPI_OK) handle_error(rv); /* Remove all events in the eventset */ if ((rv = PAPI_cleanup_eventset(papiEventSet)) != PAPI_OK) handle_error(rv); /* Free all memory and data structures, EventSet must be empty. */ if ((rv = PAPI_destroy_eventset(&papiEventSet)) != PAPI_OK) handle_error(rv); }
long_long stop_PAPI(int ind) { long_long values[1]; if (PAPI_stop(oscrData_timerPAPIEventSet[ind], values) != PAPI_OK) OSCR_error("PAPI stop init error!\n", -1); if (PAPI_cleanup_eventset(&oscrData_timerPAPIEventSet[ind]) != PAPI_OK) OSCR_error("PAPI cleanning Eventset error!\n", -1); if (PAPI_destroy_eventset(&oscrData_timerPAPIEventSet[ind]) != PAPI_OK) OSCR_error("PAPI destroying Eventset error!\n", -1); return (values[0]); }
JNIEXPORT jint JNICALL Java_papi_Wrapper_eventSetDestroy (JNIEnv UNUSED_ARG(*env), jclass UNUSED_ARG(self), jlong eventsetid) { int eventset = (int) eventsetid; DEBUG_PRINT("cleanig-up the event set %d first", eventset); int rc = PAPI_cleanup_eventset(eventset); if (rc != PAPI_OK) { goto leave; } DEBUG_PRINT("destroying %d", eventset); rc = PAPI_destroy_eventset(&eventset); leave: DEBUG_PRINT("returning %d (%s)", rc, PAPI_strerror(rc)); return rc; }
void HWCBE_PAPI_CleanUp (unsigned nthreads) { UNREFERENCED_PARAMETER(nthreads); if (PAPI_is_initialized()) { int state; int i; unsigned t; if (PAPI_state (HWCEVTSET(THREADID), &state) == PAPI_OK) { if (state & PAPI_RUNNING) { long long tmp[MAX_HWC]; PAPI_stop (HWCEVTSET(THREADID), tmp); } } for (i = 0; i < HWC_num_sets; i++) { for (t = 0; t < nthreads; t++) { /* Remove all events in the eventset and destroy the eventset */ PAPI_cleanup_eventset(HWC_sets[i].eventsets[t]); PAPI_destroy_eventset(&HWC_sets[i].eventsets[t]); } xfree (HWC_sets[i].eventsets); } #if defined(PAPI_SAMPLING_SUPPORT) for (i = 0; i < HWC_num_sets; i++) { /* Free extra allocated memory */ if (HWC_sets[i].NumOverflows > 0) { xfree (HWC_sets[i].OverflowValue); xfree (HWC_sets[i].OverflowCounter); } } #endif xfree (HWC_sets); PAPI_shutdown(); } }
void ref_measurements(int iters, int *eventset, int *events, int nevents, long long *refvalues) { PAPI_event_info_t info; int i, retval; double x = 1.1, y; long long t1, t2; printf("PAPI reference measurements:\n"); if ((retval = PAPI_create_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(*eventset, events[i]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); x = 1.0; t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(*eventset, &refvalues[i]))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); #if 0 printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); #endif PAPI_get_event_info(events[i], &info); printf("%20s = ", info.short_descr); printf(LLDFMT, refvalues[i]); printf("\n"); if ((retval = PAPI_cleanup_eventset(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } if ((retval = PAPI_destroy_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); *eventset = PAPI_NULL; }
void polybench_papi_close() { # ifdef _OPENMP #pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if (PAPI_is_initialized ()) PAPI_shutdown (); # ifdef _OPENMP } } #pragma omp barrier # endif }
void esd_metric_test() { int i, j, comp; int retval; int EventSet[ELG_PAPIC_MAX_COMP]; /* KF */ for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { EventSet[i] = PAPI_NULL; /* create event set */ retval = PAPI_create_eventset(&(EventSet[i])); if ( retval != PAPI_OK) esd_metric_error(retval, "PAPI_create_eventset"); } for ( j = 0; j < nmetrics; j++ ) { /* add event to event set */ /*fprintf(stderr,"Checking Metric %s, Component indes: %d,\n\n",metricv[j]->name,PAPI_COMPONENT_INDEX( metricv[j]->papi_code ));*/ comp = PAPI_COMPONENT_INDEX( metricv[j]->papi_code ); retval = PAPI_add_event(EventSet[comp], metricv[j]->papi_code); if ( retval != PAPI_OK ) { char errstring[PAPI_MAX_STR_LEN]; sprintf(errstring, "PAPI_add_event(%d:\"%s\")", j, metricv[j]->name); esd_metric_error(retval, errstring); } elg_cntl_msg("Event %s added to event set", metricv[j]->name); } for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { retval = PAPI_cleanup_eventset(EventSet[i]); if ( retval != PAPI_OK ) esd_metric_error(retval, "PAPI_cleanup_eventset"); retval = PAPI_destroy_eventset(&(EventSet[i])); if ( retval != PAPI_OK ) esd_metric_error(retval, "PAPI_destroy_eventset"); } elg_cntl_msg("Event set tested OK"); }
int CheckBitmapCounters (int ncounters, unsigned *counters, int *bitmask) { int valid_bitmap = TRUE; int EventSet = PAPI_NULL; int i; if (PAPI_create_eventset(&EventSet) != PAPI_OK) { fprintf (stderr, "Error! Failed to create the eventset!\n"); return FALSE; } for (i = 0; i < ncounters; i++) if (bitmask[i]) valid_bitmap = valid_bitmap && (PAPI_add_event (EventSet, counters[i]) == PAPI_OK); 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"); return valid_bitmap; }
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 ); }
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,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; }
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]; }