int _hl_rate_calls(float *real_time, float *proc_time, long long * ins, float *rate, int EVENT, HighLevelInfo * state) { long long values[2] = { 0, 0 }; int retval = 0; int level = 0; if (EVENT == PAPI_FP_INS) level = HL_FLIPS; else if (EVENT == PAPI_TOT_INS) level = HL_IPC; else if (EVENT == PAPI_FP_OPS) level = HL_FLOPS; if (state->running != 0 && state->running != level) return (PAPI_EINVAL); if (state->running == 0) { if (PAPI_query_event(EVENT) != PAPI_OK) return (PAPI_ENOEVNT); if ((retval = PAPI_add_event(state->EventSet, EVENT)) != PAPI_OK) { _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } if (PAPI_query_event(PAPI_TOT_CYC) != PAPI_OK) return (PAPI_ENOEVNT); if ((retval = PAPI_add_event(state->EventSet, PAPI_TOT_CYC)) != PAPI_OK) { _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } state->initial_time = PAPI_get_real_usec(); if ((retval = PAPI_start(state->EventSet)) != PAPI_OK) return (retval); state->running = level; } else { if ((retval = PAPI_stop(state->EventSet, values)) != PAPI_OK) return (retval); /* Use Multiplication because it is much faster */ *real_time = (float) ((long long)(PAPI_get_real_usec() - state->initial_time) * .000001); *proc_time = (float) (values[1]*.000001/((_papi_hwi_system_info.hw_info.mhz==0)?1:_papi_hwi_system_info.hw_info.mhz)); if (*proc_time > 0) *rate = (float) ((float) values[0]*(EVENT==PAPI_TOT_INS?1:_papi_hwi_system_info.hw_info.mhz)/(values[1]==0?1:values[1])); state->total_proc_time += *proc_time; state->total_ins += values[0]; *proc_time = state->total_proc_time; *ins = (long long)state->total_ins; if ((retval = PAPI_start(state->EventSet)) != PAPI_OK) { state->running = 0; return (retval); } } return PAPI_OK; }
/** @class PAPI_stop_counters * @brief Stop counting hardware events and reset values to zero. * * @par C Interface: * \#include <papi.h> @n * int PAPI_stop_counters( long long *values, int array_len ); * * @param *values * an array where to put the counter values * @param array_len * the number of items in the *values array * * @post * After this function is called, the values are reset to zero. * * @retval PAPI_EINVAL * One or more of the arguments is invalid. * @retval PAPI_ENOTRUN * The EventSet is not started yet. * @retval PAPI_ENOEVST * The EventSet has not been added yet. * * The PAPI_stop_counters() function stops the counters and copies the counts * into the *values array. * The counters must have been started by a previous call to PAPI_start_counters(). * * \code int Events[2] = { PAPI_TOT_CYC, PAPI_TOT_INS }; long long values[2]; if ( PAPI_start_counters( Events, 2 ) != PAPI_OK ) handle_error(1); your_slow_code(); if ( PAPI_stop_counters( values, 2 ) != PAPI_OK ) handle_error(1); * \endcode * * @see PAPI_read_counters() PAPI_start_counters() PAPI_set_opt() */ int PAPI_stop_counters( long long *values, int array_len ) { int retval; HighLevelInfo *state = NULL; if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) return ( retval ); if ( state->running == 0 ) return ( PAPI_ENOTRUN ); if ( state->running == HL_START ) { if ( array_len < state->num_evts || values == NULL) { return ( PAPI_EINVAL ); } else { retval = PAPI_stop( state->EventSet, values ); } } if ( state->running > HL_START ) { long long tmp_values[3]; retval = PAPI_stop( state->EventSet, tmp_values ); } if ( retval == PAPI_OK ) { _internal_cleanup_hl_info( state ); PAPI_cleanup_eventset( state->EventSet ); } APIDBG( "PAPI_stop_counters returns %d\n", retval ); return retval; }
int PAPI_stop_counters(long long * values, int array_len) { int retval; HighLevelInfo *state = NULL; if ((retval = _internal_check_state(&state)) != PAPI_OK) return (retval); if (state->running == 0) return (PAPI_ENOTRUN); if (state->running == HL_FLOPS || state->running == HL_FLIPS || state->running == HL_IPC) { long long tmp_values[2]; retval = PAPI_stop(state->EventSet, tmp_values); } else if(state->running != HL_START_COUNTERS || array_len < state->num_evts) return (PAPI_EINVAL); else retval = PAPI_stop(state->EventSet, values); if (retval==PAPI_OK) { _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); } APIDBG("PAPI_stop_counters returns %d\n", retval); return retval; }
int PAPI_start_counters(int *events, int array_len) { int i, retval; HighLevelInfo *state = NULL; if ((retval = _internal_check_state(&state)) != PAPI_OK) return (retval); if(state->running != 0) return(PAPI_EINVAL); /* load events to the new EventSet */ for (i = 0; i < array_len; i++) { retval = PAPI_add_event(state->EventSet, events[i]); if (retval == PAPI_EISRUN) return (retval); if (retval) { /* remove any prior events that may have been added * and cleanup the high level information */ _internal_cleanup_hl_info(state); PAPI_cleanup_eventset(state->EventSet); return (retval); } } /* start the EventSet */ if ((retval = _internal_start_hl_counters(state)) == PAPI_OK) { state->running = HL_START_COUNTERS; state->num_evts = array_len; } return (retval); }
int _hl_rate_calls( float *real_time, float *proc_time, int *events, long long *values, long long *ins, float *rate, int mode ) { long long rt, pt; // current elapsed real and process times in usec int num_events = 2; int retval = 0; HighLevelInfo *state = NULL; if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) { return ( retval ); } if ( state->running != HL_STOP && state->running != mode ) { return PAPI_EINVAL; } if ( state->running == HL_STOP ) { switch (mode) { case HL_FLOP: case HL_FLIP: num_events = 1; break; case HL_IPC: break; case HL_EPC: if ( events[2] != 0 ) num_events = 3; break; default: return PAPI_EINVAL; } if (( retval = PAPI_add_events( state->EventSet, events, num_events )) != PAPI_OK ) { _internal_cleanup_hl_info( state ); PAPI_cleanup_eventset( state->EventSet ); return retval; } state->total_ins = 0; state->initial_real_time = state->last_real_time = PAPI_get_real_usec( ); state->initial_proc_time = state->last_proc_time = PAPI_get_virt_usec( ); if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) { return retval; } /* Initialize the interface */ state->running = mode; *real_time = 0.0; *proc_time = 0.0; *rate = 0.0; } else { if ( ( retval = PAPI_stop( state->EventSet, values ) ) != PAPI_OK ) { state->running = HL_STOP; return retval; } /* Read elapsed real and process times */ rt = PAPI_get_real_usec(); pt = PAPI_get_virt_usec(); /* Convert to seconds with multiplication because it is much faster */ *real_time = ((float)( rt - state->initial_real_time )) * .000001; *proc_time = ((float)( pt - state->initial_proc_time )) * .000001; state->total_ins += values[0]; switch (mode) { case HL_FLOP: case HL_FLIP: /* Calculate MFLOP and MFLIP rates */ if ( pt > 0 ) { *rate = (float)values[0] / (pt - state->last_proc_time); } else *rate = 0; break; case HL_IPC: case HL_EPC: /* Calculate IPC */ if (values[1]!=0) { *rate = (float) ((float)values[0] / (float) ( values[1])); } break; default: return PAPI_EINVAL; } state->last_real_time = rt; state->last_proc_time = pt; if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) { state->running = HL_STOP; return retval; } } *ins = state->total_ins; return PAPI_OK; }