Esempio n. 1
0
int
wait_for_attach_and_loop( int num )
{
	kill( getpid(  ), SIGSTOP );
	do_flops( NUM_FLOPS * num );
	kill( getpid(  ), SIGSTOP );
	return ( 0 );
}
Esempio n. 2
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(  );
}
Esempio n. 3
0
int main(int argc, char **argv)
{
      int c, i = NUM_FLOPS;
        if (argc > 1) {
	         c =  atoi(argv[1]);
		      if (c >= 0) {
			         i = c;
				      }
		        }
	  do_flops(i);
	    exit(0);
}
Esempio n. 4
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(  ) );
}
Esempio n. 5
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 );
}
int main( int argc, char **argv ) {

   int retval;
   int EventSet = PAPI_NULL;
   int EventSet2 = PAPI_NULL;
   long long values[1],values2[1];
   char *uncore_event=NULL;
   char event_name[BUFSIZ];
   int uncore_cidx=-1;
   const PAPI_component_info_t *info;

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

   /* Init the PAPI library */
   retval = PAPI_library_init( PAPI_VER_CURRENT );
   if ( retval != PAPI_VER_CURRENT ) {
      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
   }

   /* Find the uncore PMU */
   uncore_cidx=PAPI_get_component_index("perf_event_uncore");
   if (uncore_cidx<0) {
      test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
   }

   /* Check if component disabled */
   info=PAPI_get_component_info(uncore_cidx);
   if (info->disabled) {
      test_skip(__FILE__,__LINE__,"uncore component disabled",0);
   }

   /* Get a relevant event name */
   uncore_event=get_uncore_event(event_name, BUFSIZ);
   if (uncore_event==NULL) {
      test_skip( __FILE__, __LINE__,
	        "PAPI does not support uncore on this processor", PAPI_ENOSUPP );
   }

   /* Create an eventset */
   retval = PAPI_create_eventset(&EventSet);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   /* Create another eventset */
   retval = PAPI_create_eventset(&EventSet2);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   /* Set a component for the EventSet */
   retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);

   /* we need to set to a certain cpu for uncore to work */

   PAPI_cpu_option_t cpu_opt;

   cpu_opt.eventset=EventSet;
   cpu_opt.cpu_num=0;

   retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
   if (retval != PAPI_OK) {
      test_skip( __FILE__, __LINE__,
		      "this test; trying to PAPI_CPU_ATTACH; need to run as root",
		      retval);
   }

   /* we need to set the granularity to system-wide for uncore to work */

   PAPI_granularity_option_t gran_opt;

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet;
   gran_opt.granularity=PAPI_GRN_SYS;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      test_skip( __FILE__, __LINE__,
		      "this test; trying to set PAPI_GRN_SYS",
		      retval);
   }

   /* we need to set domain to be as inclusive as possible */

   PAPI_domain_option_t domain_opt;

   domain_opt.def_cidx=0;
   domain_opt.eventset=EventSet;
   domain_opt.domain=PAPI_DOM_ALL;

   retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
   if (retval != PAPI_OK) {
      test_skip( __FILE__, __LINE__,
		      "this test; trying to set PAPI_DOM_ALL; need to run as root",
		      retval);
   }

   /* Add our uncore event */
   retval = PAPI_add_named_event(EventSet, uncore_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to use event %s\n", uncore_event);
      }
      test_fail(__FILE__, __LINE__, "adding uncore event ",retval);
   }

   /* Add PAPI_TOT_CYC */
   retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC");
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
      }
      test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
   }


   /* Start PAPI */
   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 );
   }

   /* our work code */
   do_flops( NUM_FLOPS );

   /* Stop PAPI */
   retval = PAPI_stop( EventSet, values );
   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 );
   }

   if ( !TESTS_QUIET ) {
      printf("Uncore and regular event test:\n");
      printf("Using uncore event %s\n",uncore_event);
      printf("\t%s: %lld\n",uncore_event,values[0]);
      printf("\t%s: %lld\n","PAPI_TOT_CYC",values2[0]);
   }

   test_pass( __FILE__, NULL, 0 );

   return 0;
}
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long *values;
   int num_flops, retval, i, j;
   int *events, mythreshold;
   char **names;
   const PAPI_hw_info_t *hw_info = NULL;
   int num_events, *ovt; 
   char name[PAPI_MAX_STR_LEN];

   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);

   /* 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 */
   EventSet = enum_add_native_events(&num_events, &events);
   names = (char **)calloc(num_events, sizeof(char *));
   for(i=0;i<num_events;i++){
     if (PAPI_event_code_to_name(events[i], name) != PAPI_OK) 
       test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);
     else
       names[i] = strdup(name);
   }
   values = (long long *)calloc(num_events*(num_events+1), sizeof(long long));
   ovt = (int *)calloc(num_events, sizeof(int));

#if defined(linux)
     {
       char *tmp = getenv("THRESHOLD");
       if (tmp) 
	     mythreshold = atoi(tmp);
       else
	     mythreshold = hw_info->mhz*10000*2;
     }
#else
      mythreshold = THRESHOLD;
