Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
void initialize_papi (int eventCode) {
  /* Initialize the PAPI library */
  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI library init error! %d\n",PAPI_EINVAL);
    handle_error(1);
  }
  
  if (EventSet==PAPI_NULL) {
  	if (PAPI_create_eventset(&EventSet) != PAPI_OK) {
	  	printf("PAPI create eventset error\n");
  	  handle_error(1);
  	}
  } else {
  	if (PAPI_cleanup_eventset(EventSet) != PAPI_OK) {
  		printf("PAPI cleanup error\n");
			handle_error(1);
		}
	}
	
  if (PAPI_add_event(EventSet, eventCode) != PAPI_OK) {
		printf("PAPI add event error: %x\n", eventCode);
    handle_error(1);
  }  
}
Ejemplo n.º 7
0
/** @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;
}
Ejemplo n.º 8
0
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");
}
Ejemplo n.º 9
0
/** 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;
	}
}
Ejemplo n.º 10
0
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");*/
    }
}
Ejemplo n.º 11
0
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");
    }
  }
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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

}
Ejemplo n.º 14
0
/* 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");
}
Ejemplo n.º 15
0
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();
        }
Ejemplo n.º 17
0
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);
}
Ejemplo n.º 18
0
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);
}
Ejemplo n.º 19
0
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]);
}
/*   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");
}
Ejemplo n.º 21
0
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);
}
Ejemplo n.º 22
0
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]);
}
Ejemplo n.º 23
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;
}
Ejemplo n.º 24
0
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();
	}
}
Ejemplo n.º 25
0
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;
}
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 28
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 );
}
Ejemplo n.º 29
0
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;
}
Ejemplo n.º 30
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;
}