Exemple #1
0
static void
resultline( int i, int j, int EventSet )
{
	float ferror = 0;
	long long flpins = 0;
	long long papi, theory;
	int diff, retval;
	const PAPI_hw_info_t *hwinfo = NULL;

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

	i++;					 /* convert to 1s base  */
	theory = 2;
	while ( j-- )
		theory *= i;		 /* theoretical ops   */
	papi = flpins << FMA;

	diff = ( int ) ( papi - theory );

	ferror = ( ( float ) abs( diff ) ) / ( ( float ) theory ) * 100;

	printf( "%8d %12lld %12lld %8d %10.4f\n", i, papi, theory, diff, ferror );

#ifndef DONT_FAIL
	if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 1 );
	if ( hwinfo->vendor != PAPI_VENDOR_AMD && ferror > MAX_ERROR &&
		 abs( diff ) > MAX_DIFF && i > 20 )
		test_fail( __FILE__, __LINE__, "Calibrate: error exceeds 10%",
				   PAPI_EMISC );
#endif
}
Exemple #2
0
char *get_instructions_event(char *event, int size) {

   const PAPI_hw_info_t *hwinfo;

   hwinfo = PAPI_get_hardware_info();
   if ( hwinfo == NULL ) {
	return NULL;
   }

   if (hwinfo->vendor == PAPI_VENDOR_INTEL) {

      if ( hwinfo->cpuid_family == 6) {
	 strncpy(event,"INSTRUCTIONS_RETIRED",size);
	 return event;
      }

      if ( hwinfo->cpuid_family == 15) {
	 strncpy(event,"INSTR_RETIRED:NBOGUSNTAG",size);
	 return event;
      }


      return NULL;
   }
   else if (hwinfo->vendor == PAPI_VENDOR_AMD) {
	 strncpy(event,"RETIRED_INSTRUCTIONS",size);
	 return event;
   }

   return NULL;
}
Exemple #3
0
void
init_multiplex( void )
{
	int retval;
	const PAPI_hw_info_t *hw_info;
	const PAPI_component_info_t *cmpinfo;

	/* Initialize the library */

	/* for now, assume multiplexing on CPU compnent only */
	cmpinfo = PAPI_get_component_info( 0 );
	if ( cmpinfo == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );

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

	if ( ( strstr( cmpinfo->name, "perfctr.c" ) ) && (hw_info !=NULL) &&
		 strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
		retval = PAPI_set_domain( PAPI_DOM_ALL );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
	}
	retval = PAPI_multiplex_init(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI multiplex init fail\n", retval );
}
int main(int argc, char **argv)
{
   int retval;
   long long elapsed_us, elapsed_cyc;
   const PAPI_hw_info_t *hw_info;

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

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

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

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

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

   sleep(10);

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

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

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

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

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

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

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

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

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

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   if (!TESTS_QUIET) {
      printf("Master real usec   : \t%lld\n", elapsed_us);
      printf("Master real cycles : \t%lld\n", elapsed_cyc);
   }
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Exemple #6
0
char *get_offcore_event(char *event, int size) {

   const PAPI_hw_info_t *hwinfo;

   hwinfo = PAPI_get_hardware_info();
   if ( hwinfo == NULL ) {
	return NULL;
   }

   if (hwinfo->vendor == PAPI_VENDOR_INTEL) {

      if ( hwinfo->cpuid_family == 6) {
	switch(hwinfo->cpuid_model) {
	   case 26:
           case 30:
	   case 31: /* Nehalem */
	   case 46: /* Nehalem EX */
	            strncpy(event,"OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM",size);
		    return event;
	            break;
	   case 37:
	   case 44: /* Westmere */
	   case 47: /* Westmere EX */
	            strncpy(event,"OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM",size);
		    return event;
	            break;

	   case 45: /* SandyBridge EP */
	   case 42: /* SandyBridge */
	            strncpy(event,"OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE",size);
		    return event;
		    break;

	   case 58: /* IvyBridge */
	   case 62: /* Ivy Trail */
	            strncpy(event,"OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE",size);
		    return event;
		    break;

	   case 60: /* Haswell */
	   case 69:
	   case 70:
	   case 63: /* Haswell EP */
	            strncpy(event,"OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE",size);
		    return event;
		    break;

	 }
      }
      return NULL;
   }
   else if (hwinfo->vendor == PAPI_VENDOR_AMD) {
      return NULL;
   }

   return NULL;
}
int main(int argc, char **argv)
{
   pthread_t slaves[MAX_THREADS];
   int rc, i, nthr;
   int retval;
  const PAPI_hw_info_t *hwinfo = NULL;

#if defined(__ALPHA) && defined(__osf__)
   test_skip(__FILE__, __LINE__, "thread support not available on this platform!", PAPI_ESBSTR);
#endif

   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 ((hwinfo = PAPI_get_hardware_info()) == NULL)
    test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);
   
   retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self));
   if (retval != PAPI_OK) {
      if (retval == PAPI_ESBSTR)
         test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval);
      else
         test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }

   if (hwinfo->ncpu > MAX_THREADS) 
     nthr = MAX_THREADS;
   else
     nthr = hwinfo->ncpu;

   printf("Creating %d threads\n", nthr);

   for (i=0;i<nthr;i++)
     {
       rc = pthread_create(&slaves[i], NULL, Slave, NULL);
       if (rc) {
	 retval = PAPI_ESYS;
	 test_fail(__FILE__, __LINE__, "pthread_create", retval);
       }
     }

   for (i=0;i<nthr;i++)
     {
       pthread_join(slaves[i], NULL);
     }

   printf("Expected: %lld Received: %lld\n", (long long)nthr*num_iters, count);
   if (nthr*num_iters != count)
      test_fail(__FILE__, __LINE__, "Thread Locks", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Exemple #8
0
/*  Support routine to display header information to the screen
	from the hardware info data structure. The same code was duplicated
	in a number of tests and utilities. Seems to make sense to refactor.
	This may not be the best place for it to live, but it works for now.
 */
int
papi_print_header( char *prompt, const PAPI_hw_info_t ** hwinfo )
{
	if ( ( *hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
		return ( PAPI_ESBSTR );

	printf( "%s", prompt );
	printf
		( "--------------------------------------------------------------------------------\n" );
	printf( "PAPI Version             : %d.%d.%d.%d\n",
			PAPI_VERSION_MAJOR( PAPI_VERSION ),
			PAPI_VERSION_MINOR( PAPI_VERSION ),
			PAPI_VERSION_REVISION( PAPI_VERSION ),
			PAPI_VERSION_INCREMENT( PAPI_VERSION ) );
	printf( "Vendor string and code   : %s (%d)\n", ( *hwinfo )->vendor_string,
			( *hwinfo )->vendor );
	printf( "Model string and code    : %s (%d)\n", ( *hwinfo )->model_string,
			( *hwinfo )->model );
	printf( "CPU Revision             : %f\n", ( *hwinfo )->revision );
	if ( ( *hwinfo )->cpuid_family > 0 )
		printf
			( "CPUID Info               : Family: %d  Model: %d  Stepping: %d\n",
			  ( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model,
			  ( *hwinfo )->cpuid_stepping );
	printf( "CPU Megahertz            : %f\n", ( *hwinfo )->mhz );
	printf( "CPU Clock Megahertz      : %d\n", ( *hwinfo )->clock_mhz );
	if ( ( *hwinfo )->threads > 0 )
		printf( "Hdw Threads per core     : %d\n", ( *hwinfo )->threads );
	if ( ( *hwinfo )->cores > 0 )
		printf( "Cores per Socket         : %d\n", ( *hwinfo )->cores );
	if ( ( *hwinfo )->sockets > 0 )
		printf( "Sockets                  : %d\n", ( *hwinfo )->sockets );
	if ( ( *hwinfo )->nnodes > 0 )
		printf( "NUMA Nodes               : %d\n", ( *hwinfo )->nnodes );
	printf( "CPUs per Node            : %d\n", ( *hwinfo )->ncpu );
	printf( "Total CPUs               : %d\n", ( *hwinfo )->totalcpus );
	printf( "Running in a VM          : %s\n", ( *hwinfo )->virtualized?
		"yes":"no");
	if ( (*hwinfo)->virtualized) {
           printf( "VM Vendor:               : %s\n", (*hwinfo)->virtual_vendor_string);
	}
	printf( "Number Hardware Counters : %d\n",
			PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) );
	printf( "Max Multiplex Counters   : %d\n",
			PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) );
	printf
		( "--------------------------------------------------------------------------------\n" );
	printf( "\n" );
	return PAPI_OK;
}
int main(int argc, char **argv)
{
   int i,j;
   int retval;
   int print_avail_only = 0;
   PAPI_event_info_t info;
   const PAPI_hw_info_t *hwinfo = NULL;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */
   for (i = 0; i < argc; i++)
      if (argv[i]) {
         if (strstr(argv[i], "-a"))
            print_avail_only = PAPI_PRESET_ENUM_AVAIL;
         if (strstr(argv[i], "-h")) {
            print_help();
            exit(1);
         }
      }

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

   if (!TESTS_QUIET) {
      retval = PAPI_set_debug(PAPI_VERB_ECONT);
      if (retval != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval);
   }

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

   i = PAPI_PRESET_MASK;
   printf("name,derived,postfix,short_descr,long_descr,note,[native,...]\n\n");

   do {
      if (PAPI_get_event_info(i, &info) == PAPI_OK) {
	      printf("%s,%s,%s,", info.symbol, info.derived, info.postfix);
         if (info.short_descr[0]) { printf("\"%s\",", info.short_descr); }
         else { printf(","); }
         if (info.long_descr[0]) { printf("\"%s\",", info.long_descr); }
         else { printf(","); }
	      if (info.note[0]) printf("\"%s\"", info.note);

         for (j=0;j<(int)info.count;j++) printf(",%s",info.name[j]);
         printf("\n");
	   }
   } while (PAPI_enum_event(&i, print_avail_only) == PAPI_OK);
   exit(1);
}
Exemple #10
0
/*  Support routine to display header information to the screen
	from the hardware info data structure. The same code was duplicated
	in a number of tests and utilities. Seems to make sense to refactor.
	This may not be the best place for it to live, but it works for now.
 */
int
papi_print_header( char *prompt, int event_flag,
				   const PAPI_hw_info_t ** hwinfo )
{
	if ( ( *hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
		return ( PAPI_ESBSTR );

	printf( "%s", prompt );
	printf
		( "--------------------------------------------------------------------------------\n" );
	printf( "PAPI Version             : %d.%d.%d.%d\n",
			PAPI_VERSION_MAJOR( PAPI_VERSION ),
			PAPI_VERSION_MINOR( PAPI_VERSION ),
			PAPI_VERSION_REVISION( PAPI_VERSION ),
			PAPI_VERSION_INCREMENT( PAPI_VERSION ) );
	printf( "Vendor string and code   : %s (%d)\n", ( *hwinfo )->vendor_string,
			( *hwinfo )->vendor );
	printf( "Model string and code    : %s (%d)\n", ( *hwinfo )->model_string,
			( *hwinfo )->model );
	printf( "CPU Revision             : %f\n", ( *hwinfo )->revision );
	if ( ( *hwinfo )->cpuid_family > 0 )
		printf
			( "CPUID Info               : Family: %d  Model: %d  Stepping: %d\n",
			  ( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model,
			  ( *hwinfo )->cpuid_stepping );
	printf( "CPU Megahertz            : %f\n", ( *hwinfo )->mhz );
	printf( "CPU Clock Megahertz      : %d\n", ( *hwinfo )->clock_mhz );
	if ( ( *hwinfo )->threads > 0 )
		printf( "Hdw Threads per core     : %d\n", ( *hwinfo )->threads );
	if ( ( *hwinfo )->cores > 0 )
		printf( "Cores per Socket         : %d\n", ( *hwinfo )->cores );
	if ( ( *hwinfo )->sockets > 0 )
		printf( "Sockets                  : %d\n", ( *hwinfo )->sockets );
	if ( ( *hwinfo )->nnodes > 0 )
		printf( "NUMA Nodes               : %d\n", ( *hwinfo )->nnodes );
	printf( "CPU's per Node           : %d\n", ( *hwinfo )->ncpu );
	printf( "Total CPU's              : %d\n", ( *hwinfo )->totalcpus );
	printf( "Number Hardware Counters : %d\n",
			PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) );
	printf( "Max Multiplex Counters   : %d\n",
			PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) );
	printf
		( "--------------------------------------------------------------------------------\n" );
	if ( event_flag )
		printf
			( "The following correspond to fields in the PAPI_event_info_t structure.\n" );
	printf( "\n" );
	return ( PAPI_OK );
}
uint64_t vt_metric_clckrt(void)
{
  const PAPI_hw_info_t* hwinfo = NULL;
  double hertz;

  if (!PAPI_is_initialized()) {
    /* initialize PAPI, since it hasn't already been initialized */
    int retval = PAPI_library_init(PAPI_VER_CURRENT);
    if ( retval != PAPI_VER_CURRENT )
      metric_error(retval, "PAPI_library_init");
  }

  hwinfo = PAPI_get_hardware_info();
  if ( hwinfo == NULL)
    vt_error_msg("Failed to access PAPI hardware info\n");
  vt_cntl_msg(2, "Clock rate: %f MHz", hwinfo->mhz);

  hertz = hwinfo->mhz * 1000000.0;

  return (uint64_t)hertz;
}
double esd_metric_clckrt()
{
  const char* env;
  const PAPI_hw_info_t* hwinfo = NULL;

  if (!PAPI_is_initialized()) {
      /* read configuration variable "EPK_METRICS". Return if unset. */
      env = epk_get(EPK_METRICS);
      if ( env == NULL || strlen(env)==0)
          return 0.0;

      /* initialize PAPI, since it hasn't already been initialized */
      int retval = PAPI_library_init(PAPI_VER_CURRENT);
      if ( retval != PAPI_VER_CURRENT )
        esd_metric_error(retval, "PAPI_library_init");
  }

  hwinfo = PAPI_get_hardware_info(); 
  if ( hwinfo == NULL)
    elg_error_msg("Failed to access PAPI hardware info");
  elg_cntl_msg("Clock rate: %f MHz", hwinfo->mhz);

  return hwinfo->mhz * 1000000.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;
}
Exemple #14
0
/* add native events to use all counters */
int
enum_add_native_events( int *num_events, int **evtcodes, 
			int need_interrupt, int no_software_events )
{
	/* query and set up the right event to monitor */
     int EventSet = PAPI_NULL;
     int i = 0, k, event_code, retval;
     int counters, event_found = 0;
     PAPI_event_info_t info;
     const PAPI_component_info_t *s = NULL;
     const PAPI_hw_info_t *hw_info = NULL;
   
     s = PAPI_get_component_info( 0 );
     if ( s == NULL ) {
	test_fail( __FILE__, __LINE__, 
			   "PAPI_get_component_info", PAPI_ESBSTR );
     }

     hw_info = PAPI_get_hardware_info(  );
     if ( hw_info == NULL ) {
        test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
     }
   
     counters = PAPI_num_hwctrs(  );
     if (counters<1) {
	test_fail(__FILE__,__LINE__, "No counters available!\n",1);
     }

     if (!TESTS_QUIET) printf("Trying to fill %d hardware counters...\n",
			      counters);
   
     if (need_interrupt) {
        if ( (!strcmp(hw_info->model_string,"POWER6")) ||
	     (!strcmp(hw_info->model_string,"POWER5")) ) {
	   
	   test_warn(__FILE__, __LINE__,
		    "Limiting num_counters because of LIMITED_PMC on Power5 and Power6",1);
           counters=4;
	}
     }

     ( *evtcodes ) = ( int * ) calloc( counters, sizeof ( int ) );

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

     /* For platform independence, always ASK FOR the first event */
     /* Don't just assume it'll be the first numeric value */
     i = 0 | PAPI_NATIVE_MASK;
     PAPI_enum_event( &i, PAPI_ENUM_FIRST );

     do {
        retval = PAPI_get_event_info( i, &info );

	/* HACK! FIXME */
        if (no_software_events && ( strstr(info.symbol,"PERF_COUNT_SW") || strstr(info.long_descr, "PERF_COUNT_SW") ) ) {
	   if (!TESTS_QUIET) {
	      printf("Blocking event %s as a SW event\n", info.symbol);
	   }
	   continue;
	}

	if ( s->cntr_umasks ) {
	   k = i;
			
	   if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
	      do {
	         retval = PAPI_get_event_info( k, &info );
		 event_code = ( int ) info.event_code;

		 retval = PAPI_add_event( EventSet, event_code );
		 if ( retval == PAPI_OK ) {
		    ( *evtcodes )[event_found] = event_code;
		    if ( !TESTS_QUIET ) {
		       printf( "event_code[%d] = 0x%x (%s)\n",
			       event_found, event_code, info.symbol );
		    }
		    event_found++;
		 } else {
		    if ( !TESTS_QUIET ) {
		       printf( "0x%x (%s) can't be added to the EventSet.\n",
			       event_code, info.symbol );
		    }
		 }
	      } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK
						&& event_found < counters );
	   } else {
	      event_code = ( int ) info.event_code;
	      retval = PAPI_add_event( EventSet, event_code );
	      if ( retval == PAPI_OK ) {
		  ( *evtcodes )[event_found] = event_code;
		  if ( !TESTS_QUIET ) {
		     printf( "event_code[%d] = 0x%x (%s)\n",
			       event_found, event_code, info.symbol );
		  }
		  event_found++;
	      }
	   }
	   if ( !TESTS_QUIET && retval == PAPI_OK ) {
	     /* */
	   }
	} else {
			event_code = ( int ) info.event_code;
			retval = PAPI_add_event( EventSet, event_code );
			if ( retval == PAPI_OK ) {
				( *evtcodes )[event_found] = event_code;
				event_found++;
			} else {
				if ( !TESTS_QUIET )
					fprintf( stdout, "0x%x is not available.\n", event_code );
			}
		}
	}
	while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK &&
			event_found < counters );

	*num_events = ( int ) event_found;

	if (!TESTS_QUIET) printf("Tried to fill %d counters with events, "
				 "found %d\n",counters,event_found);

	return EventSet;
}
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);
}
int main(int argc, char **argv) {
   
   int retval,quiet;
   const PAPI_hw_info_t *info;

   int events[2];
   long long counts[2];
   double error;
   long long expected;

   char test_string[]="Testing core2_constraints...";

   quiet=test_quiet();

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT) {
     if (!quiet) printf("ERROR: PAPI_library_init %d\n", retval);
        test_fail(test_string);
   }

   if ( (info=PAPI_get_hardware_info())==NULL) {
     if (!quiet) printf("cannot obtain hardware info %d\n",retval);
      test_fail(test_string);
   }

   if ((info->vendor==PAPI_VENDOR_INTEL) && (info->cpuid_family==6) && 
			((info->cpuid_model==15) || (info->cpuid_model==23) || (info->cpuid_model==29))) {

     if (!quiet) printf("Found core2!\n");
   }
   else {
     if (!quiet) printf("Not a core2.\n");
     test_skip(test_string);
   }

   expected=naive_matrix_multiply_estimated_flops(quiet);

   retval=PAPI_event_name_to_code("FP_COMP_OPS_EXE",&events[0]);
   if (retval!=PAPI_OK) {
      if (!quiet) printf("PAPI_event_name_to_code %d\n", retval);      
      test_fail(test_string);
   }

   events[1]=PAPI_TOT_INS;

   PAPI_start_counters(events,2);

   naive_matrix_multiply(quiet);

   PAPI_stop_counters(counts,2);

   error=(((double)counts[0]-(double)expected)/(double)expected)*100.0;
   if (!quiet) printf("   Expected: %lld  Actual: %lld   Error: %.2lf\n", 
             expected, counts[0],error);

   if (error > 1.0) {
      if (!quiet) printf("FP error higher than expected\n");
      test_fail(test_string);
   }

   /* set FP_COMP_OPS_EXE to be in slot 2 */

   retval=PAPI_event_name_to_code("FP_COMP_OPS_EXE",&events[1]);
   if (retval!=PAPI_OK) {
      if (!quiet) printf("PAPI_event_name_to_code %d\n",retval);
      test_fail(test_string);
   }
   events[0]=events[1];

   PAPI_start_counters(events,2);

   naive_matrix_multiply(quiet);

   PAPI_stop_counters(counts,2);
   
   error=(((double)counts[1]-(double)expected)/(double)expected)*100.0;
   if (!quiet) printf("   Expected: %lld  Actual: %lld   Error: %.2lf\n", 
             expected, counts[1],error);

   if (error > 1.0) {
      if (!quiet) printf("FP error higher than expected\n");
      test_fail(test_string);
   }

   PAPI_shutdown();

   test_pass(test_string);

   return 0;
}
int main(int argc, char **argv)
{
   int retval, i,j;
   int EventSet=PAPI_NULL;
   long long values[2];
   const PAPI_hw_info_t *hwinfo = NULL;
   char descr[PAPI_MAX_STR_LEN];
   PAPI_event_info_t evinfo;
   PAPI_mh_level_t *L;


   const unsigned int eventlist[] = {
      PAPI_L1_DCA,
      PAPI_L1_DCM,
      PAPI_L1_DCH,
      PAPI_L2_DCA,
      PAPI_L2_DCM,
      PAPI_L2_DCH,
#if 0
      PAPI_L1_LDM,
      PAPI_L1_STM,
      PAPI_L1_DCR,
      PAPI_L1_DCW,
      PAPI_L1_ICM,
      PAPI_L1_TCM,
      PAPI_LD_INS,
      PAPI_SR_INS,
      PAPI_LST_INS,
      PAPI_L2_DCR,
      PAPI_L2_DCW,
      PAPI_CSR_TOT,
      PAPI_MEM_SCY,
      PAPI_MEM_RCY,
      PAPI_MEM_WCY,
      PAPI_L1_ICH,
      PAPI_L1_ICA,
      PAPI_L1_ICR,
      PAPI_L1_ICW,
      PAPI_L1_TCH,
      PAPI_L1_TCA,
      PAPI_L1_TCR,
      PAPI_L1_TCW,
      PAPI_L2_DCM,
      PAPI_L2_ICM,
      PAPI_L2_TCM,
      PAPI_L2_LDM,
      PAPI_L2_STM,
      PAPI_L2_DCH,
      PAPI_L2_DCA,
      PAPI_L2_DCR,
      PAPI_L2_DCW,
      PAPI_L2_ICH,
      PAPI_L2_ICA,
      PAPI_L2_ICR,
      PAPI_L2_ICW,
      PAPI_L2_TCH,
      PAPI_L2_TCA,
      PAPI_L2_TCR,
      PAPI_L2_TCW,
#endif
      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 ((hwinfo = PAPI_get_hardware_info()) == NULL) {
      test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);
   }

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

   /* Extract and report the cache information */
   L = (PAPI_mh_level_t *) (hwinfo->mem_hierarchy.level);
   for (i=0; i<hwinfo->mem_hierarchy.levels; i++) {
      for (j=0; j<2; j++) {
	  int tmp;

	  tmp = PAPI_MH_CACHE_TYPE(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_UNIFIED)
	  { printf("L%d Unified ",i+1);} 
	  else if (tmp == PAPI_MH_TYPE_DATA)
	  { 	      printf("L%d Data ",i+1);}
	  else if (tmp == PAPI_MH_TYPE_INST)
	  { printf("L%d Instruction ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_VECTOR)
	  { printf("L%d Vector ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_TRACE)
	  { printf("L%d Trace ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_EMPTY)
	  { break; }
	  else
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); }

	  tmp = PAPI_MH_CACHE_WRITE_POLICY(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_WB)
	  { printf("Write back ");} 
	  else if (tmp == PAPI_MH_TYPE_WT)
	  { printf("Write through ");} 
	  else 
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); } 

	  tmp = PAPI_MH_CACHE_REPLACEMENT_POLICY(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_PSEUDO_LRU)
	  { printf("Pseudo LRU policy "); } 
	  else if (tmp == PAPI_MH_TYPE_LRU)
	  { printf("LRU policy ");} 
	  else if (tmp == PAPI_MH_TYPE_UNKNOWN)
	  { printf("Unknown policy "); }
	  else
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); }

	  printf("Cache:\n");
         if (L[i].cache[j].type) {
            printf("  Total size: %dKB\n  Line size: %dB\n  Number of Lines: %d\n  Associativity: %d\n\n",
               (L[i].cache[j].size)>>10, L[i].cache[j].line_size, L[i].cache[j].num_lines, L[i].cache[j].associativity);
         }
      }
   }
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 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);
}
Exemple #20
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 );
}
Exemple #21
0
int
main( int argc, char **argv )
{
    int status, retval, num_tests = 1, tmp;
    int EventSet1 = PAPI_NULL;
    long long **values;
    long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
    char event_name[PAPI_MAX_STR_LEN];;
    const PAPI_hw_info_t *hw_info;
    const PAPI_component_info_t *cmpinfo;
    pid_t pid;

    /* Fork before doing anything with the PMU */

    setbuf(stdout,NULL);
    pid = fork(  );
    if ( pid < 0 )
        test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
    if ( pid == 0 )
        exit( wait_for_attach_and_loop(  ) );

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


    /* Master only process below here */

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

    if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 );

    if ( cmpinfo->attach == 0 )
        test_skip( __FILE__, __LINE__, "Platform does not support attaching",
                   0 );

    hw_info = PAPI_get_hardware_info(  );
    if ( hw_info == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );

    /* 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 */
    retval = PAPI_create_eventset(&EventSet1);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    /* Force addition of component */

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

    /* The following call causes this test to fail for perf_events */

    retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    sprintf(event_name,"PAPI_TOT_CYC");

    retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    retval = PAPI_add_event(EventSet1, PAPI_FP_INS);
    if ( retval == PAPI_ENOEVNT ) {
        test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
    } else if ( retval != PAPI_OK ) {
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    }

    values = allocate_test_space( 1, 2);

    elapsed_us = PAPI_get_real_usec(  );

    elapsed_cyc = PAPI_get_real_cyc(  );

    elapsed_virt_us = PAPI_get_virt_usec(  );

    elapsed_virt_cyc = PAPI_get_virt_cyc(  );

    printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
    pid_t  child = wait( &status );
    printf( "Debugger exited wait() with %d\n",child );
    if (WIFSTOPPED( status ))
    {
        printf( "Child has stopped due to signal %d (%s)\n",
                WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
    }
    if (WIFSIGNALED( status ))
    {
        printf( "Child %ld received signal %d (%s)\n",
                (long)child,
                WTERMSIG(status) , strsignal(WTERMSIG( status )) );
    }
    printf("After %d\n",retval);

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

    printf("Continuing\n");
    if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
        perror( "ptrace(PTRACE_CONT)" );
        return 1;
    }


    do {
        child = wait( &status );
        printf( "Debugger exited wait() with %d\n", child);
        if (WIFSTOPPED( status ))
        {
            printf( "Child has stopped due to signal %d (%s)\n",
                    WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
        }
        if (WIFSIGNALED( status ))
        {
            printf( "Child %ld received signal %d (%s)\n",
                    (long)child,
                    WTERMSIG(status) , strsignal(WTERMSIG( status )) );
        }
    } while (!WIFEXITED( status ));

    printf("Child exited with value %d\n",WEXITSTATUS(status));
    if (WEXITSTATUS(status) != 0)
        test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);

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

    elapsed_virt_us = PAPI_get_virt_usec(  ) - elapsed_virt_us;

    elapsed_virt_cyc = PAPI_get_virt_cyc(  ) - elapsed_virt_cyc;

    elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

    elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

    retval = PAPI_cleanup_eventset(EventSet1);
    if (retval != PAPI_OK)
        test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

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

    printf( "Test case: 3rd party attach start, stop.\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    : \t           1\n" );

    printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
    printf( TAB1, "PAPI_FP_INS  : \t", ( values[0] )[1] );
    printf( TAB1, "Real usec    : \t", elapsed_us );
    printf( TAB1, "Real cycles  : \t", elapsed_cyc );
    printf( TAB1, "Virt usec    : \t", elapsed_virt_us );
    printf( TAB1, "Virt cycles  : \t", elapsed_virt_cyc );

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

    printf( "Verification: none\n" );

    test_pass( __FILE__, values, num_tests );
    exit( 1 );
}
void mainloop(int arg)
{
   int retval, num_tests = 1;
   int EventSet1=PAPI_NULL;
   int mask1 = 0x0;
   int num_events1;
   long long **values;
   const PAPI_hw_info_t *hw_info;
   int PAPI_event;
   char event_name[PAPI_MAX_STR_LEN];

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != 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 */
   EventSet1 = add_two_nonderived_events(&num_events1, &PAPI_event, hw_info, &mask1);

   values = allocate_test_space(num_tests, num_events1);

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

   do_stuff();

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

   do_stuff();

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

   /* clear the papi_overflow event */
   if ((retval = PAPI_overflow(EventSet1, PAPI_event, 0, 0, NULL)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

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

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

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

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

   free_test_space(values, num_tests);
   PAPI_shutdown();
}
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);
}
Exemple #24
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;
}
Exemple #25
0
int
main( int argc, char **argv )
{
	long length;
	int mask;
	int retval;
	const PAPI_exe_info_t *prginfo;
	caddr_t start, end;

	prof_init( argc, argv, &prginfo );

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

       	mask = MASK_TOT_CYC | MASK_TOT_INS | MASK_FP_OPS | MASK_L2_TCM;

#if defined(__powerpc__)
	if ( strcmp( hw_info->model_string, "POWER6" ) == 0 )
		mask = MASK_TOT_CYC | MASK_FP_INS;
	else
		mask = MASK_TOT_CYC | MASK_TOT_INS | MASK_FP_INS;
#endif

#if defined(ITANIUM2)
	mask = MASK_TOT_CYC | MASK_FP_OPS | MASK_L2_TCM | MASK_L1_DCM;
#endif
	EventSet = add_test_events( &num_events, &mask, 0 );
	values = allocate_test_space( 1, num_events );

/* profile the cleara and my_main address space */
	start = ( caddr_t ) cleara;
	end = ( caddr_t ) my_dummy;

/* Itanium and PowerPC64 processors return function descriptors instead
 * of function addresses. You must dereference the descriptor to get the address.
*/
#if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
	start = ( caddr_t ) ( ( ( struct fdesc * ) start )->ip );
	end = ( caddr_t ) ( ( ( struct fdesc * ) end )->ip );
#endif

	/* call dummy so it doesn't get optimized away */
	retval = my_dummy( 1 );

	length = end - start;
	if ( length < 0 )
		test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );

	prof_print_address
		( "Test case byte_profile: Multi-event profiling at byte resolution.\n",
		  prginfo );
	prof_print_prof_info( start, end, THRESHOLD, event_name );

	retval =
		do_profile( start, ( unsigned ) length, 
			    FULL_SCALE * 2, THRESHOLD,
			    PAPI_PROFIL_BUCKET_32, mask );

	remove_test_events( &EventSet, mask );

	if ( retval )
		test_pass( __FILE__, values, 1 );
	else
		test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
	return 1;
}
Exemple #26
0
int
main( int argc, char **argv )
{
	int retval;
	const PAPI_exe_info_t *prginfo = NULL;
	const PAPI_hw_info_t *hw_info;

#if !defined(ITANIUM2) && !defined(ITANIUM3)
	test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 );
	exit( 1 );