#endif

   num_flops = NUM_FLOPS*2;

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

   do_flops(num_flops);

   retval = PAPI_stop(EventSet, values);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   for(i=0;i<num_events;i++){
     retval = PAPI_overflow(EventSet, events[i], mythreshold, 0, handler);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

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

     do_flops(num_flops);

     retval = PAPI_stop(EventSet, values+(i+1)*num_events);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
     retval = PAPI_overflow(EventSet, events[i], 0, 0, handler);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);
     ovt[i] = total;
     total=0;
   }

   if (!TESTS_QUIET) {

      printf("Test Overflow on %d counters with %d events.\n", num_events, num_events);
      printf("---------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", num_flops);
      printf("-----------------------------------------------\n");

      printf("Test type                   : ");
      for(i=0;i<num_events+1;i++)
        printf("%16d", i);
      printf("\n");
      for(j=0;j<num_events;j++){
        printf("%-27s : ", names[j]);
        for(i=0;i<num_events+1;i++)
          printf("%16lld", *(values+j+num_events*i));
        printf("\n");
      }
      printf("Overflows                   : %16s", "");
      for(i=0;i<num_events;i++)
        printf("%16d", ovt[i]);
      printf("\n");
      printf("-----------------------------------------------\n");
   }

   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);

   free(ovt);
   for(i=0;i<num_events;i++)
     free(names[i]);
   free(names);
   free(events);
   free(values);
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Esempio n. 8
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long ( values[3] )[2];
	int retval;
	int PAPI_event, k, i;
	char event_name[PAPI_MAX_STR_LEN];
	int index_array[2], number;
	int num_events1, mask1;

	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 );

	/* 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 */
	EventSet =
		add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );

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

	do_flops( NUM_FLOPS );

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

	retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, THRESHOLD, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

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

	do_flops( NUM_FLOPS );

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

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

	printf
		( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
	printf
		( "---------------------------------------------------------------\n" );
	printf( "Threshold for overflow is: %d\n", THRESHOLD );
	printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
	printf( "-----------------------------------------------\n" );

	printf( "Test type    : %16d%16d\n", 1, 2 );
	printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
	printf( OUT_FMT, event_name, ( values[0] )[1], ( values[1] )[1] );

	if ( overflow_counts[0].count == 0 && overflow_counts[1].count == 0 )
		test_fail( __FILE__, __LINE__, "one counter had no overflows", 1 );

	for ( k = 0; k < 3; k++ ) {
		if ( overflow_counts[k].mask ) {
			number = 2;
			retval = PAPI_get_overflow_event_index( EventSet,
													overflow_counts[k].mask,
													index_array, &number );
			if ( retval != PAPI_OK )
				test_fail( __FILE__, __LINE__,
						   "PAPI_get_overflow_event_index", retval );
			printf( INDEX_FMT, ( long long ) overflow_counts[k].mask );
			printf( " counts: %d ", overflow_counts[k].count );
			for ( i = 0; i < number; i++ )
				printf( " Event Index %d ", index_array[i] );
			printf( "\n" );
		}
	}
	printf( "Case 2 %s Overflows: %d\n", "Unknown", total_unknown );
	printf( "-----------------------------------------------\n" );

	if ( total_unknown > 0 )
		test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Esempio n. 9
0
int main(int argc, char **argv)
{
   int retval, num_tests = 5, num_events, tmp;
   long long **values;
   int EventSet=PAPI_NULL;
   int PAPI_event, mask;
   char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
   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);

   /* 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 */
   EventSet = add_two_events(&num_events, &PAPI_event, hw_info, &mask);

   retval = PAPI_event_code_to_name(PAPI_event, event_name);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);
   sprintf(add_event_str, "PAPI_add_event[%s]", event_name);

   values = allocate_test_space(num_tests, num_events);

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

   do_flops(NUM_FLOPS);

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

   retval = PAPI_reset(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_reset", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_read(EventSet, values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_read(EventSet, values[2]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   do_flops(NUM_FLOPS);

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

   retval = PAPI_read(EventSet, values[4]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   remove_test_events(&EventSet, mask);

   if (!TESTS_QUIET) {
      printf("Test case 1: Non-overlapping start, stop, read.\n");
      printf("-----------------------------------------------\n");
      tmp = PAPI_get_opt(PAPI_DEFDOM, NULL);
      printf("Default domain is: %d (%s)\n", tmp, stringify_all_domains(tmp));
      tmp = PAPI_get_opt(PAPI_DEFGRN, NULL);
      printf("Default granularity is: %d (%s)\n", tmp, stringify_granularity(tmp));
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf
          ("-------------------------------------------------------------------------\n");

      printf("Test type   :        1           2           3           4           5\n");
      sprintf(add_event_str, "%s:", event_name);
      printf(TAB5, add_event_str,
             (values[0])[0], (values[1])[0], (values[2])[0], (values[3])[0],
             (values[4])[0]);
      printf(TAB5, "PAPI_TOT_CYC:", (values[0])[1], (values[1])[1], (values[2])[1],
             (values[3])[1], (values[4])[1]);
      printf ("-------------------------------------------------------------------------\n"); 
      printf("Verification:\n");
      printf("Row 1 Column 1 at least %d\n", NUM_FLOPS);
      printf("%% difference between %s 1 & 2: %.2f\n",add_event_str,100.0*(float)(values[0])[0]/(float)(values[1])[0]);
      printf("%% difference between %s 1 & 2: %.2f\n","PAPI_TOT_CYC",100.0*(float)(values[0])[1]/(float)(values[1])[1]);
      printf("Column 1 approximately equals column 2\n");
      printf("Column 3 approximately equals 2 * column 2\n");
      printf("Column 4 approximately equals 3 * column 2\n");
      printf("Column 4 exactly equals column 5\n");
   }

   {
      long long min, max;
      min = (long long) (values[1][0] * .9);
      max = (long long) (values[1][0] * 1.1);

      if (values[0][0] > max || values[0][0] < min || values[2][0] > (2 * max)
          || values[2][0] < (2 * min) || values[3][0] > (3 * max)
          || values[3][0] < (3 * min)
          || values[3][0] != values[4][0]
          || values[0][0] < (long long)NUM_FLOPS) {
/*
         printf("min: ");
         printf(LLDFMT, min);
         printf("max: ");
         printf(LLDFMT, max);
         printf("1st: ");
         printf(LLDFMT, values[0][0]);
         printf("2nd: ");
         printf(LLDFMT, values[1][0]);
         printf("3rd: ");
         printf(LLDFMT, values[2][0]);
         printf("4th: ");
         printf(LLDFMT, values[3][0]);
         printf("5th: ");
         printf(LLDFMT, values[4][0]);
         printf("\n");
*/         test_fail(__FILE__, __LINE__, event_name, 1);
      }

      min = (long long) (values[1][1] * .8);
      max = (long long) (values[1][1] * 1.2);
      if (values[0][1] > max || values[0][1] < min || values[2][1] > (2 * max)
          || values[2][1] < (2 * min) || values[3][1] > (3 * max)
          || values[3][1] < (3 * min)
          || values[3][1] != values[4][1]) {
         test_fail(__FILE__, __LINE__, "PAPI_TOT_CYC", 1);
      }
   }
   test_pass(__FILE__, values, num_tests);
   exit(1);
}
Esempio n. 10
0
int main( int argc, char **argv ) {

   int retval;
   int EventSet1 = PAPI_NULL;
   int EventSet2 = PAPI_NULL;
   int EventSet3 = PAPI_NULL;
   int EventSet4 = PAPI_NULL;
   int EventSet5 = PAPI_NULL;
   int EventSet6 = PAPI_NULL;
   int EventSet7 = PAPI_NULL;
   int EventSet8 = PAPI_NULL;
   int EventSet9 = PAPI_NULL;
   int EventSet10 = PAPI_NULL;
 
   PAPI_domain_option_t domain_opt;
   PAPI_granularity_option_t gran_opt;
   PAPI_cpu_option_t cpu_opt;
   cpu_set_t mask;

   long long dom_user_values[1],dom_userkernel_values[1],dom_all_values[1];
   long long grn_thr_values[1],grn_proc_values[1];
   long long grn_sys_values[1],grn_sys_cpu_values[1];
   long long total_values[1],total_affinity_values[1];
   long long total_all_values[1];

   dom_user_values[0]=0;
   dom_userkernel_values[0]=0;
   dom_all_values[0]=0;
   grn_thr_values[0]=0;
   grn_proc_values[0]=0;
   grn_sys_values[0]=0;
   grn_sys_cpu_values[0]=0;
   total_values[0]=0;
   total_affinity_values[0]=0;
   total_all_values[0]=0;

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

   /* Init the PAPI library */
   retval = PAPI_library_init( PAPI_VER_CURRENT );
   if ( retval != PAPI_VER_CURRENT ) {
      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
   }

   /***************************/
   /***************************/
   /* Default, user events    */
   /***************************/
   /***************************/

   if (!TESTS_QUIET) {
      printf("\nTrying PAPI_TOT_CYC with different domains:\n");
   }

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_USER:\t\t\t");
   }

   retval = PAPI_create_eventset(&EventSet1);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_add_named_event(EventSet1, "PAPI_TOT_CYC");
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
      }
      test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
   }

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

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet1, dom_user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
      printf("%lld\n",dom_user_values[0]);
   }


   /***************************/
   /***************************/
   /* User+Kernel events      */
   /***************************/
   /***************************/

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_USER|PAPI_DOM_KERNEL:\t");
   }

   retval = PAPI_create_eventset(&EventSet2);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet2, 0);

   /* we need to set domain to be as inclusive as possible */

   domain_opt.def_cidx=0;
   domain_opt.eventset=EventSet2;
   domain_opt.domain=PAPI_DOM_USER|PAPI_DOM_KERNEL;

   retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
   if (retval != PAPI_OK) {

      if (retval==PAPI_EPERM) {
         test_skip( __FILE__, __LINE__,
		    "this test; trying to set PAPI_DOM_ALL; need to run as root",
		    retval);
      }
      else {
         test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval);
      }
   }


   retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC");
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
      }
      test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
   }

   retval = PAPI_start( EventSet2 );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet2, dom_userkernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
      printf("%lld\n",dom_userkernel_values[0]);
   }

   /***************************/
   /***************************/
   /* DOMAIN_ALL  events      */
   /***************************/
   /***************************/

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_ALL:\t\t\t");
   }

   retval = PAPI_create_eventset(&EventSet3);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet3, 0);

   /* we need to set domain to be as inclusive as possible */

   domain_opt.def_cidx=0;
   domain_opt.eventset=EventSet3;
   domain_opt.domain=PAPI_DOM_ALL;

   retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
   if (retval != PAPI_OK) {

      if (retval==PAPI_EPERM) {
         test_skip( __FILE__, __LINE__,
		    "this test; trying to set PAPI_DOM_ALL; need to run as root",
		    retval);
      }
      else {
         test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval);
      }
   }


   retval = PAPI_add_named_event(EventSet3, "PAPI_TOT_CYC");
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
      }
      test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
   }

   retval = PAPI_start( EventSet3 );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet3, dom_all_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
      printf("%lld\n",dom_all_values[0]);
   }


   /***************************/
   /***************************/
   /* PAPI_GRN_THR  events */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\nTrying different granularities:\n");
   }

   if ( !TESTS_QUIET ) {
      printf("\tPAPI_GRN_THR:\t\t\t");
   }

   retval = PAPI_create_eventset(&EventSet4);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet4, 0);

   /* Set the granularity to system-wide */

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet4;
   gran_opt.granularity=PAPI_GRN_THR;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      test_skip( __FILE__, __LINE__,
		      "this test; trying to set PAPI_GRN_THR",
		      retval);
   }


   retval = PAPI_add_named_event(EventSet4, "PAPI_TOT_CYC");
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
         fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
      }
      test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
   }

   retval = PAPI_start( EventSet4 );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet4, grn_thr_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
      printf("%lld\n",grn_thr_values[0]);
   }


   /***************************/
   /***************************/
   /* PAPI_GRN_PROC  events   */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\tPAPI_GRN_PROC:\t\t\t");
   }

   retval = PAPI_create_eventset(&EventSet5);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet5, 0);

   /* Set the granularity to system-wide */

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet5;
   gran_opt.granularity=PAPI_GRN_PROC;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      if (!TESTS_QUIET) {
         printf("Unable to set PAPI_GRN_PROC\n");
      }
   }
   else {
      retval = PAPI_add_named_event(EventSet5, "PAPI_TOT_CYC");
      if (retval != PAPI_OK) {
         if ( !TESTS_QUIET ) {
            printf("Error trying to add PAPI_TOT_CYC\n");
         }
         test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
      }

      retval = PAPI_start( EventSet5 );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
      }

      do_flops( NUM_FLOPS );

      retval = PAPI_stop( EventSet5, grn_proc_values );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
      }

      if ( !TESTS_QUIET ) {
         printf("%lld\n",grn_proc_values[0]);
      }
   }



   /***************************/
   /***************************/
   /* PAPI_GRN_SYS  events    */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\tPAPI_GRN_SYS:\t\t\t");
   }

   retval = PAPI_create_eventset(&EventSet6);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet6, 0);

   /* Set the granularity to system-wide */

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet6;
   gran_opt.granularity=PAPI_GRN_SYS;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      if (!TESTS_QUIET) {
         printf("Unable to set PAPI_GRN_SYS\n");
      }
   }
   else {
      retval = PAPI_add_named_event(EventSet6, "PAPI_TOT_CYC");
      if (retval != PAPI_OK) {
         if ( !TESTS_QUIET ) {
            printf("Error trying to add PAPI_TOT_CYC\n");
         }
      } else {

         retval = PAPI_start( EventSet6 );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_start", retval );
         }

         do_flops( NUM_FLOPS );

         retval = PAPI_stop( EventSet6, grn_sys_values );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
         }

         if ( !TESTS_QUIET ) {
            printf("GRN_SYS PAPI_TOT_CYC: %lld\n",grn_sys_values[0]);
         }
      }

   }


   /****************************/
   /****************************/
   /* PAPI_GRN_SYS_CPU  events */
   /****************************/
   /****************************/

   if ( !TESTS_QUIET ) {
      printf("\tPAPI_GRN_SYS_CPU:\t\t");
   }

   retval = PAPI_create_eventset(&EventSet7);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet7, 0);

   /* Set the granularity to system-wide */

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet7;
   gran_opt.granularity=PAPI_GRN_SYS_CPU;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      if (!TESTS_QUIET) {
         printf("Unable to set PAPI_GRN_SYS_CPU\n");
      }
   }
   else {
      retval = PAPI_add_named_event(EventSet7, "PAPI_TOT_CYC");
      if (retval != PAPI_OK) {
         if ( !TESTS_QUIET ) {
            printf("Error trying to add PAPI_TOT_CYC\n");
         }
         test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
      }

      retval = PAPI_start( EventSet7 );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
      }

      do_flops( NUM_FLOPS );

      retval = PAPI_stop( EventSet7, grn_sys_cpu_values );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
      }

      if ( !TESTS_QUIET ) {
         printf("%lld\n",grn_sys_cpu_values[0]);
      }
   }


   /***************************/
   /***************************/
   /* SYS and ATTACH  events  */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\nPAPI_GRN_SYS plus CPU attach:\n");
   }

   if ( !TESTS_QUIET ) {
      printf("\tGRN_SYS, DOM_USER, CPU 0 attach:\t");
   }

   retval = PAPI_create_eventset(&EventSet8);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }

   retval = PAPI_assign_eventset_component(EventSet8, 0);

   /* Set the granularity to system-wide */

   gran_opt.def_cidx=0;
   gran_opt.eventset=EventSet8;
   gran_opt.granularity=PAPI_GRN_SYS;

   retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
   if (retval != PAPI_OK) {
      if (!TESTS_QUIET) {
         printf("Unable to set PAPI_GRN_SYS\n");
      }
   }
   else {
      /* we need to set to a certain cpu */

      cpu_opt.eventset=EventSet8;
      cpu_opt.cpu_num=0;

      retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
      if (retval != PAPI_OK) {
	 if (retval==PAPI_EPERM) {
            test_skip( __FILE__, __LINE__,
		    "this test; trying to CPU_ATTACH; need to run as root",
		    retval);
	 }

         test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval);
      }

      retval = PAPI_add_named_event(EventSet8, "PAPI_TOT_CYC");
      if (retval != PAPI_OK) {
         if ( !TESTS_QUIET ) {
            printf("Error trying to add PAPI_TOT_CYC\n");
         }
         test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
      }

      retval = PAPI_start( EventSet8 );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
      }

      do_flops( NUM_FLOPS );

      retval = PAPI_stop( EventSet8, total_values );
      if ( retval != PAPI_OK ) {
         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
      }

      if ( !TESTS_QUIET ) {
         printf("%lld\n",total_values[0]);
      }
   }


   /***************************/
   /***************************/
   /* SYS and ATTACH, bind CPU  events  */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\tGRN_SYS, DOM_USER, CPU 0 affinity:\t");
   }

   /* Set affinity to CPU 0 */
   CPU_ZERO(&mask);
   CPU_SET(0,&mask);
   retval=sched_setaffinity(0, sizeof(mask), &mask);

   if (retval<0) {
     if (!TESTS_QUIET) {
        printf("Setting affinity failed: %s\n",strerror(errno));
     }
   } else {
   
      retval = PAPI_create_eventset(&EventSet9);
      if (retval != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
      }

      retval = PAPI_assign_eventset_component(EventSet9, 0);

      /* Set the granularity to system-wide */

      gran_opt.def_cidx=0;
      gran_opt.eventset=EventSet9;
      gran_opt.granularity=PAPI_GRN_SYS;

      retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
      if (retval != PAPI_OK) {
         if (!TESTS_QUIET) {
            printf("Unable to set PAPI_GRN_SYS\n");
         }
      }
      else {
         /* we need to set to a certain cpu for uncore to work */
      
         cpu_opt.eventset=EventSet9;
         cpu_opt.cpu_num=0;

         retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
         if (retval != PAPI_OK) {
            test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval);
         }

         retval = PAPI_add_named_event(EventSet9, "PAPI_TOT_CYC");
         if (retval != PAPI_OK) {
            if ( !TESTS_QUIET ) {
               printf("Error trying to add PAPI_TOT_CYC\n");
            }
            test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
         }

         retval = PAPI_start( EventSet9 );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_start", retval );
         }

         do_flops( NUM_FLOPS );

         retval = PAPI_stop( EventSet9, total_affinity_values );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
         }

         if ( !TESTS_QUIET ) {
            printf("%lld\n",total_affinity_values[0]);
         }
      }
   }

   /***************************/
   /***************************/
   /* SYS and ATTACH, bind CPU  events  */
   /***************************/
   /***************************/

   if ( !TESTS_QUIET ) {
      printf("\tGRN_SYS, DOM_ALL, CPU 0 affinity:\t");
   }



   /* Set affinity to CPU 0 */
   CPU_ZERO(&mask);
   CPU_SET(0,&mask);
   retval=sched_setaffinity(0, sizeof(mask), &mask);

   if (retval<0) {
     if (!TESTS_QUIET) {
        printf("Setting affinity failed: %s\n",strerror(errno));
     }
   } else {
   
      retval = PAPI_create_eventset(&EventSet10);
      if (retval != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
      }

      retval = PAPI_assign_eventset_component(EventSet10, 0);

      /* Set DOM_ALL */
      domain_opt.def_cidx=0;
      domain_opt.eventset=EventSet10;
      domain_opt.domain=PAPI_DOM_ALL;

      retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
      if (retval != PAPI_OK) {

         if (retval==PAPI_EPERM) {
            test_skip( __FILE__, __LINE__,
		    "this test; trying to set PAPI_DOM_ALL; need to run as root",
		    retval);
         }
         else {
            test_fail(__FILE__, __LINE__, "setting PAPI_DOM_ALL",retval);
         }
      }

      /* Set the granularity to system-wide */

      gran_opt.def_cidx=0;
      gran_opt.eventset=EventSet10;
      gran_opt.granularity=PAPI_GRN_SYS;

      retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
      if (retval != PAPI_OK) {
         if (!TESTS_QUIET) {
            printf("Unable to set PAPI_GRN_SYS\n");
         }
      }
      else {
         /* we need to set to a certain cpu for uncore to work */
      
         cpu_opt.eventset=EventSet10;
         cpu_opt.cpu_num=0;

         retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
         if (retval != PAPI_OK) {
            test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval);
         }

         retval = PAPI_add_named_event(EventSet10, "PAPI_TOT_CYC");
         if (retval != PAPI_OK) {
            if ( !TESTS_QUIET ) {
               printf("Error trying to add PAPI_TOT_CYC\n");
            }
            test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
         }

         retval = PAPI_start( EventSet10 );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_start", retval );
         }

         do_flops( NUM_FLOPS );

         retval = PAPI_stop( EventSet10, total_all_values );
         if ( retval != PAPI_OK ) {
            test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
         }

         if ( !TESTS_QUIET ) {
            printf("%lld\n",total_all_values[0]);
         }
      }
   }

   /**************/
   /* Validation */
   /**************/

   if ( !TESTS_QUIET ) {
      printf("\n");
   }

   if ( !TESTS_QUIET ) {
      printf("Validating:\n");
      printf("\tDOM_USER|DOM_KERNEL (%lld) > DOM_USER (%lld)\n",
             dom_userkernel_values[0],dom_user_values[0]);
   }
   if (dom_user_values[0] > dom_userkernel_values[0]) {
      test_fail( __FILE__, __LINE__, "DOM_USER too high", 0 );
   }

   if ( !TESTS_QUIET ) {
      printf("\n");
   }

   test_pass( __FILE__, NULL, 0 );

   return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long(values[2])[2];
   long long min, max;
   int num_flops = NUM_FLOPS, retval;
   int PAPI_event, mythreshold=THRESHOLD;
   char event_name[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info = NULL;
   int num_events, mask; 

   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);

   /* 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 */
   EventSet = add_two_nonderived_events(&num_events, &PAPI_event, hw_info, &mask);

   if ( PAPI_event == PAPI_FP_INS )
      mythreshold = THRESHOLD ;
   else 
