void handler( int EventSet, void *address, long long overflow_vector, void *context ) { ( void ) context; ( void ) address; ( void ) overflow_vector; #if 0 fprintf( stderr, "handler(%d ) Overflow at %p! bit=0x%llx \n", EventSet, address, overflow_vector ); #endif PAPI_read(EventSet,values); if (!quiet) printf("%lld %lld\t",values[0],values[1]); PAPI_read(EventSet2,rapl_values); if (!quiet) printf("RAPL: %lld %lld\n",rapl_values[0],rapl_values[1]); if ((rapl_values[0]<old_rapl_values[0]) || (rapl_values[1]<old_rapl_values[1])) { if (!quiet) printf("RAPL decreased!\n"); rapl_backward=1; } old_rapl_values[0]=rapl_values[0]; old_rapl_values[1]=rapl_values[1]; total++; }
int HWCBE_PAPI_Read (unsigned int tid, long long *store_buffer) { int EventSet = HWCEVTSET(tid); #if !defined(IS_BG_MACHINE) if (PAPI_read(EventSet, store_buffer) != PAPI_OK) { fprintf (stderr, PACKAGE_NAME": PAPI_read failed for thread %d evtset %d (%s:%d)\n", tid, EventSet, __FILE__, __LINE__); return 0; } return 1; #else if (!__in_PAPI_read_BG) { __in_PAPI_read_BG = TRUE; if (PAPI_read(EventSet, store_buffer) != PAPI_OK) { fprintf (stderr, PACKAGE_NAME": PAPI_read failed for thread %d evtset %d (%s:%d)\n", tid, EventSet, __FILE__, __LINE__); return 0; } __in_PAPI_read_BG = FALSE; return 1; } else return 0; #endif }
void PAPI_HW_COUNTER_off(int tid, int aid) { int retval; #ifdef MEASURE_TIME thr_vars[tid]._tmp_time[aid].end=PAPI_get_real_cyc(); #endif #ifdef MEASURE_HW_COUNTER retval=PAPI_read(thr_vars[tid].EventSet, thr_vars[tid].values); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_read()", retval); } #endif #ifdef MEASURE_CPI thr_vars[tid]._tmp_inst[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_inst]; thr_vars[tid]._tmp_cyc[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_cyc]; #endif #ifdef MEASURE_MEMACC thr_vars[tid]._tmp_load[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_load]; thr_vars[tid]._tmp_store[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_store]; #endif #ifdef MEASURE_LLCMISS thr_vars[tid]._tmp_llcmiss[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_llcmiss]; #endif #ifdef MEASURE_ICACHEMISS thr_vars[tid]._tmp_icachemiss[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_icachemiss]; #endif #ifdef MEASURE_DCACHEMISS thr_vars[tid]._tmp_l1dcm[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_l1dcm]; thr_vars[tid]._tmp_l1dca[aid].end=thr_vars[tid].values[thr_vars[tid].papi_idx_l1dca]; #endif #ifdef MEASURE_ENERGY retval=PAPI_read(thr_vars[tid].EnergyEventSet, thr_vars[tid].energy_values); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "PAPI_read()", retval); } int i; for(i=0;i<thr_vars[tid].num_energy_events;i++){ thr_vars[tid]._tmp_energies[i][aid].end=thr_vars[tid].energy_values[i]; } #endif }
int GPTL_PAPIstop (const int t, /* thread number */ Papistats *aux) /* struct containing PAPI stats */ { int ret; /* return code from PAPI lib calls */ int n; /* loop index */ long_long delta; /* change in counters from previous read */ /* If no events are to be counted just return */ if (npapievents == 0) return 0; /* Read the counters */ if ((ret = PAPI_read (EventSet[t], papicounters[t])) != PAPI_OK) return GPTLerror ("GPTL_PAPIstop: %s\n", PAPI_strerror (ret)); /* ** Accumulate the difference since timer start in aux. ** Negative accumulation can happen when multiplexing is enabled, so don't ** set count to BADCOUNT in that case. */ for (n = 0; n < npapievents; n++) { #ifdef DEBUG printf ("GPTL_PAPIstop: event %d counter value is %ld\n", n, (long) papicounters[t][n]); #endif delta = papicounters[t][n] - aux->last[n]; if ( ! is_multiplexed && delta < 0) aux->accum[n] = BADCOUNT; else aux->accum[n] += delta; } return 0; }
void *PapiKernel (void *Args) { struct periodic_info info; long long i=0; long long tempvalues[3]; tempvalues[0]=0; tempvalues[1]=0; tempvalues[2]=0; // 10ms interval make_periodic (10000, &info); while (1) { i+=10; /* Do useful work */ PAPI_read(eventset, values); fprintf(gnuplotfile,"%lld\t%lld\t%lld\n", i, values[1]-tempvalues[1], values[2]-tempvalues[2]); tempvalues[1]=values[1]; tempvalues[2]=values[2]; wait_period (&info); } return NULL; }
void polybench_papi_stop_counter(int evid) { # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; long_long values[1]; values[0] = 0; if ((retval = PAPI_read (polybench_papi_eventset, &values[0])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_read", retval); if ((retval = PAPI_stop (polybench_papi_eventset, NULL)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_stop", retval); polybench_papi_values[evid] = values[0]; if ((retval = PAPI_remove_event (polybench_papi_eventset, polybench_papi_eventlist[evid])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_remove_event", retval); # ifdef _OPENMP } } #pragma omp barrier # endif }
void Timing::stop(std::string const &name){ // get or create timer Timer &timer = timers[name]; #ifdef KRIPKE_USE_BGPM HPM_Stop(name.c_str()); #endif #ifdef RAJA_USE_CALIPER cali::Annotation(name.c_str()).end(); #endif if(timer.started){ #ifdef KRIPKE_USE_PAPI int num_papi = papi_event.size(); if(num_papi > 0){ // read timers long long tmp[16]; //PAPI_stop_counters(tmp, num_papi); PAPI_read(papi_set, tmp); // accumulate to all started timers (since this clears the PAPI values) for(int i = 0;i < num_papi;++ i){ timer.papi_total[i] += tmp[i] - timer.papi_start_values[i]; } } #endif // Stop the timer timer.started = false; timer.total_time += getTime() - timer.start_time; timer.count ++; } }
void MeasureTimePAPI::getTimeValuesStartP(MeasureTimeValues *res) const { #ifdef USE_PAPI MeasureTimeValuesPAPI *val = static_cast<MeasureTimeValuesPAPI*>(res); // if (PAPI_reset(eventSet) != PAPI_OK) // { // std::cerr << "PAPI_reset - FAILED" << std::endl; // throw ModelicaSimulationError(UTILITY,"PAPI_reset_counters - FAILED"); // } long long values[NUM_PAPI_EVENTS]; if (PAPI_read(_eventSet, values) != PAPI_OK) { std::cerr << "PAPI_read_counters - FAILED" << std::endl; throw ModelicaSimulationError(UTILITY,"PAPI_read_counters - FAILED"); } // val->time = 0; // val->l2CacheMisses = 0; // val->instructions = 0; val->_time = values[0]; val->_l2CacheMisses = values[1]; val->_instructions = values[2]; #endif }
void esd_metric_read(struct esd_metv* metv, elg_ui8 values[]) { int retval; int i, j, k; long_long papi_vals[ELG_METRIC_MAXNUM]; if ( metv == NULL ) return; /* KF: since contiguous counters in a component could be non-contiguous in the metric specification we always have to read in a temp. array and redistribute counter values accordingly */ for( i=0; i<ELG_PAPIC_MAX_COMP; i++ ) { if( (metv->NumEvents[i])==0 ) continue; retval = PAPI_read(metv->EventSet[i], papi_vals); if ( retval != PAPI_OK ) esd_metric_error(retval, "PAPI_read"); for( j=0; j<metv->NumEvents[i]; j++ ) { k = metv->Comp2Metr[i][j]; values[k] = (elg_ui8) papi_vals[j]; } } }
PetscErrorCode PetscLogEventBeginDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) { StageLog stageLog; EventPerfLog eventLog; int stage; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); ierr = StageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); ierr = StageLogGetEventPerfLog(stageLog, stage, &eventLog);CHKERRQ(ierr); /* Check for double counting */ eventLog->eventInfo[event].depth++; if (eventLog->eventInfo[event].depth > 1) PetscFunctionReturn(0); /* Log performance info */ eventLog->eventInfo[event].count++; PetscTimeSubtract(eventLog->eventInfo[event].time); #if defined(PETSC_HAVE_CHUD) eventLog->eventInfo[event].flops -= chudGetPMCEventCount(chudCPU1Dev,PMC_1); #elif defined(PETSC_HAVE_PAPI) { long_long values[2]; ierr = PAPI_read(PAPIEventSet,values);CHKERRQ(ierr); eventLog->eventInfo[event].flops -= values[0]; /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */ } #else eventLog->eventInfo[event].flops -= _TotalFlops; #endif eventLog->eventInfo[event].numMessages -= irecv_ct + isend_ct + recv_ct + send_ct; eventLog->eventInfo[event].messageLength -= irecv_len + isend_len + recv_len + send_len; eventLog->eventInfo[event].numReductions -= allreduce_ct; PetscFunctionReturn(0); }
void vt_metric_read(struct vt_metv* metv, uint64_t offsets[], uint64_t values[]) { int retval; int i; if ( metv == NULL ) return; VT_SUSPEND_IO_TRACING(VT_CURRENT_THREAD); /* foreach used eventset */ for (i=0; i < VT_METRIC_MAXNUM && metv->EventSet[i]!=NULL; i++) { retval = PAPI_read(metv->EventSet[i]->EventId, metv->EventSet[i]->Values ); if ( retval != PAPI_OK ) metric_error(retval, "PAPI_read"); } if ( offsets != NULL ) for ( i = 0; i < nmetrics; i++ ) values[i] = (uint64_t) *metv->Values[i] + offsets[i]; else for ( i = 0; i < nmetrics; i++ ) values[i] = (uint64_t) *metv->Values[i]; VT_RESUME_IO_TRACING(VT_CURRENT_THREAD); }
int GPTL_PAPIstart (const int t, /* thread number */ Papistats *aux) /* struct containing PAPI stats */ { int ret; /* return code from PAPI lib calls */ int n; /* loop index */ /* If no events are to be counted just return */ if (npapievents == 0) return 0; /* Read the counters */ if ((ret = PAPI_read (EventSet[t], papicounters[t])) != PAPI_OK) return GPTLerror ("GPTL_PAPIstart: %s\n", PAPI_strerror (ret)); /* ** Store the counter values. When GPTL_PAPIstop is called, the counters ** will again be read, and differenced with the values saved here. */ for (n = 0; n < npapievents; n++) aux->last[n] = papicounters[t][n]; return 0; }
perf_counter_t perf_read(perf_t *perf) { perf_counter_t counter; counter.tick = PAPI_get_real_usec(); int retval = PAPI_read(perf->EventSet, (counter_t*)&counter.value); assert(retval == PAPI_OK); return counter; }
void ipm_pthread_hpm_read(int tid, long long int *count) { #ifdef HPM_PAPI int i; PAPI_read(papi_eventset[tid], count); #endif return; }
void read_counters100 () { int i; int ret; long_long counters[MAX_AUX]; for (i = 0; i < 10; ++i) { ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); ret = PAPI_read (EventSet[0], counters); } return; }
/* ** The following functions are publicly available */ void read_counters1000 () { int i; int ret; long_long counters[MAX_AUX]; #pragma unroll(10) for (i = 0; i < 1000; ++i) { ret = PAPI_read (EventSet[0], counters); } return; }
void handler (int EventSet, void *address, long long overflow_vector, void *context) { int ret; int i; long long vals[8] = {0, 0, 0, 0, 0, 0, 0, 0}; printf ("\nOverflow at %p! bit=0x%llx \n", address,overflow_vector); ret = PAPI_read (EventSet, vals); printf ("Overflow read vals :"); for (i = 0; i < 3 /* 8 */; i++) printf ("%lld ", vals[i]); printf ("\n\n"); ovrflow = vals[0]; }
void vt_metric_read(struct vt_metv* metv, uint64_t values[]) { int retval; if ( metv == NULL ) return; if (sizeof(long_long) == 8) { retval = PAPI_read(metv->EventSet, (long_long*) values); } else { int i; long_long papi_vals[VT_METRIC_MAXNUM]; retval = PAPI_read(metv->EventSet, papi_vals); for (i = 0; i < nmetrics; i++) values[i] = (uint64_t) papi_vals[i]; } if ( retval != PAPI_OK ) vt_metric_error(retval, "PAPI_read"); }
void start_record_cache_access() { int retVal = PAPI_library_init(PAPI_VER_CURRENT); assert(retVal == PAPI_VER_CURRENT); EventSet = PAPI_NULL; retVal = PAPI_create_eventset(&g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_add_event(g_event_set, PAPI_L1_TCM); assert(retVal == PAPI_OK); retVal = PAPI_start(g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_read(g_event_set, startRecords); assert(retVal == PAPI_OK); }
int PAPI_accum_var (int EventSet, long_long values[2][NEVENTS]) { long_long dummy_values[NEVENTS]; long_long a; int i; PAPI_read (EventSet, dummy_values); for (i = 0; i < NEVENTS; i++) { a = dummy_values[i]; values[0][i] += a; values[1][i] += a * a; } return (PAPI_reset(EventSet)); }
int PAPI_accum_min (int EventSet, long_long *values) { long_long dummy_values[NEVENTS]; long_long a; long_long b; int i; PAPI_read (EventSet, dummy_values); for (i = 0; i < NEVENTS; i++) { a = dummy_values[i]; b = values[i]; if (a < b) values[i] = a; } return (PAPI_reset(EventSet)); }
PetscErrorCode PetscLogEventEndDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) { PetscStageLog stageLog; PetscEventPerfLog eventLog = NULL; int stage; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscLogGetStageLog(&stageLog); CHKERRQ(ierr); ierr = PetscStageLogGetCurrent(stageLog, &stage); CHKERRQ(ierr); ierr = PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog); CHKERRQ(ierr); /* Check for double counting */ eventLog->eventInfo[event].depth--; if (eventLog->eventInfo[event].depth > 0) PetscFunctionReturn(0); else if (eventLog->eventInfo[event].depth < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Logging event had unbalanced begin/end pairs"); /* Log performance info */ PetscTimeAdd(&eventLog->eventInfo[event].timeTmp); eventLog->eventInfo[event].time += eventLog->eventInfo[event].timeTmp; eventLog->eventInfo[event].time2 += eventLog->eventInfo[event].timeTmp*eventLog->eventInfo[event].timeTmp; #if defined(PETSC_HAVE_PAPI) { long_long values[2]; ierr = PAPI_read(PAPIEventSet,values); CHKERRQ(ierr); eventLog->eventInfo[event].flopsTmp += values[0]; /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */ } #else eventLog->eventInfo[event].flopsTmp += petsc_TotalFlops; #endif eventLog->eventInfo[event].flops += eventLog->eventInfo[event].flopsTmp; eventLog->eventInfo[event].flops2 += eventLog->eventInfo[event].flopsTmp*eventLog->eventInfo[event].flopsTmp; eventLog->eventInfo[event].numMessages += petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct; eventLog->eventInfo[event].messageLength += petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len; eventLog->eventInfo[event].numReductions += petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct; PetscFunctionReturn(0); }
void Timing::start(std::string const &name){ // get or create timer Timer &timer = timers[name]; if(!timer.started){ timer.started = true; timer.start_time = getTime(); #ifdef KRIPKE_USE_PAPI int num_papi = papi_event.size(); if(num_papi > 0){ if(timer.papi_total.size() == 0){ timer.papi_start_values.resize(num_papi, 0); timer.papi_total.resize(num_papi, 0); } /* // start timers PAPI_start_counters(&papi_event[0], num_papi); // clear timers long long tmp[16]; PAPI_read_counters(tmp, num_papi); */ // read initial values PAPI_read(papi_set, &timer.papi_start_values[0]); } #endif #ifdef RAJA_USE_CALIPER cali::Annotation(name.c_str()).begin(); #endif #ifdef KRIPKE_USE_BGPM HPM_Start(name.c_str()); #endif } }
int _internal_hl_read_cnts(long long * values, int array_len, int flag) { int retval; HighLevelInfo *state = NULL; if ((retval = _internal_check_state(&state)) != PAPI_OK) return (retval); if (state->running != HL_START_COUNTERS || array_len < state->num_evts) return (PAPI_EINVAL); if (flag == PAPI_HL_ACCUM) return (PAPI_accum(state->EventSet, values)); else if (flag == PAPI_HL_READ) { if ((retval = PAPI_read(state->EventSet, values)) != PAPI_OK) return (retval); return (PAPI_reset(state->EventSet)); } /* Invalid flag passed in */ return (PAPI_EINVAL); }
PetscErrorCode PetscLogEventBeginDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) { PetscStageLog stageLog; PetscEventPerfLog eventLog = NULL; int stage; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscLogGetStageLog(&stageLog); CHKERRQ(ierr); ierr = PetscStageLogGetCurrent(stageLog, &stage); CHKERRQ(ierr); ierr = PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog); CHKERRQ(ierr); /* Check for double counting */ eventLog->eventInfo[event].depth++; if (eventLog->eventInfo[event].depth > 1) PetscFunctionReturn(0); /* Log performance info */ eventLog->eventInfo[event].count++; eventLog->eventInfo[event].timeTmp = 0.0; PetscTimeSubtract(&eventLog->eventInfo[event].timeTmp); eventLog->eventInfo[event].flopsTmp = 0.0; #if defined(PETSC_HAVE_PAPI) { long_long values[2]; ierr = PAPI_read(PAPIEventSet,values); CHKERRQ(ierr); eventLog->eventInfo[event].flopsTmp -= values[0]; /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */ } #else eventLog->eventInfo[event].flopsTmp -= petsc_TotalFlops; #endif eventLog->eventInfo[event].numMessages -= petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct; eventLog->eventInfo[event].messageLength -= petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len; eventLog->eventInfo[event].numReductions -= petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct; PetscFunctionReturn(0); }
void ipm_hpm_read(long long int *count) { /* read the counters */ /* assumes hpm is IPM_HPM_ACTIVE */ int i; #ifndef HPM_DISABLED #ifdef HPM_PAPI #ifdef CPU_PPC450D /* then we are on a bluegene P*/ if (node_rank != 0 ) return; #endif PAPI_read(papi_eventset[0], count); #endif #ifdef HPM_PMAPI pm_get_data_mythread(&pmapi_data); for(i=0;i<MAXSIZE_HPMCOUNTERS;i++) { count[i] = pmapi_data.accu[i]; } #endif #endif return; }
PetscErrorCode PetscLogEventEndDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) { StageLog stageLog; EventPerfLog eventLog; int stage; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); ierr = StageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); ierr = StageLogGetEventPerfLog(stageLog, stage, &eventLog);CHKERRQ(ierr); /* Check for double counting */ eventLog->eventInfo[event].depth--; if (eventLog->eventInfo[event].depth > 0) { PetscFunctionReturn(0); } else if (eventLog->eventInfo[event].depth < 0) { SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Logging event had unbalanced begin/end pairs"); } /* Log performance info */ PetscTimeAdd(eventLog->eventInfo[event].time); #if defined(PETSC_HAVE_CHUD) eventLog->eventInfo[event].flops += chudGetPMCEventCount(chudCPU1Dev,PMC_1); #elif defined(PETSC_HAVE_PAPI) { long_long values[2]; ierr = PAPI_read(PAPIEventSet,values);CHKERRQ(ierr); eventLog->eventInfo[event].flops += values[0]; /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */ } #else eventLog->eventInfo[event].flops += _TotalFlops; #endif eventLog->eventInfo[event].numMessages += irecv_ct + isend_ct + recv_ct + send_ct; eventLog->eventInfo[event].messageLength += irecv_len + isend_len + recv_len + send_len; eventLog->eventInfo[event].numReductions += allreduce_ct; PetscFunctionReturn(0); }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long values[MAX_EVENTS]; int i,code,enum_retval; const PAPI_component_info_t *cmpinfo = NULL; long long start_time,write_start_time,write_end_time,read_start_time,read_end_time; char event_name[BUFSIZ]; union { long long ll; double dbl; } event_value_union; static int num_events=0; FILE *fileout; /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { fprintf(stderr,"PAPI_library_init failed\n"); exit(1); } /* Find the libmsr component */ numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { fprintf(stderr,"PAPI_get_component_info failed\n"); exit(1); } if (strstr(cmpinfo->name,"libmsr")) { rapl_cid=cid; printf("Found libmsr component at cid %d\n", rapl_cid); if (cmpinfo->disabled) { fprintf(stderr,"No libmsr events found: %s\n", cmpinfo->disabled_reason); exit(1); } break; } } /* Component not found */ if (cid==numcmp) { fprintf(stderr,"No libmsr component found\n"); exit(1); } /* Find events in the component */ code = PAPI_NATIVE_MASK; enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( enum_retval == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); exit(1); } printf("Found: %s\n",event_name); strncpy(events[num_events],event_name,BUFSIZ); sprintf(filenames[num_events],"results.%s",event_name); num_events++; if (num_events==MAX_EVENTS) { printf("Too many events! %d\n",num_events); exit(1); } enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } if (num_events==0) { printf("Error! No libmsr events found!\n"); exit(1); } /* Open output file */ char fileoutname[]="libmsr_write_test_output.txt"; fileout=fopen( fileoutname ,"w" ); if ( fileout==NULL) { fprintf( stderr,"Could not open %s\n",fileoutname ); exit(1); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { fprintf(stderr,"Error creating eventset!\n"); } for(i=0;i<num_events;i++) { retval = PAPI_add_named_event( EventSet, events[i] ); if (retval != PAPI_OK) fprintf(stderr,"Error adding event %s\n",events[i]); } start_time=PAPI_get_real_nsec(); /* Grab the initial values for the events */ retval = PAPI_start( EventSet); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_start() failed\n"); exit(1); } /* Initial checking read */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } /* Write a header line */ fprintf( fileout, "ACTION TIME-STAMP TIME-FOR-UNIT-WORK TIME-OVERHEAD-RW\t" ); for(i=0; i<num_events; i++) fprintf( fileout, "%s ", events[i]+9 ); fprintf( fileout, "\n" ); /* Read the initial values */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "INIT %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", 0.0); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); int rpt=0; int limit1base=10; int limit2base=10; while(rpt++<200) { //printf("rpt %d\n", rpt); if ( rpt % 10 == 0 ) { for (i=0; i<num_events; i++) { event_value_union.ll = values[i]; if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=1.0; else event_value_union.dbl=PAPI_NULL; values[i]=event_value_union.ll; } write_start_time=PAPI_get_real_nsec(); retval = PAPI_write( EventSet, values ); write_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_write() failed\n"); exit(1); } fprintf( fileout, "SET %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", ((double)(write_end_time-write_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } /* DO SOME WORK TO USE ENERGY */ //usleep(100000); double work_start_time=PAPI_get_real_nsec(); ompcpuloadprimes( 100000 ); double work_time=PAPI_get_real_nsec()-work_start_time; //printf("primescount %d\n", primescount); /* Read and output the values */ read_start_time=PAPI_get_real_nsec(); retval = PAPI_read( EventSet, values ); read_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "READ %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, work_time/1.0e9 ); fprintf( fileout, "%8.3e ", ((double)(read_end_time-read_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } retval = PAPI_stop( EventSet, values); return 0; }
int main (int argc, char ** argv) { int ret, status, i = 0; pid_t rt_child; timer_t tid; struct sigaction sa; struct sigevent sigev; struct itimerspec new_tmr; struct sched_param s_param; cpu_set_t mask; scheduler_check_arguments(argc, argv); //--------------------------------PAPI initilization------------------------------// init_papi(); scheduler_init_papi(); set_option(); scheduler_set_option(); add_events(); scheduler_add_event(); //---------------------------Timer initialization and sigaction----------------------// sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = timer_handler; sigemptyset(&sa.sa_mask); if(sigaction(SIGRTMIN, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } if(sigaction(SIGCONT, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGRTMIN; sigev.sigev_value.sival_ptr = &tid; if(timer_create(CLOCK_REALTIME, &sigev, &tid) != -1){ new_tmr.it_value.tv_sec = 0; new_tmr.it_value.tv_nsec = 25000000; new_tmr.it_interval.tv_sec = 0; new_tmr.it_interval.tv_nsec = 25000000; } /**********************************************************************************************/ //Launch the attackers printf("Launching %d attackers\n", atoi(argv[2])); for(i=0; i < atoi(argv[2]); i++){ if((pid_attacker[nb_attackers++] = fork()) == 0){ CPU_ZERO(&mask); CPU_SET(i+2, &mask); printf("Core %d\n", i+2); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } char c[2]; sprintf(c, "%d", i+2); if(execl("/usr/bin/xterm", "xterm", "-hold", "-e", "./bin/attack_task", "1", c, NULL) == -1){ exit(17); } exit(0); } } sleep(10); /**********************************************************************************************/ /**********************************************************************************************/ //Child executes the RT task in one core if((rt_child = fork())==0){ int stdin_fd = -1; //Setting the affinity of the child //Using only one CPU with max priority CPU_ZERO(&mask); CPU_SET(1, &mask); stdin_fd = open("/dev/null", O_RDONLY); if(stdin_fd == -1) exit(127); dup2(stdin_fd, 1); dup2(stdin_fd, 2); close(stdin_fd); s_param.sched_priority = sched_get_priority_max(SCHED_FIFO); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } if(sched_setscheduler(getpid(), SCHED_FIFO, &s_param)){ fprintf(stderr, "Sched error: sched_setscheduler\n"); exit(17); } if(execl(argv[1], "RT task", NB_RT_ITERATION, NULL) == -1){ fprintf(stderr, "Execl error: Couldn't launch RT exec\n"); exit(17); } exit(0); }else if(rt_child == -1){ fprintf(stderr, "Fork: couldn't create the RT child.\n"); exit(16); /**********************************************************************************************/ //The scheduler }else{ sleep(1); //<= Waiting for stationnary period if(timer_settime(tid, 0, &new_tmr, NULL) == -1){ perror("Timer_settime"); exit(3); } // Launch the counters and the timer if((ret = PAPI_start(PAPI_EventSet)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } if((ret = PAPI_start(scheduler_eventset)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } struct timeval tv1, tv2; gettimeofday(&tv1, NULL); // Wait for RT child to finish, then kill attackers ret = -1; while(ret != rt_child){ ret = waitpid(rt_child, &status, 0); } if (!WIFEXITED(status)) { fprintf(stderr, "scheduler: Child exited with wrong status\n"); exit(16); } for(i=0; i<nb_attackers; i++){ fprintf(stderr, "\nScheduler (%d) > Sending signal to %d\n", getpid(), pid_attacker[i]); kill(pid_attacker[i], SIGKILL); } gettimeofday(&tv2, NULL); char time_to_char[20]; printf ("\nTotal time = %f seconds\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); sprintf(time_to_char, "%f\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); // Stopping and reading for Gnuplot if((ret = PAPI_stop(PAPI_EventSet, papi_values))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_stop(scheduler_eventset, &scheduler_value))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_read(PAPI_EventSet, papi_values)) != PAPI_OK){ fprintf(stderr, "PAPI error : Couldn't read the values %s\n", PAPI_strerror(ret)); exit(18); } // Printing and writting for Gnuplot print_counters(papi_values); write_miss_values(1, nb_attackers, papi_values); // Writting the time for Gnuplot int fic_time; char fic_name[50]; switch(atoi(argv[2])){ case 0: strcpy(fic_name, "plot/mesures_execution_0_scheduler.data"); break; case 1: strcpy(fic_name, "plot/mesures_execution_1_scheduler.data"); break; case 2: strcpy(fic_name, "plot/mesures_execution_2_scheduler.data"); break; default: strcpy(fic_name, "plot/mesures_execution.data"); break; } if ((fic_time = open(fic_name, O_RDWR | O_APPEND))==-1){ perror("Open error on fic_time\n"); exit(19); } if (write(fic_time, time_to_char, strlen(time_to_char))==0){ fprintf(stderr, "Write exec_time error\n"); exit(20); } // Cleaning event sets if((ret=PAPI_cleanup_eventset(PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_cleanup_eventset(scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_destroy_eventset(&PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } if((ret=PAPI_destroy_eventset(&scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } } return EXIT_SUCCESS; }
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; }