#endif

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

	init_array(  );
	printf( "Malloc'd array  pointers: %p   %p   %p\n", &parray1, &parray2,
			&parray3 );
	printf( "Malloc'd array addresses: %p   %p   %p\n", parray1, parray2,
			parray3 );
	printf( "Static   array addresses: %p   %p   %p\n", &array1, &array2,
			&array3 );

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

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

	if ( ( prginfo = PAPI_get_executable_info(  ) ) == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );

#if defined(linux) && defined(__ia64__)
	sprintf( event_name[0], "loads_retired" );
	sprintf( event_name[1], "stores_retired" );
	PAPI_event_name_to_code( event_name[0], &PAPI_event[0] );
	PAPI_event_name_to_code( event_name[1], &PAPI_event[1] );
#else
	test_fail( __FILE__, __LINE__, "only works for Itanium", PAPI_ESBSTR );
#endif

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

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

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

/***************************************************************************************/
	printf
		( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" );
	printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 );
	printf
		( "These loads result from accessing the pointers to compute array addresses.\n" );
	printf
		( "They will likely disappear with higher levels of optimization.\n" );

	measure_load_store( ( caddr_t ) & parray1, ( caddr_t ) ( &parray1 + 1 ) );
	measure_load_store( ( caddr_t ) & parray2, ( caddr_t ) ( &parray2 + 1 ) );
	measure_load_store( ( caddr_t ) & parray3, ( caddr_t ) ( &parray3 + 1 ) );