#if defined(linux)
      mythreshold = hw_info->mhz*10000*2;
#else
      mythreshold = THRESHOLD*2;
#endif

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

   do_flops(NUM_FLOPS);

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

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

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

   do_flops(num_flops);

   retval = PAPI_stop(EventSet, values[1]);
   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);

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

      printf("Test case: Overflow dispatch of 2nd event in set with 2 events.\n");
      printf("---------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", num_flops);
      printf("-----------------------------------------------\n");

      printf("Test type    : %16d%16d\n", 1, 2);
      printf(OUT_FMT, event_name, (values[0])[0], (values[1])[0]);
      printf(OUT_FMT, "PAPI_TOT_CYC", (values[0])[1], (values[1])[1]);
      printf("Overflows    : %16s%16d\n", "", total);
      printf("-----------------------------------------------\n");
   }

   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 (!TESTS_QUIET) {
      printf("Verification:\n");
#if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4)
   num_flops *= 2;
#endif
      if (PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS){
         printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
      }
      printf("Column 1 approximately equals column 2\n");
      printf("Row 3 approximately equals %u +- %u %%\n",
             (unsigned) ((values[0])[0] / (long long) mythreshold),
             (unsigned) (OVR_TOLERANCE * 100.0));
   }
/*
  min = (long long)((values[0])[1]*(1.0-TOLERANCE));
  max = (long long)((values[0])[1]*(1.0+TOLERANCE));
  if ( (values[0])[1] > max || (values[0])[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

   min = (long long) (((values[0])[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold);
   max = (long long) (((values[0])[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold);
   printf("Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) ", total, max, total, min);
   if (total > max || total < min)
      test_fail(__FILE__, __LINE__, "Overflows", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Esempio n. 12
0
int main(int argc, char *argv[]) {
 int i,j,k,ii,ireg,three_reg=0;
 double gflops;
 volatile double a = 0.5, b = 2.2;
 double c = 0.11;
 long int nflop=128*1024*1024;
 long int nfma = 0;

 task.flags = 0;
 ipm_init(task.flags);
/*
 IPM_CLEAR_TASKDATA(task);
 task.mpi_rank = 0;
 task.mpi_size = 1;
 task.hpm_eventset = 0;
*/
 task.flags |= IPM_HPM_ACTIVE;

 while(--argc && argv++) {
  if(!strcmp("-v",*argv)) {
    task.flags |= VERBOSE;
  } else if(!strcmp("-x",*argv)) {
    task.hpm_eventset = -1;
    task.flags &= ~IPM_HPM_ACTIVE;
  } else if(!strcmp("-r",*argv)) {
    three_reg = 1;
  } else if(!strcmp("-s",*argv)) {
    --argc; argv++;
    task.hpm_eventset = (int)atol(*argv);
  } else if(!strcmp("-n",*argv)) {
    --argc; argv++;
    nflop = atol(*argv);
/*    printf("nflop = 2 * %ld\n", nflop); */
  } else if(!strcmp("-fma",*argv)) {
    --argc; argv++;
    nfma = atol(*argv);
  }
 }

 ipm_hpm_start();

 if(0) {
  printf("IPM: %d hpm_test eventset=%d events :", task.mpi_rank, task.hpm_eventset);
  for(i=0;i<MAXSIZE_HPMCOUNTERS;i++) {
    ii = ipm_hpm_eorder[task.hpm_eventset][i];
    printf("%s ", ipm_hpm_ename[task.hpm_eventset][ii]);
  }
  printf("\n");

  for(ireg=0;ireg<MAXSIZE_REGION;ireg++) {
    printf("IPM: %d hpm_test init region(%d) %s count",
        task.mpi_rank,ireg, task.region_label[ireg]);
   for(i=0;i<MAXSIZE_HPMCOUNTERS;i++) {
    ii = ipm_hpm_eorder[task.hpm_eventset][i];
	printf(" %lld", task.hpm_count[ireg][task.hpm_eventset][ii]);
   }
   printf("\n");
  }
 }

 if(!three_reg) {
  ipm_region(1,"ipm_noregion");
  ipm_region(-1,"ipm_noregion");

  do_flops(nflop);
  do_fmas(nfma);

  ipm_region(-1,"ipm_noregion");
 } else {

  ipm_region(1,"ipm_noregion");
  do_flops(nflop);
  ipm_region(-1,"ipm_noregion");

  ipm_region(1,"a");
  do_flops(nflop*2);
  ipm_region(-1,"a");

  ipm_region(1,"b");
  do_flops(nflop*3);
  ipm_region(-1,"b");

 }

 ipm_hpm_stop();

 IPM_PRINT_TASKDATA(task);

 return 0;
}
Esempio n. 13
0
int
main( int argc, char **argv )
{
	int num_tests=1;
	int num_events=1;
	int retval;
	int cpu_num = 1;
	int EventSet1 = PAPI_NULL;
	long long **values;
	char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_CYC";
	PAPI_option_t opts;

	// user can provide cpu number on which to count events as arg 1
	if (argc > 1) {
		retval = atoi(argv[1]);
		if (retval >= 0) {
			cpu_num = retval;
		}
	}

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

	retval = PAPI_create_eventset(&EventSet1);
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

	// Force event set to be associated with component 0 (perf_events component provides all core events)
	retval = PAPI_assign_eventset_component( EventSet1, 0 );
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );

	// Attach this event set to cpu 1
	opts.cpu.eventset = EventSet1;
	opts.cpu.cpu_num = cpu_num;

	retval = PAPI_set_opt( PAPI_CPU_ATTACH, &opts );
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval );

	retval = PAPI_add_named_event(EventSet1, event_name);
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_add_named_event", retval );
	
	// get space for counter values (this needs to do this call because it malloc's space that test_pass and friends free)
	values = allocate_test_space( num_tests, num_events);
	
	retval = PAPI_start( EventSet1 );
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
	
	// do some work
	do_flops(NUM_FLOPS);
	
	retval = PAPI_stop( EventSet1, values[0] );
	if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
	
	printf ("Event: %s: %8lld on Cpu: %d\n", event_name, values[0][0], cpu_num);
	
	PAPI_shutdown( );
	
	test_pass( __FILE__, values, 1 );
	return PAPI_OK;
}
Esempio n. 14
0
int main(int argc, char **argv)
{
   int retval, num_tests = 2, eventcnt, events[2], i, tmp;
   int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL;
   int PAPI_event;
   long_long values1[2], values2[2];
   long_long elapsed_cyc;
   char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];


   retval = PAPI_library_init(PAPI_VER_CURRENT);

      retval = PAPI_set_debug(PAPI_VERB_ECONT);

   /* query and set up the right instruction to monitor */
   if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK)
      PAPI_event = PAPI_FP_OPS;
   else
      PAPI_event = PAPI_TOT_INS;

   retval = PAPI_event_code_to_name(PAPI_event, event_name);
   sprintf(add_event_str, "PAPI_add_event[%s]", event_name);

   retval = PAPI_create_eventset(&EventSet1);

   /* Add the events */

   retval = PAPI_add_event(EventSet1, PAPI_event);

   retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);

   /* Add them reversed to EventSet2 */

   retval = PAPI_create_eventset(&EventSet2);

   eventcnt = 2;
   retval = PAPI_list_events(EventSet1, events, &eventcnt);

   for (i = eventcnt - 1; i >= 0; i--) {
      retval = PAPI_event_code_to_name(events[i], event_name);

      retval = PAPI_add_event(EventSet2, events[i]);
   }

   elapsed_cyc = PAPI_get_real_cyc();

   retval = PAPI_start(EventSet1);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet1, values1);

   retval = PAPI_start(EventSet2);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet2, values2);


   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   retval = PAPI_cleanup_eventset(EventSet1);   /* JT */

   retval = PAPI_destroy_eventset(&EventSet1);

   retval = PAPI_cleanup_eventset(EventSet2);   /* JT */

   retval = PAPI_destroy_eventset(&EventSet2);

      printf("Test case 0: start, stop.\n");
      printf("-----------------------------------------------\n");
      tmp = PAPI_get_opt(PAPI_DEFDOM, NULL);
      tmp = PAPI_get_opt(PAPI_DEFGRN, NULL);
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf
          ("-------------------------------------------------------------------------\n");

      printf("Test type    : \t           1\t           2\n");

      printf("%ld %ld\n", values1[0], values2[1]);
      printf("%d %d\n", "PAPI_TOT_INS : \t", values1[1], values2[0]);
      printf("%ld\n", "Real cycles  : \t", elapsed_cyc);

      printf
          ("-------------------------------------------------------------------------\n");

      printf("Verification: none\n");
   exit(1);
}
Esempio n. 15
0
int main(int argc, char *argv[]) {


	float rtime1, rtime2, ptime1, ptime2, mflops;
	long long flpops;

	unsigned long int tid;
	int num_hwcntrs = 0;
	int fip = 0, retval;
	float real_time, proc_time;
	long long flpins;

	int i;
	unsigned int EventSet = PAPI_NULL; 
    int count = 0, err_count = 0;


    PAPI_event_info_t info;

    long long ( values2[2] )[2];
    long long min, max;
    int PAPI_event, mythreshold = THRESHOLD;
    char event_name1[PAPI_MAX_STR_LEN];
    const PAPI_hw_info_t *hw_info = NULL;
    int num_events, mask;
    int num_flops = NUM_FLOPS;
    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 );

  retval = PAPI_create_eventset( &EventSet );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* Get hardware info */
  hw_info = PAPI_get_hardware_info(  );
  if ( hw_info == NULL )
      test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

  EventSet = 	add_two_nonderived_events( &num_events, &PAPI_event, &mask );

  printf("Using %#x for the overflow event\n",PAPI_event);

  if ( PAPI_event == PAPI_FP_INS ) {
      mythreshold = THRESHOLD;
  }
  else {
		#if defined(linux)
      mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
		#else
      mythreshold = THRESHOLD * 2;
		#endif
  }

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

  do_flops( NUM_FLOPS );

	/* stop the calibration run */
  retval = PAPI_stop( EventSet, values2[0] );
  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 );
  }

  do_flops( num_flops );

	/* stop overflow run */
  retval = PAPI_stop( EventSet, values2[1] );
  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 );

  if ( !TESTS_QUIET ) {
      if ( ( retval =
         PAPI_event_code_to_name( PAPI_event, event_name1 ) ) != PAPI_OK )
         test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

     printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
     printf( "---------------------------------------------------------------\n" );
     printf( "Threshold for overflow is: %d\n", mythreshold );
     printf( "Using %d iterations\n", num_flops );
     printf( "-----------------------------------------------\n" );

     printf( "Test type    : %16d%16d\n", 1, 2 );
     printf( OUT_FMT, event_name1, ( values2[0] )[1], ( values2[1] )[1] );
     printf( OUT_FMT, "PAPI_TOT_CYC", ( values2[0] )[0], ( values2[1] )[0] );
     printf( "Overflows    : %16s%16d\n", "", total );
     printf( "-----------------------------------------------\n" );
 }

 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 ( !TESTS_QUIET ) {
  printf( "Verification:\n" );
#if defined(linux) || defined(__ia64__) || defined(_POWER4)
  num_flops *= 2;
#endif
  if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) {
     printf( "Row 1 approximately equals %d %d\n", num_flops, num_flops );
 }
 printf( "Column 1 approximately equals column 2\n" );
 printf( "Row 3 approximately equals %u +- %u %%\n",( unsigned ) ( ( values2[0] )[1] / ( long long ) mythreshold ),( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
}

min =
( long long ) ( ( ( double ) values2[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
  ( double ) mythreshold );
max =
( long long ) ( ( ( double ) values2[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
  ( double ) mythreshold );
printf( "Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) \n", total,
  max, total, min );
if ( total > max || total < min )
  test_fail( __FILE__, __LINE__, "Overflows", 1 );



printf("Initial thread id is: %lu\n",tid);

	/* Initialize the PAPI library and get the number of counters available */

if ((num_hwcntrs = PAPI_num_counters()) <= 0)  
  handle_error(1);



  /*  The installation supports PAPI, but has no counters */
if ((num_hwcntrs = PAPI_num_counters()) == 0 )
    fprintf(stderr,"Info:: This machine does not provide hardware counters.");

printf("This system has %d available counters.\n", num_hwcntrs);

if (num_hwcntrs > 2)
  num_hwcntrs = 2;

	 /* Start counting events */




if (PAPI_start_counters(Events, num_hwcntrs) != PAPI_OK)
  handle_error(1);

if (argc != 8) {
  printf("\nError :: Ejecutar como : a.out archivo_BD Num_elem archivo_queries Num_queries N_THREADS numero_K Dimension_objetos\n");
  return 0;
}
TOPK = atoi(argv[6]);
DIM = atoi(argv[7]);
double **DB;
	double **Consultas; //Cola de consultas
	int N_QUERIES, N_DB;
	char str_f[256];
	double dato[DIM];
	int j;
	FILE *f_dist, *fquery;
	Elem *heap, e_temp,*answer;
	int *acum, N_THREADS;


	//N_THREADS es el nro. de threads con el que se lanzará la región paralela
	N_THREADS = atoi(argv[5]);
	//N_QUERIES es el nro. de consultas
	N_QUERIES = atoi(argv[4]);
	N_DB = atoi(argv[2]);

	printf("\nN_QUERIES = %d\nN_THREADS = %d\n", N_QUERIES, N_THREADS);
	fflush(stdout);

	acum = (int *) malloc(sizeof (int)*N_THREADS);
	for (i = 0; i < N_THREADS; i++)
		acum[i] = 0;

	sprintf(str_f, "%s", argv[1]);
	printf("\nAbriendo %s... ", argv[1]);
	fflush(stdout);
	f_dist = fopen(str_f, "r");
	printf("OK\n");
	fflush(stdout);


	Consultas = (double **) malloc(sizeof (double *)*N_QUERIES);
	for (i = 0; i < N_QUERIES; i++)
		Consultas[i] = (double *) malloc(sizeof (double)*DIM);

	DB = (double **) malloc(sizeof (double *)*N_DB);
	for (i = 0; i < N_DB; i++)
		DB[i] = (double *) malloc(sizeof (double)*DIM);

	answer = (Elem *)malloc(sizeof(Elem)*N_QUERIES*TOPK);

	printf("\nCargando DB... ");
	fflush(stdout);
	for (i = 0; i < N_DB; i++) {
		//Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las ","
		//if (leedato_cophir(dato, f_dist) == ERROR || feof(f_dist))
		if (leedato(dato, f_dist) == ERROR || feof(f_dist)) {
			printf("\n\nERROR :: N_DB mal establecido\n\n");
			fflush(stdout);
			fclose(f_dist);
			break;
		}
		copiavalor(DB[i], dato);
	}
	fclose(f_dist);
	printf("OK\n");
	fflush(stdout);

	if ((fquery = fopen(argv[3], "r")) == NULL)
		printf("Error al abrir para lectura el archivo de qeuries: %s\n", argv[3]);
	else
		printf("Abriendo  para lectura %s\n", argv[3]);
	printf("\nCargando Consultas... ");
	fflush(stdout);
	for (i = 0; i < N_QUERIES; i++) {
		//Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las ","
		//if (leedato_cophir(dato, fquery) == ERROR || feof(fquery))
		if (leedato(dato, fquery) == ERROR || feof(fquery)) {
			printf("\n\nERROR :: N_QUERIES mal establecido, Menos queries que las indicadas\n\n");
			fflush(stdout);
			fclose(fquery);
			break;
		}
		copiavalor(Consultas[i], dato);
	}
	fclose(fquery);
	printf("OK\n");
	fflush(stdout);

	PAPI_start_counters((int*) Events, NUM_EVENTS);
	omp_set_num_threads(N_THREADS);

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	retval =
	PAPI_thread_init( ( unsigned
		long ( * )( void ) ) ( omp_get_thread_num ) );
	if ( retval != PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}

#pragma omp parallel shared(Consultas, DB, N_QUERIES, N_DB, N_THREADS, acum, DIM)
	{
		float real_time;
		struct timeval t1, t2;
		int i, j;
		Elem *heap, e_temp;
		double d;
		int n_elem = 0;
		int trid = omp_get_thread_num(); //ID del thread
		int procs = omp_get_num_threads(); //Nro. total de threads
		double suma = 0;

		suma = 0;
		heap = (Elem *) malloc(sizeof (Elem) * TOPK);

#pragma omp barrier

#pragma omp master
		{
			gettimeofday(&t1, 0);
		}

		//Cada hilo accede a un subconjunto de las consultas. Cada hio accede de manera circular al arreglo de consultas.
        for (i = trid; i < N_QUERIES; i += procs) {
         n_elem = 0;
         for (j = 0; j < N_DB; j++) {

            d = distancia(Consultas[i], DB[j]);
				//Si la distancia del objeto a la consulta es menor que la raíz del heap, entonces se inserta en el heap. La raíz siempre mantiene la mayor de las distancias

            if(n_elem<TOPK){
               e_temp.dist = d;
               e_temp.ind = j;
               inserta2(heap, &e_temp, &n_elem);
           }
           if (n_elem==TOPK){
               if (d < topH(heap, &n_elem)) {
                  e_temp.dist = d;
                  e_temp.ind = j;
					//Si el heap no está lleno, se inserta el elemento
                  if (n_elem < TOPK)
                     inserta2(heap, &e_temp, &n_elem);
						//Si el heap está lleno, se inserta el elemento nuevo y se saca el que era antes de mayor de distancia. popush2() hace las operaciones de sacar el elemento mayor e insertar el nuevo.
                 else
                     popush2(heap, &n_elem, &e_temp);
             }}
         }

			//En este punto del código se tienen los K elemntos más cercanos a la consulta en 'heap'. Se pueden extraer con extraer2()
         for (j = 0; j < TOPK ; j++) {
           extrae2(heap, &n_elem, &e_temp);
           answer[i*TOPK+j].ind = e_temp.ind;
           answer[i*TOPK+j].dist = e_temp.dist;
       }
			//Realizamos una operación con los resultados para que el compilador no evite hacer instrucciones que considere que el usuario no utiliza. Simplemente cada hilo suma las distancias de los elementos mas cercanos a la consulta 
   }
   Thread( 1000000 * ( tid + 1 ) );



   fflush(stdout);

#pragma omp barrier

#pragma omp master
   {   

    if ( fip > 0 ) {
		/* Setup PAPI library and begin collecting data from the counters */
       if ( fip == 1 ) {
          if ( ( retval =
             PAPI_flips( &real_time, &proc_time, &flpins,
                &mflops ) ) < PAPI_OK )
             test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
     } else {
      if ( ( retval =
         PAPI_flops( &real_time, &proc_time, &flpins,
            &mflops ) ) < PAPI_OK )
         test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
 }

 gettimeofday(&t2, 0);
 real_time = (t2.tv_sec - t1.tv_sec) + (float) (t2.tv_usec - t1.tv_usec) / 1000000;

 Salida_Multihilo = fopen("Salida_Multihilo.txt", "w");
 for (i = 0; i < N_QUERIES; ++i){
  fprintf(Salida_Multihilo, "Consulta id:: %d\n",i);
  for (j = 0; j < TOPK; ++j){
     fprintf(Salida_Multihilo,"ind = %d :: dist = %f\n",answer[(i*TOPK)+j].ind,answer[(i*TOPK)+j].dist);
 }
 fprintf(Salida_Multihilo, "---------------------------------\n");
}
fclose(Salida_Multihilo);

printf("\n\nK = %d", TOPK);
printf("\nReal Time = %f segundos.\n", real_time);
fflush(stdout);


if ( fip == 1 ) {
  if ( ( retval =
     PAPI_flips( &real_time, &proc_time, &flpins,
        &mflops ) ) < PAPI_OK )
     test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
} else {
  if ( ( retval =
     PAPI_flops( &real_time, &proc_time, &flpins,
        &mflops ) ) < PAPI_OK )
     test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
}

if ( !TESTS_QUIET ) {
  if ( fip == 1 ) {
     printf( "Real_time: %f Proc_time: %f Total flpins: ", real_time,
        proc_time );
 } else {
     printf( "Real_time: %f Proc_time: %f Total flpops: ", real_time,
        proc_time );
 }
 printf( LLDFMT, flpins );
 printf( " MFLOPS: %f\n", mflops );
}
}

}
free(heap);



	}//end pragma omp parallel

	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 );
	}

	const PAPI_hw_info_t *hwinfo = NULL;
	const PAPI_mh_tlb_info_t *mhinfo = NULL;
	const  PAPI_mh_cache_info_t *mhcacheinfo = NULL;
	const PAPI_mh_level_t *mhlevel = NULL;


	if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
		exit(1);
	if ((hwinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);	
	if ((mhinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);
	if ((mhcacheinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);
	if ((mhlevel = PAPI_get_hardware_info()) == NULL)
		exit(1);

	printf("\n\nA continuación información actual del equipo\n\n");

	printf("MH Type %d - Num entries %d  - Associativity %d \n",mhinfo->type, mhinfo->num_entries, mhinfo->associativity);
	printf("Cache MH type %d size %d line size %d num_lines %d Associativity %d\n\n",mhcacheinfo->type, mhcacheinfo->size,mhcacheinfo->line_size, mhcacheinfo->num_lines, mhcacheinfo->associativity);



    retval=papi_print_header("Available PAPI preset and user defined events plus hardware information.\n",&hwinfo );


    printf("Total hardware flops = %lld\n",(float)values[1]);
    printf("L2 data cache misses is %lld\n", values[0]);






    retval = PAPI_stop_counters(values, NUM_EVENTS);
    return 0;
}
Esempio n. 16
0
int
main( int argc, char **argv )
{
    int EventSet = PAPI_NULL;
    long long ( values[2] )[2];
    long long min, max;
    int num_flops, retval;
    int PAPI_event, mythreshold;
    char event_name[PAPI_MAX_STR_LEN];
    const PAPI_hw_info_t *hw_info = NULL;

    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 );

#if defined(POWER3) || defined(__sparc__)
    PAPI_event = PAPI_TOT_INS;
#else
    /* query and set up the right instruction to monitor */
    PAPI_event = find_nonderived_event( );
#endif

    if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
        mythreshold = THRESHOLD;
    else
#if defined(linux)
        mythreshold = ( int ) hw_info->cpu_max_mhz * 10000 * 2;
#else
        mythreshold = THRESHOLD * 2;
#endif

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

    retval = PAPI_add_event( EventSet, PAPI_event );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

    retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

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

    do_flops( NUM_FLOPS );

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

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

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

    do_flops( NUM_FLOPS );

    retval = PAPI_stop( EventSet, values[1] );
    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 );

    num_flops = NUM_FLOPS;
#if defined(linux) || defined(__ia64__) || defined(_POWER4)
    num_flops *= 2;
#endif

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

        printf
        ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
        printf
        ( "---------------------------------------------------------------\n" );
        printf( "Threshold for overflow is: %d\n", mythreshold );
        printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
        printf( "-----------------------------------------------\n" );

        printf( "Test type    : %16d%16d\n", 1, 2 );
        printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
        printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
        printf( "Overflows    : %16s%16d\n", "", total );
        printf( "-----------------------------------------------\n" );

        printf( "Verification:\n" );
        /*
        	if (PAPI_event == PAPI_FP_INS)
        		printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
        */
        /* Note that the second run prints output on stdout. On some systems
         * this is costly. PAPI_TOT_INS or PAPI_TOT_CYC are likely to be _very_
         * different between the two runs.
         * printf("Column 1 approximately equals column 2\n");
         */
        printf( "Row 3 approximately equals %u +- %u %%\n",
                ( unsigned ) ( ( values[0] )[0] / ( long long ) mythreshold ),
                ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
    }
    /*
      min = (long long)((values[0])[0]*(1.0-TOLERANCE));
      max = (long long)((values[0])[0]*(1.0+TOLERANCE));
      if ( (values[1])[0] > max || (values[1])[0] < min )
      	test_fail(__FILE__, __LINE__, event_name, 1);
    */

    min =
        ( long long ) ( ( ( double ) values[0][0] * ( 1.0 - OVR_TOLERANCE ) ) /
                        ( double ) mythreshold );
    max =
        ( long long ) ( ( ( double ) values[0][0] * ( 1.0 + OVR_TOLERANCE ) ) /
                        ( double ) mythreshold );
    if ( total > max || total < min )
        test_fail( __FILE__, __LINE__, "Overflows", 1 );

    test_pass( __FILE__, NULL, 0 );
    exit( 1 );
}
int main( int argc, char **argv ) {


   char *instructions_event=NULL;
   char event_name[BUFSIZ];

   char user_event[BUFSIZ];
   char kernel_event[BUFSIZ];
   char user_kernel_event[BUFSIZ];


   int retval;

   /* Default Domain */
   int EventSet_default = PAPI_NULL;
   int EventSet_default_user = PAPI_NULL;
   int EventSet_default_kernel = PAPI_NULL;
   int EventSet_default_user_kernel = PAPI_NULL;
   long long default_values[1];
   long long default_user_values[1];
   long long default_kernel_values[1];
   long long default_user_kernel_values[1];

   /* User Domain */
   int EventSet_user = PAPI_NULL;
   int EventSet_user_user = PAPI_NULL;
   int EventSet_user_kernel = PAPI_NULL;
   int EventSet_user_user_kernel = PAPI_NULL;
   long long user_values[1];
   long long user_user_values[1];
   long long user_kernel_values[1];
   long long user_user_kernel_values[1];

   /* Kernel Domain */
   int EventSet_kernel = PAPI_NULL;
   int EventSet_kernel_user = PAPI_NULL;
   int EventSet_kernel_kernel = PAPI_NULL;
   int EventSet_kernel_user_kernel = PAPI_NULL;
   long long kernel_values[1];
   long long kernel_user_values[1];
   long long kernel_kernel_values[1];
   long long kernel_user_kernel_values[1];

   /* All Domain */
   int EventSet_all = PAPI_NULL;
   int EventSet_all_user = PAPI_NULL;
   int EventSet_all_kernel = PAPI_NULL;
   int EventSet_all_user_kernel = PAPI_NULL;
   long long all_values[1];
   long long all_user_values[1];
   long long all_kernel_values[1];
   long long all_user_kernel_values[1];

   /* Two Events */
   int EventSet_two = PAPI_NULL;
   long long two_values[2];

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

   /* Init the PAPI library */
   retval = PAPI_library_init( PAPI_VER_CURRENT );
   if ( retval != PAPI_VER_CURRENT ) {
      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
   }


   /* Get a relevant event name */
   instructions_event=get_instructions_event(event_name, BUFSIZ);
   if (instructions_event==NULL) {
      test_skip( __FILE__, __LINE__,
                "No instructions event definition for this arch", 
		 PAPI_ENOSUPP );
   }

   sprintf(user_event,"%s:u=1",instructions_event);
   sprintf(kernel_event,"%s:k=1",instructions_event);
   sprintf(user_kernel_event,"%s:u=1:k=1",instructions_event);

   /*********************************/
   /* Two Events                    */
   /*********************************/

   if (!TESTS_QUIET) {
      printf("\tTwo Events in same EventSet\n");
   }

   retval = PAPI_create_eventset(&EventSet_two);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_two, user_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding user event ",retval);
   }
   retval = PAPI_add_named_event(EventSet_two, kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_two );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_two, two_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld, %s count = %lld\n",
	    user_event,two_values[0],
	    kernel_event,two_values[1]);
   }


   /*********************************/
   /* Default Domain, Default Event */
   /*********************************/

   if (!TESTS_QUIET) {
      printf("\tDefault Domain\n");
   }

   retval = PAPI_create_eventset(&EventSet_default);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_default, instructions_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",instructions_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_default );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_default, default_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",instructions_event,default_values[0]);
   }


   /*********************************/
   /* Default Domain, User Event */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_default_user);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_default_user, user_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_default_user );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_default_user, default_user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_event,default_user_values[0]);
   }

   /*********************************/
   /* Default Domain, Kernel Event */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_default_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_default_kernel, kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_default_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_default_kernel, default_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",kernel_event,default_kernel_values[0]);
   }

   /*****************************************/
   /* Default Domain, user and Kernel Event */
   /*****************************************/


   retval = PAPI_create_eventset(&EventSet_default_user_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_default_user_kernel, user_kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_default_user_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_default_user_kernel, default_user_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_kernel_event,default_user_kernel_values[0]);
   }

   /*********************************/
   /* User Domain, Default Event    */
   /*********************************/

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_USER Domain\n");
   }

   retval=PAPI_set_cmp_domain(PAPI_DOM_USER, 0);

   retval = PAPI_create_eventset(&EventSet_user);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_user, instructions_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",instructions_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_user );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_user, user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",instructions_event,user_values[0]);
   }


   /*********************************/
   /* User Domain, User Event       */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_user_user);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_user_user, user_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_user_user );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_user_user, user_user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_event,user_user_values[0]);
   }

   /*********************************/
   /* User Domain, Kernel Event     */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_user_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_user_kernel, kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_user_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_user_kernel, user_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",kernel_event,user_kernel_values[0]);
   }

   /*****************************************/
   /* User Domain, user and Kernel Event    */
   /*****************************************/

   retval = PAPI_create_eventset(&EventSet_user_user_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_user_user_kernel, user_kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_user_user_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_user_user_kernel, user_user_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_kernel_event,user_user_kernel_values[0]);
   }

   /*********************************/
   /* Kernel Domain, Default Event  */
   /*********************************/

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_KERNEL Domain\n");
   }

   retval=PAPI_set_cmp_domain(PAPI_DOM_KERNEL, 0);

   retval = PAPI_create_eventset(&EventSet_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_kernel, instructions_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",instructions_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_kernel, kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",instructions_event,kernel_values[0]);
   }


   /*********************************/
   /* Kernel Domain, User Event     */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_kernel_user);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_kernel_user, user_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_kernel_user );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_kernel_user, kernel_user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_event,kernel_user_values[0]);
   }

   /*********************************/
   /* Kernel Domain, Kernel Event   */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_kernel_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_kernel_kernel, kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_kernel_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_kernel_kernel, kernel_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",kernel_event,kernel_kernel_values[0]);
   }

   /*****************************************/
   /* Kernel Domain, user and Kernel Event  */
   /*****************************************/

   retval = PAPI_create_eventset(&EventSet_kernel_user_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_kernel_user_kernel, user_kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_kernel_user_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_kernel_user_kernel, kernel_user_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_kernel_event,kernel_user_kernel_values[0]);
   }

   /*********************************/
   /* All Domain, Default Event  */
   /*********************************/

   if (!TESTS_QUIET) {
      printf("\tPAPI_DOM_ALL Domain\n");
   }

   retval=PAPI_set_cmp_domain(PAPI_DOM_ALL, 0);

   retval = PAPI_create_eventset(&EventSet_all);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_all, instructions_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",instructions_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_all );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_all, all_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",instructions_event,all_values[0]);
   }


   /*********************************/
   /* All Domain, User Event        */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_all_user);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_all_user, user_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_all_user );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_all_user, all_user_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_event,all_user_values[0]);
   }

   /*********************************/
   /* All Domain, Kernel Event      */
   /*********************************/

   retval = PAPI_create_eventset(&EventSet_all_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_all_kernel, kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_all_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_all_kernel, all_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",kernel_event,all_kernel_values[0]);
   }

   /*****************************************/
   /* All Domain, user and Kernel Event     */
   /*****************************************/

   retval = PAPI_create_eventset(&EventSet_all_user_kernel);
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
   }


   retval = PAPI_add_named_event(EventSet_all_user_kernel, user_kernel_event);
   if (retval != PAPI_OK) {
      if ( !TESTS_QUIET ) {
	 fprintf(stderr,"Error trying to add %s\n",user_kernel_event);
      }
      test_fail(__FILE__, __LINE__, "adding instructions event ",retval);
   }

   retval = PAPI_start( EventSet_all_user_kernel );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
   }

   do_flops( NUM_FLOPS );

   retval = PAPI_stop( EventSet_all_user_kernel, all_user_kernel_values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

   if ( !TESTS_QUIET ) {
     printf("\t\t%s count = %lld\n",user_kernel_event,all_user_kernel_values[0]);
   }

   /**************/
   /* Validation */
   /**************/

   //TODO

   test_pass( __FILE__, NULL, 0 );

   return 0;
}
Esempio n. 18
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long ( values[3] )[2];
	int retval;
	int PAPI_event, k, idx[4];
	char event_name[3][PAPI_MAX_STR_LEN];
	int num_events1;
	int threshold = THRESHOLD;

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

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

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* decide which of PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS to add,
	   depending on the availability and derived status of the event on
	   this platform */
	if ( ( PAPI_event = find_nonderived_event(  ) ) == 0 )
		test_fail( __FILE__, __LINE__, "no PAPI_event", 0 );

	if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

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

	do_flops( NUM_FLOPS );

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

	/* Set both overflows after adding both events (batch) */
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_event, threshold, 0,
						  handler_batch ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
						  handler_batch ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

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

	do_flops( NUM_FLOPS );

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

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 1, &idx[0], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 2, &idx[1], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	/* Add each event and set its overflow (interleaved) */
	if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_event, threshold, 0,
						  handler_interleaf ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
						  handler_interleaf ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

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

	do_flops( NUM_FLOPS );

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

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 1, &idx[2], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 2, &idx[3], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

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

	if ( ( retval =
		   PAPI_event_code_to_name( PAPI_TOT_CYC, event_name[1] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	strcpy( event_name[2], "Unknown" );

	printf
		( "Test case: Overflow dispatch of both events in set with 2 events.\n" );
	printf
		( "---------------------------------------------------------------\n" );
	printf( "Threshold for overflow is: %d\n", threshold );
	printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
	printf( "-----------------------------------------------\n" );

	printf( "Test type    : %18s%18s%18s\n", "1 (no overflow)", "2 (batch)",
			"3 (interleaf)" );
	printf( OUT_FMT, event_name[0], ( values[0] )[0], ( values[1] )[0],
			( values[2] )[0] );
	printf( OUT_FMT, event_name[1], ( values[0] )[1], ( values[1] )[1],
			( values[2] )[1] );
	printf( "\n" );

	printf( "Predicted overflows at event %-12s : %6d\n", event_name[0],
			( int ) ( ( values[0] )[0] / threshold ) );
	printf( "Predicted overflows at event %-12s : %6d\n", event_name[1],
			( int ) ( ( values[0] )[1] / threshold ) );

	printf( "\nBatch overflows (add, add, over, over):\n" );
	for ( k = 0; k < 2; k++ ) {
		if ( overflow_counts[0][k].mask ) {
			printf( VEC_FMT, ( long long ) overflow_counts[0][k].mask,
					event_name[idx[k]], overflow_counts[0][k].count );
		}
	}

	printf( "\nInterleaved overflows (add, over, add, over):\n" );
	for ( k = 0; k < 2; k++ ) {
		if ( overflow_counts[1][k].mask )
			printf( VEC_FMT, 
				( long long ) overflow_counts[1][k].mask,
				event_name[idx[k + 2]], 
				overflow_counts[1][k].count );
	}

	printf( "\nCases 2+3 Unknown overflows: %d\n", total_unknown );
	printf( "-----------------------------------------------\n" );

	if ( overflow_counts[0][0].count == 0 || overflow_counts[0][1].count == 0 )
		test_fail( __FILE__, __LINE__, "a batch counter had no overflows", 1 );

	if ( overflow_counts[1][0].count == 0 || overflow_counts[1][1].count == 0 )
		test_fail( __FILE__, __LINE__,
				   "an interleaved counter had no overflows", 1 );

	if ( total_unknown > 0 )
		test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Esempio n. 19
0
int
main( int argc, char **argv )
{
	int retval;
	int num_events;
	long long *values;
	char *success;
	PAPI_event_info_t info;
	int EventSet = PAPI_NULL;
	int i, j, data_type, event;
	int u_format = 0;
	int hex_format = 0;

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

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

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* Automatically pass if no events, for run_tests.sh */
	if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) {
		test_pass( __FILE__, NULL, 0 );
	}

	values =
		( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc );
	success = ( char * ) malloc( ( size_t ) argc );

	if ( success == NULL || values == NULL )
		test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS );

	for ( num_events = 0, i = 1; i < argc; i++ ) {
		if ( !strcmp( argv[i], "-h" ) ) {
			print_help( argv );
			exit( 1 );
		} else if ( !strcmp( argv[i], "-u" ) ) {
			u_format = 1;
		} else if ( !strcmp( argv[i], "-x" ) ) {
			hex_format = 1;
		} else {
			if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) {
				printf( "Failed adding: %s\nbecause: %s\n", argv[i], 
					PAPI_strerror(retval));
			} else {
				success[num_events++] = i;
				printf( "Successfully added: %s\n", argv[i] );
			}
		}
	}

	/* Automatically pass if no events, for run_tests.sh */
	if ( num_events == 0 ) {
		test_pass( __FILE__, NULL, 0 );
	}


	printf( "\n" );

	do_flops( 1 );
	do_flush(  );

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
	   test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
	}

	do_flops( NUM_FLOPS );
	do_misses( 1, L1_MISS_BUFFER_SIZE_INTS );

	if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );

	for ( j = 0; j < num_events; j++ ) {
		i = success[j];
		if (! (u_format || hex_format) ) {
			retval = PAPI_event_name_to_code( argv[i], &event );
			if (retval == PAPI_OK) {
				retval = PAPI_get_event_info(event, &info);
				if (retval == PAPI_OK) data_type = info.data_type;
				else data_type = PAPI_DATATYPE_INT64;
			}
			switch (data_type) {
			  case PAPI_DATATYPE_UINT64:
				printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] );
				break;
			  case PAPI_DATATYPE_FP64:
				printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) );
				j++;
				break;
			  case PAPI_DATATYPE_BIT64:
				printf( "%s : \t0x%llX", argv[i], values[j] );
				break;
			  case PAPI_DATATYPE_INT64:
			  default:
				printf( "%s : \t%lld", argv[i], values[j] );
				break;
			}
			if (retval == PAPI_OK)  printf( " %s", info.units );
			printf( "\n" );
		}
		if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] );
		if (hex_format) printf( "%s : \t0x%llX\n", argv[i], values[j] );
	}

	printf( "\n----------------------------------\n" );
	printf
		( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Esempio n. 20
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long *values;
	int num_flops, retval, i, j;
	int *events, mythreshold;
	char **names;
	const PAPI_hw_info_t *hw_info = NULL;
	int num_events, *ovt;
	char name[PAPI_MAX_STR_LEN];
	const PAPI_component_info_t *comp_info = NULL;
	int using_perfmon = 0;
	int using_aix = 0;
	int numcmp, cid;

	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", retval );
	}

        numcmp = PAPI_num_components(  );

	for ( cid = 0; cid < numcmp; cid++ ) {

	    comp_info = PAPI_get_component_info( cid );
	    if ( comp_info == NULL ) {
	       test_fail( __FILE__, __LINE__, "PAPI_get_component_info", retval );
	    }

	    if ( strstr( comp_info->name, "perfmon.c" ) ) {
	       using_perfmon = 1;
	    }

	    if ( strstr( comp_info->name, "aix.c" ) ) {
	       using_aix = 1;
	    }
	}

	/* add PAPI_TOT_CYC and one of the events in */
	/* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS,    */
        /* depending on the availability of the event*/
	/* on the platform */
	EventSet = enum_add_native_events( &num_events, &events, 1 , 1);

	if (!TESTS_QUIET) printf("Trying %d events\n",num_events);

	names = ( char ** ) calloc( ( unsigned int ) num_events, 
				    sizeof ( char * ) );

	for ( i = 0; i < num_events; i++ ) {
	   if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval);
	   }
	   else {
	      names[i] = strdup( name );
	      if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]);
	   }
	}

	values = ( long long * )
		calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ),
				sizeof ( long long ) );
	ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) );

