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
int main(int argc, char* argv[]) 
{
	int rtn,i;
    	unsigned int test_size = atoi(argv[1]);
    	long_long s;
    	long_long e;
        
        //Incremental Data for testing
	for(i = 0; i < DATA_POINTS/4; i++){
            senddata[i] = i;
	}

    	printf("# Host to PCIE\n");
    	printf("# Transfer Size(Bytes), Transfer Time (s),Throughput: (MB/s)\n"); 
	
	s = PAPI_get_real_usec(); 
        rtn = fpga_transfer_data(HOST,USERPCIE1,(unsigned char *) senddata,test_size,0, 1);
        //fpga_wait_interrupt();
	e = PAPI_get_real_usec();         
	printf("%d, %f, %f\n", test_size,(e-s)*1e-6,(double)(test_size*1000000.0)/(1024.0*1024.0*(double)(e-s)));

        /*for(i=0;i<1024;i=i+4){
              rtn = fpga_ddr_pio_rd(i);
              printf("%d\n",rtn);
        }*/   


	return 0;
}                 
Ejemplo n.º 3
0
 main(){

	long_long start_cycles, end_cycles, start_usec, end_usec;
	int EventSet = PAPI_NULL;

	int tabla[100];

	        
	if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
	  exit(1);

	/* Gets the starting time in clock cycles */
	start_cycles = PAPI_get_real_cyc();

	/* Gets the starting time in microseconds */
	start_usec = PAPI_get_real_usec();

	/*Create an EventSet */
	//if (PAPI_create_eventset(&EventSet) != PAPI_OK)
	//  exit(1);
	tabla[0]=1;
	tabla[100]=1;
	/* Gets the ending time in clock cycles */
	end_cycles = PAPI_get_real_cyc();

	/* Gets the ending time in microseconds */
	end_usec = PAPI_get_real_usec();

	printf("Wall clock cycles: %lld\n", end_cycles - start_cycles);
	printf("Wall clock time in microseconds: %lld\n", end_usec - start_usec); 
}
/** Log performance counters into "pstats.dat" */
static void log_counters( FILE *out, const char *phase, long long *pTic, long long values[] ) {
    long long toc = PAPI_get_real_usec();

#ifdef CACHE_PROFILE
    if( PAPI_read_counters( values, 4 ) != PAPI_OK ) {
        handle_error( 1 );
    }

    fprintf( out, "%s PAPI_L2_TCM %lld\n", phase, values[0] );
    fprintf( out, "%s PAPI_L2_TCA %lld\n", phase, values[2] );
    fprintf( out, "%s L2MissRate %.4lf%\n", phase, ( double )values[0] / ( double )values[2] );
    fprintf( out, "%s PAPI_L3_TCM %lld\n", phase, values[1] );
    fprintf( out, "%s PAPI_L3_TCA %lld\n", phase, values[3] );
    fprintf( out, "%s L3MissRate %.4lf%\n", phase, ( double )values[1] / ( double )values[3] );
#else
    if( PAPI_read_counters( values, 1 ) != PAPI_OK ) {
        handle_error( 1 );
    }

    fprintf( out, "%s PAPI_FP_OPS %lld\n", phase, values[0] );
#endif

    fprintf( out, "%s RealTime %.4lfs\n", phase, ( toc - *pTic ) * 1e-6 );
    *pTic = PAPI_get_real_usec();
}
void *Thread(void *arg)
{
   int retval, num_tests = 1;
   int EventSet1=PAPI_NULL;
   int mask1, papi_event;
   int num_events1;
   long long **values;
   long long elapsed_us, elapsed_cyc;
   char event_name[PAPI_MAX_STR_LEN];

   /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
      PAPI_TOT_INS, depends on the availability of the event on the 
      platform */
   EventSet1 = add_two_nonderived_events(&num_events1, &papi_event, hw_info, &mask1);

   expected[EventSet1] = *(int *)arg / mythreshold;
   myid[EventSet1] = PAPI_thread_id();

   values = allocate_test_space(num_tests, num_events1);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

   if ((retval = PAPI_overflow(EventSet1, papi_event, mythreshold, 0, handler))
                 != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   /* start_timer(1); */
   if ((retval = PAPI_start(EventSet1)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_stuff();

   if ((retval = PAPI_stop(EventSet1, values[0])) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   if ((retval = PAPI_overflow(EventSet1, papi_event, 0, 0, NULL)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   remove_test_events(&EventSet1, mask1);

   if ((retval = PAPI_event_code_to_name(papi_event, event_name)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);

   if (!TESTS_QUIET) {
      printf("Thread 0x%x %s : \t%lld\n", (int) pthread_self(), 
                     event_name, (values[0])[0]);
      printf("Thread 0x%x PAPI_TOT_CYC: \t%lld\n", (int) pthread_self(), (values[0])[1]);
      printf("Thread 0x%x Real usec   : \t%lld\n", (int) pthread_self(), elapsed_us);
      printf("Thread 0x%x Real cycles : \t%lld\n", (int) pthread_self(), elapsed_cyc);
   }
   free_test_space(values, num_tests);
   pthread_exit(NULL);
   return (NULL);
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
   int retval;
   long long elapsed_us, elapsed_cyc;
   const PAPI_hw_info_t *hw_info;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

   printf("Testing real time clock. (CLOCK %d MHz, CPU %f MHz)\n",hw_info->clock_mhz,hw_info->mhz);
   printf("Sleeping for 10 seconds.\n");

   sleep(10);

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   printf("%lld us. %lld cyc.\n",elapsed_us,elapsed_cyc);
   printf("%f Computed MHz.\n",(float)elapsed_cyc/(float)elapsed_us);

/* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
   On Pentium III and 4, for example, cycles is a measured value, while useconds 
   is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
   Thus, any error in MHz is propagated to useconds.
   Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
   and cycles are computed from useconds. Also, MHz comes from a scan of system info,
   Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
   can be further impacted by errors in reported MHz.
   Without knowing the error bars on these system values, we can't really specify
   error ranges for our reported values, but we *DO* know that errors for at least
   one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
   Newer multicore Intel processors seem to have broken the relationship between the
   clock rate reported in /proc/cpuinfo and the actual computed clock. To accomodate
   this artifact, the test no longer fails, but merely reports results out of range.
*/

   if (elapsed_us < 9000000)
	   printf("NOTE: Elapsed real time less than 9 seconds!\n");
   if (elapsed_us > 11000000)
     printf("NOTE: Elapsed real time greater than 11 seconds!\n");
   if ((float)elapsed_cyc < 9.0 * hw_info->mhz * 1000000.0) 
     printf("NOTE: Elapsed real cycles less than 9*MHz*1000000.0!\n");
   if ((float)elapsed_cyc > 11.0 * hw_info->mhz * 1000000.0) 
     printf("NOTE: Elapsed real cycles greater than 11*MHz*1000000.0!\n");
   
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
   int i, retval;
   long long elapsed_us, elapsed_cyc;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

#if defined(_AIX)
   retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self));
   if (retval != PAPI_OK) {
      if (retval == PAPI_ESBSTR)
         test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval);
      else
         test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma ibm parallel_loop
#elif defined(sgi) && defined(mips)
   retval = PAPI_thread_init((unsigned long (*)(void)) (mp_my_threadnum));
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma parallel
#pragma local(i)
#pragma pfor
#elif defined(sun) && defined(sparc)
   retval = PAPI_thread_init((unsigned long (*)(void)) (thr_self));
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma MP taskloop private(i)
#else
#error "Architecture not included in this test file yet."
#endif
   for (i = 1; i < 3; i++)
      Thread(i, 10000000 * i);

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   if (!TESTS_QUIET) {
      printf("Master real usec   : \t%lld\n", elapsed_us);
      printf("Master real cycles : \t%lld\n", elapsed_cyc);
   }
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Ejemplo n.º 8
0
/**
 * \brief A bit-twiddling load which will run within the given bytes of memory.
 * \param [in] plan The struct that holds the plan's data values.
 * \return int Error flag value
 * \sa parseCBAPlan
 * \sa makeCBAPlan
 * \sa initCBAPlan
 * \sa perfCBAPlan
 * \sa killCBAPlan
 */
int execCBAPlan(void *plan){
    #ifdef HAVE_PAPI
    int k;
    long long start, end;
    #endif //HAVE_PAPI

    int i, j;
    int niters;
    ORB_t t1, t2;
    Plan *p;
    CBA_data *ci;

    p = (Plan *)plan;
    ci = (CBA_data *)p->vptr;

    /* update execution count */
    p->exec_count++;

    for(i = 0; i < ci->niter; i += NITERS){
        niters = ci->niter - i;
        if(niters > NITERS){
            niters = NITERS;
        }

        for(j = 0; j < niters; j++){
            /* pick NITERS random rows in the range 1..(nrow-1) */
            ci->out[j] = 1 + (brand(&(ci->br)) % (ci->nrows - 1));
            ci->out[j] <<= 48;              /* store index in high 16 bits */
        }

        if(DO_PERF){
            #ifdef HAVE_PAPI
            /* Start PAPI counters and time */
            TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME);
            start = PAPI_get_real_usec();
            #endif //HAVE_PAPI

            ORB_read(t1);
        }         //DO_PERF
        cnt_bit_arr (ci->work, ci->nrows, ci->ncols, ci->out, niters);
        if(DO_PERF){
            ORB_read(t2);

            #ifdef HAVE_PAPI
            end = PAPI_get_real_usec();             //PAPI time

            /* Collect PAPI counters and store time elapsed */
            TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME);
            for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){
                p->PAPI_Times[k] += (end - start);
            }
            #endif //HAVE_PAPI

            perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1));
        }         //DO_PERF
    }

    return ERR_CLEAN;
} /* execCBAPlan */
Ejemplo n.º 9
0
/**
 * \brief <DESCRIPTION of your plan goes here..>
 * \param plan The Plan struct that holds the plan's data values.
 * \return int Error flag value
 */
int execDOPENACCGEMMPlan(void *plan){  // <- Replace YOUR_NAME with the name of your module.
    #ifdef HAVE_PAPI
    int k;
    long long start, end;
    #endif //HAVE_PAPI

    ORB_t t1, t2;         // Storage for timestamps, used to accurately find the runtime of the plan execution.
    Plan *p;
    p = (Plan *)plan;
    p->exec_count++;       // Update the execution counter stored in the plan.
    DOPENACCGEMM_DATA *local_data = (DOPENACCGEMM_DATA *)p->vptr;

    int error;
    #ifdef HAVE_PAPI
    /* Start PAPI counters and time */
    TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME);

    start = PAPI_get_real_usec();
    #endif //HAVE_PAPI

    ORB_read(t1);         // Store the timestamp for the beginning of the execution.

    int jdx;

    for(jdx=0;jdx < local_data->loop_count; jdx++)
    {
      systemburn_openaccblas_dgemm(local_data);
    }
    // --------------------------------------------
    // Plan is executed here...
    // --------------------------------------------

    ORB_read(t2);         // Store timestamp for the end of execution.

    #ifdef HAVE_PAPI
    end = PAPI_get_real_usec();     //PAPI time

    /* Collect PAPI counters and store time elapsed */
    TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME);
    for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){
        p->PAPI_Times[k] += (end - start);
    }
    #endif //HAVE_PAPI

    perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1));      // Store the difference between the timestamps in the plan's timers.

    if(CHECK_CALC){           // Evaluates to true if the '-t' option is passed on the commandline.
        ORB_read(t1);

        // ----------------------------------------------------------------
        // Optional: Check calculations performed in execution above.
        // ----------------------------------------------------------------

        ORB_read(t2);
        perftimer_accumulate(&p->timers, TIMER1, ORB_cycles_a(t2, t1));
    }

    return ERR_CLEAN;     // <- This inicates a clean run with no errors. Does not need to be changed.
} /* execDOPENACCGEMMPlan */
Ejemplo n.º 10
0
void
Thread( int t, int n )
{
	int retval, num_tests = 1;
	int EventSet1 = PAPI_NULL;
	int PAPI_event, mask1;
	int num_events1;
	long long **values;
	long long elapsed_us, elapsed_cyc;
	char event_name[PAPI_MAX_STR_LEN];

	/* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
	   PAPI_TOT_INS, depending on the availability of the event on the
	   platform */
	EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );

	retval = PAPI_event_code_to_name( PAPI_event, event_name );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	values = allocate_test_space( num_tests, num_events1 );

	retval = PAPI_start( EventSet1 );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	do_flops( n );

	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	retval = PAPI_stop( EventSet1, values[0] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	remove_test_events( &EventSet1, mask1 );

	if ( !TESTS_QUIET ) {
		printf( "Thread %#x %-12s : \t%lld\n", t, event_name,
				values[0][1] );
		printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t, 
			values[0][0] );
	}

	free_test_space( values, num_tests );
	if ( !TESTS_QUIET ) {
		printf( "Thread %#x Real usec    : \t%lld\n", t, elapsed_us );
		printf( "Thread %#x Real cycles  : \t%lld\n", t, elapsed_cyc );
	}
	PAPI_unregister_thread(  );
}
Ejemplo n.º 11
0
void Thread( int n ){

	int retval, num_tests = 1;
	int EventSet1 = PAPI_NULL;
	int PAPI_event, mask1;
	int num_events1;
	long long **values;
	long long elapsed_us, elapsed_cyc, L1_DCM;
	char event_name[PAPI_MAX_STR_LEN];

	printf( "Thread %#x started\n", omp_get_thread_num(  ) );
	num_events1 = 2;

	EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );

	retval = PAPI_event_code_to_name( PAPI_event, event_name );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	values = allocate_test_space( num_tests, num_events1 );

	elapsed_us = PAPI_get_real_usec(  );
	
	elapsed_cyc = PAPI_get_real_cyc(  );

	retval = PAPI_start( EventSet1 );

	do_flops( n );

	retval = PAPI_stop( EventSet1, values[0] );

	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	remove_test_events( &EventSet1, mask1 );

	if ( !TESTS_QUIET ) {
		printf( "Thread %#x %-12s : \t%lld\n", omp_get_thread_num(  ),
			event_name, values[0][1] );
		printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num(  ),
			values[0][0] );
		printf( "Thread %#x Real usec   : \t%lld\n", omp_get_thread_num(  ),
			elapsed_us );
		printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num(  ),
			elapsed_cyc );
	}

	free_test_space( values, num_tests );

	PAPI_unregister_thread(  );
	printf( "Thread %#x finished\n", omp_get_thread_num(  ) );
}
int main(int argc, char** argv)
{
	int c;
	char* s;
	char* t;
	
	unsigned int distance = 0;

	unsigned int len_s;
	unsigned int len_t;

	/*for measuring time*/
	long_long start_usec, end_usec;

	while ((c = getopt (argc, argv, "s:t:")) != -1)
	{
		switch(c)
		{
			case 's':
				s = optarg;
				break;
			case 't':
				t = optarg;
				break;
			case '?':
				if ((optopt == 's') || (optopt == 't'))
		       			fprintf(stderr, "Option -%c requires an argument.\n", optopt);
				else
		       			fprintf(stderr, "Unknown option `-%c'.\n", optopt);
				return 1;
		}
	}

	len_s = strlen(s);
	len_t = strlen(t);

	/*get initial time*/
	start_usec = PAPI_get_real_usec();

	/*computing levenshtein*/
	distance = levenshtein(s, len_s, t, len_t);

	/*computing final time*/
	end_usec = PAPI_get_real_usec();

	printf("The levesthein distance: %d\n", distance);
	printf("\nTotal time spent: %.8f (s)\n", (end_usec - start_usec) / 1000000.0);

	return 0;
}
Ejemplo n.º 13
0
int
_infiniband_stop( hwd_context_t *ctx, hwd_control_state_t *ctl )
{
   infiniband_context_t* context = (infiniband_context_t*) ctx;
   infiniband_control_state_t* control = (infiniband_control_state_t*) ctl;
   long long now = PAPI_get_real_usec();
   int i;
   long long temp;

   for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
      if (control->being_measured[i])
      {
         temp = read_ib_counter_value(i);
         if (context->start_value[i] && control->need_difference[i]) {
            /* Must subtract values, but check for wraparound. 
             * We cannot even detect all wraparound cases. Using the short,
             * auto-resetting IB counters is error prone.
             */
            if (temp < context->start_value[i]) {
               SUBDBG("Wraparound!\nstart:\t%#016x\ttemp:\t%#016x",
                        (unsigned)context->start_value[i], (unsigned)temp);
               /* The counters auto-reset. I cannot even adjust them to 
                * account for a simple wraparound. 
                * Just use the current reading of the counter, which is useless.
                */
            } else
               temp -= context->start_value[i];
         }
         control->counts[i] = temp;
      }
   }
   control->lastupdate = now;

   return PAPI_OK;
}
Ejemplo n.º 14
0
int
_net_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
    long long ** events, int flags )
{
    (void) flags;
    (void) ctx;

    NET_control_state_t *net_ctl = (NET_control_state_t *) ctl;
    long long now = PAPI_get_real_usec();
    int i;

    /* Caching
     * Only read new values from /proc if enough time has passed
     * since the last read.
     */
    if ( now - net_ctl->lastupdate > NET_REFRESH_LATENCY ) {
        read_net_counters(_net_register_current);
        for ( i=0; i<NET_MAX_COUNTERS; i++ ) {
            net_ctl->values[i] = _net_register_current[i] - _net_register_start[i];
        }
        net_ctl->lastupdate = now;
    }
    *events = net_ctl->values;

    return PAPI_OK;
}
Ejemplo n.º 15
0
void
Thread( int n )
{
	int retval, num_tests = 1, tmp;
	int EventSet1 = PAPI_NULL;
	int mask1 = 0x5;
	int num_events1;
	long long **values;
	long long elapsed_us, elapsed_cyc;

	EventSet1 = add_test_events( &num_events1, &mask1 );

	/* num_events1 is greater than num_events2 so don't worry. */

	values = allocate_test_space( num_tests, num_events1 );

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	retval = PAPI_start( EventSet1 );
	if ( retval >= PAPI_OK )
		exit( 1 );

	do_flops( n );

	retval = PAPI_stop( EventSet1, values[0] );
	if ( retval >= PAPI_OK )
		exit( 1 );

	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	remove_test_events( &EventSet1, mask1 );

	printf( "Thread %#x PAPI_FP_INS : \t%lld\n", pthread_self(  ),
			( values[0] )[0] );
	printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", pthread_self(  ),
			( values[0] )[1] );
	printf( "Thread %#x Real usec   : \t%lld\n", pthread_self(  ),
			elapsed_us );
	printf( "Thread %#x Real cycles : \t%lld\n", pthread_self(  ),
			elapsed_cyc );

	free_test_space( values, num_tests );
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
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.º 18
0
/* PAPI wallclock time */
void metric_read_papiwallclock(int tid, int idx, double values[]) {
  static long long oldvalue = 0L;
  static long long offset = 0;
  long long newvalue = 0L;
#ifdef TAU_PAPI
  newvalue = PAPI_get_real_usec();
  if (newvalue < oldvalue) {
    offset += UINT_MAX;
    DEBUGPROFMSG("WARNING: papi counter overflow. Fixed in TAU! new = "
                 << newvalue << " old = " << oldvalue << " offset = " << offset << endl;
                 );
void *Slave(void *arg)
{
   long long duration;

   sleep(1);
   duration = PAPI_get_real_usec();
   lockloop(10000,&tmpcount);
   duration = PAPI_get_real_usec() - duration;

   /* First one here set's the number */
   PAPI_lock(PAPI_USR2_LOCK);
   if (num_iters == 0) {
     printf("10000 iterations took %lld us.\n",duration);
     num_iters = 10*(TIME_LIMIT_IN_US/duration);
     printf("Running %d iterations\n",num_iters);
   }
   PAPI_unlock(PAPI_USR2_LOCK);

   lockloop(num_iters,&count);
   pthread_exit(NULL);
}
Ejemplo n.º 20
0
/** Setup the counter control structure */
int
example_init_control_state( hwd_control_state_t * ctrl )
{
	SUBDBG( "example_init_control_state..." );

	/* set the hardware to initial conditions */
	example_hardware_reset(  );

	/* set the counters last-accessed time */
	( ( example_control_state_t * ) ctrl )->lastupdate = PAPI_get_real_usec(  );

	return PAPI_OK;
}
Ejemplo n.º 21
0
int
main(  )
{
	int i, rc;
	long long elapsed_us, elapsed_cyc;

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	start_pes( 2 );
	Thread( 1000000 * ( _my_pe(  ) + 1 ) );

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	printf( "Master real usec   : \t%lld\n", elapsed_us );
	printf( "Master real cycles : \t%lld\n", elapsed_cyc );

	exit( 0 );
}
Ejemplo n.º 22
0
double getTime(){
#if PAPI
    return PAPI_get_real_usec();
#else
    struct timespec ts;
    clock_gettime( CLOCK_REALTIME, &ts );
    return ( ts.tv_nsec + ts.tv_sec * 1000000000 );

    /*    struct timeval tv;
    gettimeofday( &tv, NULL );
    return ( tv.tv_sec * 1000000 + tv.tv_usec );*/
#endif
}
Ejemplo n.º 23
0
/** Triggered by PAPI_reset */
int
example_reset( hwd_context_t * ctx, hwd_control_state_t * ctrl )
{
        (void) ctx;

	SUBDBG( "example_reset ctx=%p ctrl=%p...", ctx, ctrl );

	/* Reset the hardware */
	example_hardware_reset(  );
	/* Set the counters last-accessed time */
	( ( example_control_state_t * ) ctrl )->lastupdate = PAPI_get_real_usec(  );

	return PAPI_OK;
}
Ejemplo n.º 24
0
/*
* TIMERS: TIME STOP
*/
void OSCR_timer_stop(int ind) {
    OSCR_timer_check("timerStop", ind);

    if ( ! oscrTimers[ind].active )
        OSCR_error("internal - timerStop, timer already stoped ->",ind);
    oscrTimers[ind].active = 0;


#ifdef __USE_PAPI
    oscrTimers[ind].elapsed += ((PAPI_get_real_usec() / SCALEPAPI) - oscrTimers[ind].start);
#else
    oscrTimers[ind].elapsed += (OSCR_wtime() - oscrTimers[ind].start);
#endif
}
Ejemplo n.º 25
0
/*
* TIMERS: TIME START
*/
void OSCR_timer_start(int ind) {
    OSCR_timer_check("timerStart", ind);

    if ( oscrTimers[ind].active )
        OSCR_error("internal - timerStart, timer already started ->",ind);
    oscrTimers[ind].active = 1;

#ifdef __USE_PAPI
    oscrTimers[ind].start = PAPI_get_real_usec() / SCALEPAPI;
#else
    oscrTimers[ind].start = OSCR_wtime();
#endif


}
Ejemplo n.º 26
0
/**
 * @brief Return the time in nanoseconds from first call to trios_get_time_*.
 */
uint64_t trios_get_time_ns()
{
    uint64_t result = 0;

#ifdef USING_PAPI

    long_long cur_usec, diff_usec;

    init_timer();
    cur_usec = PAPI_get_real_usec();
    diff_usec = cur_usec - init_usec;

    /* to convert to ns, multiply by 1000 */
    result = diff_usec * 1000;
#endif

#ifdef USING_CLOCK_GETTIME
    struct timespec tp;

    init_timer();
    clock_gettime(clockid, &tp);
    result = ts_diff_nsec(ts_init, tp);
#endif

#ifdef USING_MACH_ABSOLUTE_TIME
    static mach_timebase_info_data_t info = {0,0};

    init_timer();
    if (info.denom == 0)
        mach_timebase_info(&info);

    result = mach_absolute_time() * (info.numer / info.denom);
#endif

#ifdef USING_GETTIMEOFDAY
    struct timeval tp;

    init_timer();
    gettimeofday( &tp, NULL );

    result = tv_diff_us(tv_init, tp);
    result = result*(uint64_t)1000;
#endif


    return result;
}
Ejemplo n.º 27
0
int
_infiniband_start( hwd_context_t *ctx, hwd_control_state_t *ctl )
{
   infiniband_context_t* context = (infiniband_context_t*) ctx;
   infiniband_control_state_t* control = (infiniband_control_state_t*) ctl;
   long long now = PAPI_get_real_usec();
   int i;

   for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
      if (control->being_measured[i] && control->need_difference[i]) {
         context->start_value[i] = read_ib_counter_value(i);
      }
   }
   control->lastupdate = now;

   return PAPI_OK;
}
Ejemplo n.º 28
0
int
_net_stop( hwd_context_t *ctx, hwd_control_state_t *ctl )
{
    (void) ctx;

    NET_control_state_t *net_ctl = (NET_control_state_t *) ctl;
    long long now = PAPI_get_real_usec();
    int i;

    read_net_counters(_net_register_current);
    for ( i=0; i<NET_MAX_COUNTERS; i++ ) {
        net_ctl->values[i] = _net_register_current[i] - _net_register_start[i];
    }
    net_ctl->lastupdate = now;

    return PAPI_OK;
}
Ejemplo n.º 29
0
int
_net_start( hwd_context_t *ctx, hwd_control_state_t *ctl )
{
    ( void ) ctx;

    NET_control_state_t *net_ctl = (NET_control_state_t *) ctl;
    long long now = PAPI_get_real_usec();

    read_net_counters(_net_register_start);
    memcpy(_net_register_current, _net_register_start,
            NET_MAX_COUNTERS * sizeof(_net_register_start[0]));

    /* set initial values to 0 */
    memset(net_ctl->values, 0, NET_MAX_COUNTERS*sizeof(net_ctl->values[0]));
    
    /* Set last access time for caching purposes */
    net_ctl->lastupdate = now;

    return PAPI_OK;
}
Ejemplo n.º 30
0
static void init_timer() {
    static int initialized = 0;
    if (!initialized) {
        int mpi_initialized=0;

#ifdef USING_PAPI
        PAPI_library_init(PAPI_VER_CURRENT);

        init_usec = PAPI_get_real_usec();
        init_cycles = PAPI_get_real_cyc();
#endif

#ifdef USING_CLOCK_GETTIME
        clock_getres(clockid, &ts_res);
        clock_gettime(clockid, &ts_init);
#endif

#ifdef USING_GETTIMEOFDAY
        gettimeofday(&tv_init, NULL);
#endif

        initialized = 1;
    }
}