/***************************************************************************************/
	printf
		( "\n\nMeasure loads and stores on the allocated arrays themselves\n" );
	printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );

	measure_load_store( ( caddr_t ) parray1, ( caddr_t ) ( parray1 + NUM ) );
	measure_load_store( ( caddr_t ) parray2, ( caddr_t ) ( parray2 + NUM ) );
	measure_load_store( ( caddr_t ) parray3, ( caddr_t ) ( parray3 + NUM ) );
/***************************************************************************************/
	printf( "\n\nMeasure loads and stores on the static arrays\n" );
	printf
		( "These values will differ from the expected values by the size of the offsets.\n" );
	printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );

	measure_load_store( ( caddr_t ) array1, ( caddr_t ) ( array1 + NUM ) );
	measure_load_store( ( caddr_t ) array2, ( caddr_t ) ( array2 + NUM ) );
	measure_load_store( ( caddr_t ) array3, ( caddr_t ) ( array3 + NUM ) );
/***************************************************************************************/

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

	free( parray1 );
	free( parray2 );
	free( parray3 );

	test_pass( __FILE__, NULL, 0 );

	exit( 1 );
}
Exemple #27
0
int
main( int argc, char *argv[] )
{
	int EventSet = PAPI_NULL;
	int retval, i, dash = 0, evt3 = PAPI_L1_DCM;
	PAPI_option_t options;
	PAPI_option_t options2;
	const PAPI_hw_info_t *hwinfo;
	long long lwrflow = 0, error, max_error = 0;
	long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

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

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

	retval = PAPI_get_opt( PAPI_HWINFO, &options );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
	printf( "ovf_info = %d (%#x)\n", options.ovf_info.type,
			options.ovf_info.type );

	retval = PAPI_get_opt( PAPI_SUBSTRATEINFO, &options2 );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
	printf( "sub_info->hardware_intr = %d\n\n",
			options2.sub_info->hardware_intr );

	if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );

	printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );

/* processing exceptions is a pain */
#if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
	if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
		evt3 = PAPI_L2_TCM;
	} else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
		/* do nothing */
	} else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
		/* do nothing */
	} else if ( !strncmp( hwinfo->model_string, "Intel Core", 10 ) ) {
		evt3 = 0;
	} else
		evt3 = 0;			 /* for default PIII */
#endif

	retval = PAPI_create_eventset( &EventSet );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval );
	retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_CYC", retval );
	if ( evt3 ) {
		retval = PAPI_add_event( EventSet, evt3 );
		if ( retval < 0 )
			test_fail( __FILE__, __LINE__, "PAPI_add_event:evt3", retval );
	}
	retval = PAPI_overflow( EventSet, PAPI_TOT_INS, OVRFLOW, 0, handler );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	for ( i = 0; i < 1000000; i++ ) {
		if ( i % 1000 == 0 ) {
			int i;

			PAPI_read( EventSet, vals );
			if ( vals[0] % OVRFLOW > LOWERFLOW ||
				 vals[0] % OVRFLOW < UPPERFLOW ) {
				dash = 0;
				printf( "Main loop read vals :" );
				for ( i = 0; i < 3 /* 8 */ ; i++ )
					printf( "%lld ", vals[i] );
				printf( "\n" );
				if ( ovrflow ) {
					error = ovrflow - ( lwrflow + vals[0] ) / 2;
					printf( "Difference: %lld\n", error );
					ovrflow = 0;
					if ( abs( error ) > max_error )
						max_error = abs( error );
				}
				lwrflow = vals[0];
			} else if ( vals[0] % OVRFLOW > UPPERFLOW && !dash ) {
				dash = 1;
				printf( "---------------------\n" );
			}
		}
	}

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

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

	printf( "Verification:\n" );
	printf
		( "Maximum absolute difference between overflow value\nand adjacent measured values is: %lld\n",
		  max_error );
	if ( max_error >= ERRORFLOW ) {
		printf( "This exceeds the error limit: %d\n", ERRORFLOW );
		test_fail( __FILE__, __LINE__, "Overflows", 1 );
	}
	printf( "This is within the error limit: %d\n", ERRORFLOW );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Exemple #28