#if defined(linux)
	{
		char *tmp = getenv( "THRESHOLD" );
		if ( tmp ) {
			mythreshold = atoi( tmp );
		}
		else if (hw_info->mhz!=0) {
		   mythreshold = ( int ) hw_info->mhz * 20000;
		  if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold);

		}
		else {
		  if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD);
		   mythreshold = THRESHOLD;
		}
	}
#else
	mythreshold = THRESHOLD;
#endif

	num_flops = NUM_FLOPS * 2;

	   /* initial test to make sure they all work */
	if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n");

       	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	do_flops( num_flops );

	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	}

	/* done with initial test */

	/* keep adding events? */
	for ( i = 0; i < num_events; i++ ) {

	      /* Enable overflow */
	   if (!TESTS_QUIET) printf("Testing with overflow set on %s\n",
				   names[i]);

	   retval = PAPI_overflow( EventSet, events[i], 
					mythreshold, 0, handler );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	   }

       	   retval = PAPI_start( EventSet );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	   }
		
	   do_flops( num_flops );

	   retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	   }

	      /* Disable overflow */
	   retval = PAPI_overflow( EventSet, events[i], 0, 0, handler );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	   }
	   ovt[i] = total;
	   total = 0;
	}

	if ( !TESTS_QUIET ) {

	   printf("\nResults in Matrix-view:\n");
	   printf( "Test Overflow on %d counters with %d events.\n", 
		   num_events,num_events );
	   printf( "-----------------------------------------------\n" );
	   printf( "Threshold for overflow is: %d\n", mythreshold );
	   printf( "Using %d iterations of c += a*b\n", num_flops );
	   printf( "-----------------------------------------------\n" );

	   printf( "Test type                   : " );
	   for ( i = 0; i < num_events + 1; i++ ) {
	       printf( "%16d", i );
	   }
	   printf( "\n" );
	   for ( j = 0; j < num_events; j++ ) {
	       printf( "%-27s : ", names[j] );
	       for ( i = 0; i < num_events + 1; i++ ) {
		   printf( "%16lld", *( values + j + num_events * i ) );
	       }
	       printf( "\n" );
	   }
	   printf( "Overflows                   : %16s", "" );
	   for ( i = 0; i < num_events; i++ ) {
	       printf( "%16d", ovt[i] );
	   }
	   printf( "\n" );
	   printf( "-----------------------------------------------\n" );
	}

	/* validation */

	if ( !TESTS_QUIET ) {
	   printf("\nResults broken out for validation\n");
	}

	if (!TESTS_QUIET) {

	for ( j = 0; j < num_events+1; j++ ) {
	  if (j==0) {
             printf("Test results, no overflow:\n\t");
	  }
	  else {
	    printf("Overflow of event %d, %s\n\t",j-1,names[j-1]);
	  }
	  for(i=0; i < num_events; i++) {
	    if (i==j-1) {
	      printf("*%lld* ",values[(num_events*j)+i]);
	    }
	    else {
	      printf("%lld ",values[(num_events*j)+i]);
	    }
	  }
          printf("\n");
	  if (j!=0) {
	     printf("\tOverflow should be %lld / %d = %lld\n",
		 values[(num_events*j)+(j-1)],
		 mythreshold,
		 values[(num_events*j)+(j-1)]/mythreshold);
	     printf("\tOverflow was %d\n",ovt[j-1]);
	  }
	}
	}

	for ( j = 0; j < num_events; j++ ) {
		//printf("Validation: %lld / %d != %d (%lld)\n",
		//       *( values + j + num_events * (j+1) ) ,
		//       mythreshold,
		//       ovt[j],
		//       *(values+j+num_events*(j+1))/mythreshold);
		if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) {
			char error_string[BUFSIZ];

			if ( using_perfmon )
				test_warn( __FILE__, __LINE__,
						   "perfmon substrate handles overflow differently than perf_events",
						   1 );
			else if ( using_aix )
				test_warn( __FILE__, __LINE__,
						   "AIX (pmapi) substrate handles overflow differently than various other substrates",
						   1 );
			else {
				sprintf( error_string,
						 "Overflow value differs from expected %lld / %d != %d (%lld)",
						 *( values + j + num_events * ( j + 1 ) ), mythreshold,
						 ovt[j],
						 *( values + j +
							num_events * ( j + 1 ) ) / mythreshold );
				test_fail( __FILE__, __LINE__, error_string, 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 );

	free( ovt );
	for ( i = 0; i < num_events; i++ )
		free( names[i] );
	free( names );
	free( events );
	free( values );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main(int argc, char **argv)
{
    int retval, num_tests = 6, tmp;
    long long **values;
    int EventSet=PAPI_NULL;
    const PAPI_hw_info_t *hw_info;

#ifndef PENTIUM4
    test_skip(__FILE__, __LINE__, "This test is intended only for Pentium 4.", 1);
#endif

    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);

    retval = PAPI_create_eventset(&EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

    values = allocate_test_space(num_tests, 2);

    /* First test: just PAPI_LD_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    /* Second test: just PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);

    /* Third test: just PAPI_LST_INS */
    retval = PAPI_add_event(EventSet, PAPI_LST_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LST_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    /* Fourth test: PAPI_LST_INS and PAPI_LD_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    /* Fifth test: PAPI_LST_INS and PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);

    retval = PAPI_remove_event(EventSet, PAPI_LST_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LST_INS", retval);

    /* Sixth test: PAPI_LD_INS and PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

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

    do_flops(NUM_FLOPS/10);

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

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);



    if (!TESTS_QUIET) {
        printf("Pentium 4 Load / Store tests.\n");
        printf("These PAPI events are counted by setting a tag at the front of the pipeline,\n");
        printf("and counting tags at the back of the pipeline. All the tags are the same 'color'\n");
        printf("and can't be distinguished from each other. Therefore, PAPI_LD_INS and PAPI_SR_INS\n");
        printf("cannot be counted with the other two events, or the answer will always == PAPI_LST_INS.\n");
        printf("-------------------------------------------------------------------------------------------\n");
        tmp = PAPI_get_opt(PAPI_DEFDOM, NULL);
        printf("Default domain is: %d (%s)\n", tmp, stringify_all_domains(tmp));
        tmp = PAPI_get_opt(PAPI_DEFGRN, NULL);
        printf("Default granularity is: %d (%s)\n", tmp, stringify_granularity(tmp));
        printf("Using %d iterations of c += a*b\n", NUM_FLOPS/10);
        printf("-------------------------------------------------------------------------------------------\n");

        printf("Test:                1            2            3            4            5            6\n");
        printf("%s %12lld %12s %12s %12lld %12s %12lld\n",
               "PAPI_LD_INS: ", (values[0])[0], "------", "------",
               (values[3])[1], "------", (values[5])[0]);
        printf("%s %12s %12lld %12s %12s %12lld %12lld\n",
               "PAPI_SR_INS: ", "------", (values[1])[0], "------",
               "------", (values[4])[1], (values[5])[1]);
        printf("%s %12s %12s %12lld %12lld %12lld %12s\n",
               "PAPI_LST_INS:", "------", "------", (values[2])[0],
               (values[3])[0], (values[4])[0], "------");
        printf("-------------------------------------------------------------------------------------------\n");

        printf("Test 1: PAPI_LD_INS only.\n");
        printf("Test 2: PAPI_SR_INS only.\n");
        printf("Test 3: PAPI_LST_INS only.\n");
        printf("Test 4: PAPI_LD_INS and PAPI_LST_INS.\n");
        printf("Test 5: PAPI_SR_INS and PAPI_LST_INS.\n");
        printf("Test 6: PAPI_LD_INS and PAPI_SR_INS.\n");
        printf("Verification: Values within each column should be the same.\n");
        printf("              R3C3 ~= (R1C1 + R2C2) ~= all other entries.\n");
    }

    test_pass(__FILE__, values, num_tests);
    exit(1);
}
Esempio n. 22
0
void *
Thread( void *arg )
{
	int retval, num_tests = 1, i;
	int EventSet1 = PAPI_NULL, mask1, PAPI_event;
	int num_events1;
	long long **values;
	long long elapsed_us, elapsed_cyc;
	unsigned short *profbuf;
	char event_name[PAPI_MAX_STR_LEN];

	retval = PAPI_register_thread(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
	profbuf = ( unsigned short * ) malloc( length * sizeof ( unsigned short ) );
	if ( profbuf == NULL )
		exit( 1 );
	memset( profbuf, 0x00, length * sizeof ( unsigned short ) );

	/* 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, &mask1 );

	values = allocate_test_space( num_tests, num_events1 );

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

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	retval = PAPI_profil( profbuf, length, my_start, 65536,
						  EventSet1, PAPI_event, THR, PAPI_PROFIL_POSIX );
	if ( retval )
		test_fail( __FILE__, __LINE__, "PAPI_profil", retval );

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

	do_flops( *( int * ) arg );

	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;

	/* to remove the profile flag */
	retval = PAPI_profil( profbuf, length, my_start, 65536,
						  EventSet1, PAPI_event, 0, PAPI_PROFIL_POSIX );
	if ( retval )
		test_fail( __FILE__, __LINE__, "PAPI_profil", retval );


	remove_test_events( &EventSet1, mask1 );

	if ( !TESTS_QUIET ) {
		if ( mask1 == 0x3 ) {
			printf( "Thread 0x%x PAPI_TOT_INS : \t%lld\n",
					( int ) pthread_self(  ), ( values[0] )[0] );
		} else {
			printf( "Thread 0x%x PAPI_FP_INS : \t%lld\n",
					( int ) pthread_self(  ), ( 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 );

		printf( "Test case: PAPI_profil() for pthreads\n" );
		printf( "----Profile buffer for Thread 0x%x---\n",
				( int ) pthread_self(  ) );
		for ( i = 0; i < ( int ) length; i++ ) {
			if ( profbuf[i] )
				printf( "0x%lx\t%d\n", ( unsigned long ) ( my_start + 2 * i ),
						profbuf[i] );
		}
	}
	for ( i = 0; i < ( int ) length; i++ )
		if ( profbuf[i] )
			break;

	if ( i >= ( int ) length )
		test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
	free_test_space( values, num_tests );

	retval = PAPI_unregister_thread(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
	return ( NULL );
}
Esempio n. 23
0
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket) {
   int i, retval;
   unsigned long blength;
   int num_buckets;

   char *profstr[5] = {"PAPI_PROFIL_POSIX",
                        "PAPI_PROFIL_RANDOM",
                        "PAPI_PROFIL_WEIGHTED",
                        "PAPI_PROFIL_COMPRESS",
                        "PAPI_PROFIL_<all>" };

   int profflags[5] = {PAPI_PROFIL_POSIX,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_RANDOM,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_COMPRESS,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED |
                       PAPI_PROFIL_RANDOM | PAPI_PROFIL_COMPRESS };

   do_no_profile();
   blength = prof_size(plength, scale, bucket, &num_buckets);
   prof_alloc(5, blength);

   for (i=0;i<5;i++) {
      if (!TESTS_QUIET)
         printf("Test type   : \t%s\n", profstr[i]);

#ifndef SWPROFILE
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, thresh,
                              profflags[i] | bucket)) != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
      }
#else
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, thresh,
                              profflags[i] | bucket | PAPI_PROFIL_FORCE_SW)) != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
      }
#endif
      if ((retval = PAPI_start(EventSet)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);

      do_flops(getenv("NUM_FLOPS") ? atoi(getenv("NUM_FLOPS")) : NUM_FLOPS);

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

      if (!TESTS_QUIET) {
         printf(TAB1, event_name, (values[1])[0]);
         printf(TAB1, "PAPI_TOT_CYC", (values[1])[1]);
      }
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, 0, profflags[i])) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
   }

   prof_head(blength, bucket, num_buckets, 
      "address\t\t\tflat\trandom\tweight\tcomprs\tall\n");
   prof_out(start, 5, bucket, num_buckets, scale);

   retval = prof_check(5, bucket, num_buckets);

   for (i=0;i<5;i++) {
      free(profbuf[i]);
   }

   return(retval);
}
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long values[2] = { 0, 0 };
   long long min, max;
   int num_flops=NUM_FLOPS, retval;
   int PAPI_event=0, mythreshold;
   char event_name[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info = NULL;

   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);

   if((!strncmp(hw_info->model_string, "UltraSPARC", 10) &&
       !(strncmp(hw_info->vendor_string, "SUN", 3))) ||
      (!strncmp(hw_info->model_string, "AMD K7", 6)) ||
      (!strncmp(hw_info->vendor_string, "Cray", 4)) ||
      (strstr(hw_info->model_string, "POWER3"))) {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_TOT_INS) == PAPI_OK) {
         PAPI_event = PAPI_TOT_INS;
      } else {
         test_fail(__FILE__, __LINE__, "PAPI_TOT_INS not available on this Sun platform!", 0);
      }
   } else {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_FP_INS) == PAPI_OK) {
         PAPI_event = PAPI_FP_INS;
      } else {
         if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) 
            PAPI_event = PAPI_FP_OPS;
         else 
            PAPI_event = PAPI_TOT_INS;
      }
   }

   if ( PAPI_event == PAPI_FP_INS )
      mythreshold = THRESHOLD ;
   else 
#if defined(linux)
      mythreshold = hw_info->mhz*10000*2;
#else
      mythreshold = THRESHOLD*2;
#endif

   retval = PAPI_create_eventset(&EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

   retval = PAPI_add_event(EventSet, PAPI_event);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);

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

   do_flops(NUM_FLOPS);

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

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

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

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, &values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

#if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4)
   num_flops *= 2;
#endif

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

      printf("Test case: Overflow dispatch of 1st event in set with 1 event.\n");
      printf("--------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf("-----------------------------------------------\n");

      printf("Test type    : %16d%16d\n", 1, 2);
      printf(OUT_FMT, event_name, values[0], values[1]);
      printf("Overflows    : %16s%16d\n", "", total);
      printf("-----------------------------------------------\n");

      printf("Verification:\n");
/*
	if (PAPI_event == PAPI_FP_INS)
		printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
	printf("Column 1 approximately equals column 2\n");
*/
      printf("Row 3 approximately equals %u +- %u %%\n",
             (unsigned) ((values[0]) / (long long) mythreshold),
             (unsigned) (OVR_TOLERANCE * 100.0));

   }

/*
  min = (long long)(values[0]*(1.0-TOLERANCE));
  max = (long long)(values[0]*(1.0+TOLERANCE));
  if ( values[1] > max || values[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

   min = (long long) ((values[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold);
   max = (long long) ((values[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold);
   if (total > max || total < min)
      test_fail(__FILE__, __LINE__, "Overflows", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Esempio n. 25
0
int
main( int argc, char **argv )
{
	int retval, pid, status, EventSet = PAPI_NULL;
	long long int values[] = {0,0};
	PAPI_option_t opt;

        tests_quiet( argc, argv );

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

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );

	memset( &opt, 0x0, sizeof ( PAPI_option_t ) );
	opt.inherit.inherit = PAPI_INHERIT_ALL;
	opt.inherit.eventset = EventSet;
	if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) {
		if ( retval == PAPI_ECMP) {
			test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
		} else {
			test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval );
		}
	}

	if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval );

	if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );

	retval = PAPI_query_event( PAPI_FP_INS );
	if ( retval == PAPI_ENOEVNT ) {
		test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
		values[1] = NUM_FLOPS; /* fake a return value to pass the test */
	} else if ( retval != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval );
	else if ( ( retval = PAPI_add_event( EventSet, PAPI_FP_INS ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );

	pid = fork(  );
	if ( pid == 0 ) {
		do_flops( NUM_FLOPS );
		exit( 0 );
	}
	if ( waitpid( pid, &status, 0 ) == -1 ) {
	  perror( "waitpid()" );
	  exit( 1 );
	}

	if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );

	if (!TESTS_QUIET) {
	   printf( "Test case inherit: parent starts, child works, parent stops.\n" );
	   printf( "------------------------------------------------------------\n" );

	   printf( "Test run    : \t1\n" );
	   printf( "PAPI_FP_INS : \t%lld\n", values[1] );
	   printf( "PAPI_TOT_CYC: \t%lld\n", values[0] );
	   printf( "------------------------------------------------------------\n" );

	   printf( "Verification:\n" );
	   printf( "Row 1 at least %d\n", NUM_FLOPS );
	   printf( "Row 2 greater than row 1\n");
	}

	if ( values[1] < NUM_FLOPS) {
		test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
	}

	if ( values[0] < values[1]) {
		test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC < PAPI_FP_INS", 1 );
	}

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Esempio n. 26
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;
}
Esempio n. 27
0
int main( int argc, char **argv ) {

   int retval,i,j;
   int EventSet[EVENTS_TO_TRY][MAX_PACKAGES];
   long long values[EVENTS_TO_TRY][MAX_PACKAGES];
   char event_name[BUFSIZ];
   char uncore_base[BUFSIZ];
   char uncore_event[BUFSIZ];
   int uncore_cidx=-1;
   int max_cbox=0;
   int core_to_use=0;

   const PAPI_hw_info_t *hwinfo;

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

   /* Init the PAPI library */
   retval = PAPI_library_init( PAPI_VER_CURRENT );
   if ( retval != PAPI_VER_CURRENT ) {
      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
   }

   /* Find the uncore PMU */
   uncore_cidx=PAPI_get_component_index("perf_event_uncore");
   if (uncore_cidx<0) {
      test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
   }

   /* Get hardware info */
   hwinfo = PAPI_get_hardware_info();
   if ( hwinfo == NULL ) {
        test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval);
   }

   /* Get event to use */
   if (hwinfo->vendor == PAPI_VENDOR_INTEL) {

      if ( hwinfo->cpuid_family == 6) {
         switch(hwinfo->cpuid_model) {
           case 45: /* SandyBridge EP */
                    strncpy(event_name,"UNC_C_TOR_OCCUPANCY:ALL",BUFSIZ);
                    strncpy(uncore_base,"snbep_unc_cbo",BUFSIZ);
                    break;
           case 58: /* IvyBridge */
                    strncpy(event_name,"UNC_CBO_CACHE_LOOKUP:STATE_I:ANY_FILTER",BUFSIZ);
                    strncpy(uncore_base,"ivb_unc_cbo",BUFSIZ);
                    break;
           default:
                    test_skip( __FILE__, __LINE__,
	            "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
        }
      }
      else {
          test_skip( __FILE__, __LINE__,
	            "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
      }
   }
   else {
      test_skip( __FILE__, __LINE__,
	            "This test only supported Intel chips", PAPI_ENOSUPP );

   }

   if (!TESTS_QUIET) {
      printf("Trying for %d sockets\n",hwinfo->sockets);
      printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores,
          hwinfo->ncpu);
   }

   for(i=0;i < hwinfo->sockets; i++) {

      /* perf_event provides which to use in "cpumask"    */
      /* but libpfm4 doesn't report this back to us (yet) */
      core_to_use=i*hwinfo->threads*hwinfo->cores;
      if (!TESTS_QUIET) {
         printf("Using core %d for socket %d\n",core_to_use,i);
      }

      for(j=0;j<EVENTS_TO_TRY;j++) {

         /* Create an eventset */
         EventSet[j][i]=PAPI_NULL;
         retval = PAPI_create_eventset(&EventSet[j][i]);
         if (retval != PAPI_OK) {
            test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
         }

         /* Set a component for the EventSet */
         retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx);
         if (retval!=PAPI_OK) {
            test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval);
         }

         /* we need to set to a certain cpu for uncore to work */

         PAPI_cpu_option_t cpu_opt;

         cpu_opt.eventset=EventSet[j][i];
         cpu_opt.cpu_num=core_to_use;

         retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
         if (retval != PAPI_OK) {
            test_skip( __FILE__, __LINE__,
		      "this test; trying to PAPI_CPU_ATTACH; need to run as root",
		      retval);
         }

         /* Default Granularity should work */

         /* Default domain should work */

         /* Add our uncore event */
	 sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name);
         retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
         if (retval != PAPI_OK) {
            max_cbox=j;
	    break;
         }
	 if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i);

     }
   }


   for(i=0;i < hwinfo->sockets; i++) {
      for(j=0;j<max_cbox;j++) {
         if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]);
         /* Start PAPI */
         retval = PAPI_start( EventSet[j][i] );
         if ( retval != PAPI_OK ) {
	    printf("Error starting socket %d cbox %d\n",i,j);
            test_fail( __FILE__, __LINE__, "PAPI_start", retval );
         }
     }
   }

   /* our work code */
   do_flops( NUM_FLOPS );

   /* Stop PAPI */
   for(i=0;i < hwinfo->sockets; i++) {
      for(j=0;j<max_cbox;j++) {
         retval = PAPI_stop( EventSet[j][i],&values[j][i] );
         if ( retval != PAPI_OK ) {
	    printf("Error stopping socket %d cbox %d\n",i,j);
            test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
         }
     }
   }

   /* Print Results */
   if ( !TESTS_QUIET ) {
      for(i=0;i < hwinfo->sockets; i++) {
         printf("Socket %d\n",i);
         for(j=0;j<max_cbox;j++) {
            printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
         }
      }
   }

   PAPI_shutdown();

   test_pass( __FILE__, NULL, 0 );


   return 0;
}