0
int main(int argc, char **argv){
  if (argc != 3){
    printf("\tFirst argument: matrix size\n");
    printf("\tEigenvalues only: 1 for QR, 2 for BI, 3 for DC and 4 for MRRR\n");
    printf("\tEigenvectors too: 5 for QR, 6 for BI, 7 for DC and 6 for MRRR\n");
    return EXIT_SUCCESS;
  }
  int N = atoi(argv[1]);
  int method = atoi(argv[2]);
  if (method < 1 || method > 8){
    printf("\tFirst argument: matrix size\n");
    printf("\tEigenvalues only: 1 for QR, 2 for BI, 3 for DC and 4 for MRRR\n");
    printf("\tEigenvectors too: 5 for QR, 6 for BI, 7 for DC and 6 for MRRR\n");
    return EXIT_SUCCESS;
  } 

  /* allocate space for matrices, eigenvalues and eigenvectors */
  /* double *A = malloc(N * N * sizeof(double)); assert(A); */
  /* double *E = malloc(N * sizeof(double));   assert(E); */
  /* double *Q = malloc(N * N * sizeof(double)); assert(Q); */

  /* srand(0); */
  /* int j, k; */
  /* for (j = 0; j < N; ++j){ */
  /*   for (k = 0; k <= j; ++k){ */
  /*     A[N*j+k] = A[N*k+j] = 0; //(rand()%(100000*N)); */
  /*   } */
  /* } */

  /* for (j = 0; j < N/2; j++){ */
  /*   A[N*j+j] = N/2-j; */
  /* } */
  /* for (j = N/2; j < N; j++){ */
  /*   A[N*j+j] = j-N/2; */
  /* } */

  /* for (j = 0; j < N-1; j++){ */
  /*   A[N*j+j+1] = 1; */
  /* } */
  /* for (j = 1; j < N; j++){ */
  /*   A[N*j+j-1] = 1; */
  /* } */

  /* for (j = 0; j < N; j++){ */
  /*   for (k = 0; k < N; k++){ */
  /*     printf("%f  ", A[N*j+k]); */
  /*   } */
  /*   printf("\n"); */
  /* } */

  double *D = malloc(N * sizeof(double));   assert(D);
  double *E = malloc(N * sizeof(double));   assert(E);
  int j;
  /* srand(0); */
  for (j = 0; j < N; j++){
    D[j] = rand()%(1000000*N);
    E[j] = rand()%(1000000*N);
  }

  /* for (j = 0; j < N/2; j++){ */
  /*   D[j] = N/2-j; */
  /* } */
  /* for (j = N/2; j < N; j++){ */
  /*   D[j] = j-N/2; */
  /* } */
  /* for (j = 0; j < N; j++){ */
  /*     E[j] = 1; */
  /* } */

  int i, retval, native;
  const PAPI_hw_info_t *hwinfo;
  long long values[8];
  struct timeval t1, t2;

  if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
    printf("Erreur: PAPI_library_init\n");

  if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
    printf("Erreur: PAPI_create_eventset\n");

  if ((hwinfo = PAPI_get_hardware_info( )) == NULL)
    printf("Erreur: PAPI_get_hardware_info\n");

  /* printf("Architecture %s, %d\n", hwinfo->model_string, hwinfo->model); */

  for (i=0; native_name[i] != NULL; i++) {
    retval = PAPI_event_name_to_code(native_name[i], &native);
    if (retval != PAPI_OK)
      printf("Erreur: PAPI_event_name_to_code\n");
    if ((retval = PAPI_add_event(EventSet, native)) != PAPI_OK)
      printf("Erreur: PAPI_add_event\n");
  }

  if ((retval = PAPI_start(EventSet)) != PAPI_OK)
    printf("Erreur: PAPI_start\n");

  gettimeofday(&t1, NULL);

  /* functions to be measured */
  switch (method){
  case 1:
    printf("\nSolve using QR: eigenvalues only\n");
    solve_tridiag_qr(N, D, E, 'N');
    /* solve_entire_qr(N, A, E, Q, 'N'); */
    break;
  case 2:
    printf("\nSolve using BI: eigenvalues only\n");
    printf("Not in tridiagonal version\n");
    return EXIT_FAILURE;
    /* solve_tridiag_bi(N, D, E, 'N'); */
    /* solve_entire_bi(N, A, E, Q, 'N'); */
    break;
  case 3:
    printf("\nSolve using DC: eigenvalues only\n");
    solve_tridiag_dc(N, D, E, 'N');
    /* solve_entire_dc(N, A, E, Q, 'N'); */
    break;
  case 4:
    printf("\nSolve using MRRR: eigenvalues only\n");
    solve_tridiag_mr(N, D, E, 'N');
    /* solve_entire_mr(N, A, E, Q, 'N'); */
    break;
  case 5:
    printf("\nSolve using QR: eigenvalues and eigenvectors\n");
    solve_tridiag_qr(N, D, E, 'I');
    /* solve_entire_qr(N, A, E, Q, 'V'); */
    break;
  case 6:
    printf("\nSolve using BI: eigenvalues and eigenvectors\n");
    printf("Not in tridiagonal version\n");
    return EXIT_FAILURE;
    /* solve_tridiag_bi(N, D, E, 'I'); */
    /* solve_entire_bi(N, A, E, Q, 'V'); */
    break;
  case 7:
    printf("\nSolve using DC: eigenvalues and eigenvectors\n");
    solve_tridiag_dc(N, D, E, 'V');
    /* solve_entire_dc(N, A, E, Q, 'V'); */
    break;
  default:
    printf("\nSolve using MRRR: eigenvalues and eigenvectors\n");
    solve_tridiag_mr(N, D, E, 'V');
    /* solve_entire_mr(N, A, E, Q, 'V'); */
    break;
  }    

  gettimeofday(&t2, NULL);

  if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK)
    printf("Erreur: PAPI_stop\n");


  printf("Time %ld (us)\n", 1000000 * (t2.tv_sec-t1.tv_sec) + t2.tv_usec-t1.tv_usec);

  for (i=0; native_name[i] != NULL; i++) {
    fprintf(stderr, "%-40s: ", native_name[i]);
    fprintf(stderr, "values %lld\n", values[i]);
  }

  retval = PAPI_cleanup_eventset(EventSet);
  if (retval != PAPI_OK)
    printf("Erreur: PAPI_cleanup\n");
  retval = PAPI_destroy_eventset(&EventSet);
  if (retval != PAPI_OK)
    printf("Erreur: PAPI_destroy_eventset\n");

  free(D);
  free(E);
  exit(0);
}
Exemple #29
0
int
main( int argc, char **argv )
{
	int nthreads = 8, ret, i;
	PAPI_event_info_t info;
	pthread_t *threads;
	const PAPI_hw_info_t *hw_info;

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

	if ( !TESTS_QUIET ) {
		if ( argc > 1 ) {
			int tmp = atoi( argv[1] );
			if ( tmp >= 1 )
				nthreads = tmp;
		}
	}

	ret = PAPI_library_init( PAPI_VER_CURRENT );
	if ( ret != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
	}

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

	if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
		ret = PAPI_set_domain( PAPI_DOM_ALL );
		if ( ret != PAPI_OK ) {
			test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret );
		}
	}

	ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
	}

	ret = PAPI_multiplex_init(  );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret );
	}

	/* Fill up the event set with as many non-derived events as we can */

	i = PAPI_PRESET_MASK;
	do {
		if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
			if ( info.count == 1 ) {
				events[numevents++] = ( int ) info.event_code;
				printf( "Added %s\n", info.symbol );
			} else {
				printf( "Skipping derived event %s\n", info.symbol );
			}
		}
	} while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
			  && ( numevents < PAPI_MPX_DEF_DEG ) );

	printf( "Found %d events\n", numevents );

	do_stuff(  );

	printf( "Creating %d threads:\n", nthreads );

	threads =
		( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
	if ( threads == NULL ) {
		test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
	}

	/* Create the threads */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_create( &threads[i], NULL, thread, NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
		}
	}

	/* Wait for thread completion */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_join( threads[i], NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
		}
	}

	printf( "Done." );
	test_pass( __FILE__, NULL, 0 );
	pthread_exit( NULL );
	exit( 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);
}