Example #1
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;

   const PAPI_component_info_t *cmpinfo;

   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 ((cmpinfo = PAPI_get_component_info(0)) == NULL) 
     test_fail(__FILE__, __LINE__, "PAPI_get_component_info", retval);

   printf("name: %s\n",cmpinfo->name);
   printf("substrate_version: %s\n",cmpinfo->version);
   printf("support_version: %s\n",cmpinfo->support_version);
   printf("kernel_version: %s\n",cmpinfo->kernel_version);
   printf("num_cntrs: %d\n",cmpinfo->num_cntrs);
   printf("num_mpx_cntrs: %d\n",cmpinfo->num_mpx_cntrs);
   printf("num_preset_events: %d\n",cmpinfo->num_preset_events);           /* Number of counters the substrate supports */
   printf("num_native_events: %d\n",cmpinfo->num_native_events);           /* Number of counters the substrate supports */
   printf("default_domain: 0x%x (%s)\n",cmpinfo->default_domain,stringify_all_domains(cmpinfo->default_domain));
   printf("available_domains: 0x%x (%s)\n",cmpinfo->available_domains,stringify_all_domains(cmpinfo->available_domains));       /* Available domains */ 
   printf("default_granularity: 0x%x (%s)\n",cmpinfo->default_granularity,stringify_granularity(cmpinfo->default_granularity));
   /* The default granularity when this substrate is used */
   printf("available_granularities: 0x%x (%s)\n",cmpinfo->available_granularities,stringify_all_granularities(cmpinfo->available_granularities)); /* Available granularities */
   printf("itimer_sig: %d\n",cmpinfo->itimer_sig);     
   printf("itimer_num: %d\n",cmpinfo->itimer_num);     
   printf("itimer_ns: %d\n",cmpinfo->itimer_ns);      
   printf("itimer_res_ns: %d\n",cmpinfo->itimer_res_ns); 
   printf("hardware_intr_sig: %d\n",cmpinfo->hardware_intr_sig);      /* Width of opcode matcher if exists, 0 if not */
   printf("clock_ticks: %d\n",cmpinfo->clock_ticks);      
   printf("opcode_match_width: %d\n",cmpinfo->opcode_match_width);      /* Width of opcode matcher if exists, 0 if not */
/*   printf("reserved_ints[4]: %d\n",cmpinfo->reserved_ints[4]); */
   printf("hardware_intr: %d\n",cmpinfo->hardware_intr);         /* Needs hw overflow intr to be emulated in software*/
   printf("precise_intr: %d\n",cmpinfo->precise_intr);          /* Performance interrupts happen precisely */
   printf("posix1b_timers: %d\n",cmpinfo->posix1b_timers);          /* Performance interrupts happen precisely */
   printf("kernel_profile: %d\n",cmpinfo->kernel_profile);        /* Needs kernel profile support (buffered interrupts) to be emulated */
   printf("kernel_multiplex: %d\n",cmpinfo->kernel_multiplex);      /* In kernel multiplexing */
   printf("data_address_range: %d\n",cmpinfo->data_address_range);    /* Supports data address range limiting */
   printf("instr_address_range: %d\n",cmpinfo->instr_address_range);   /* Supports instruction address range limiting */
   printf("fast_counter_read: %d\n",cmpinfo->fast_counter_read);       /* Has a fast counter read */
   printf("fast_real_timer: %d\n",cmpinfo->fast_real_timer);       /* Has a fast real timer */
   printf("fast_virtual_timer: %d\n",cmpinfo->fast_virtual_timer);    /* Has a fast virtual timer */
   printf("attach: %d\n",cmpinfo->attach);    /* Has a fast virtual timer */
   printf("attach_must_ptrace: %d\n",cmpinfo->attach_must_ptrace);    /* Has a fast virtual timer */
   printf("edge_detect: %d\n",cmpinfo->edge_detect);    /* Has a fast virtual timer */
   printf("invert: %d\n",cmpinfo->invert);    /* Has a fast virtual timer */
   printf("profile_ear: %d\n",cmpinfo->profile_ear);     /* Supports data/instr/tlb miss address sampling */
   printf("cntr_groups: %d\n",cmpinfo->cntr_groups);           /* Underlying hardware uses counter groups */
   printf("cntr_umasks: %d\n",cmpinfo->cntr_umasks);           /* counters have unit masks */
   printf("cntr_IEAR_events: %d\n",cmpinfo->cntr_IEAR_events);      /* counters support instr event addr register */
   printf("cntr_DEAR_events: %d\n",cmpinfo->cntr_DEAR_events);      /* counters support data event addr register */
   printf("cntr_OPCM_events: %d\n",cmpinfo->cntr_OPCM_events);      /* counter events support opcode matching */

   test_pass(__FILE__, NULL, 0);
   exit(0);
}
Example #3
0
int main (int argc, char **argv)
{
    int retval,cid,numcmp;
    int EventSet = PAPI_NULL;
    long long value;
    int code;
    char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN];
    int event_codes[MAX_EVENTS];
    long long event_values[MAX_EVENTS];
    int total_events=0; /* events added so far */
    int r;
    const PAPI_component_info_t *cmpinfo = NULL;

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

    /* PAPI Initialization */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
    }

    if (!TESTS_QUIET) {
        printf("Trying all appio events\n");
    }

    numcmp = PAPI_num_components();

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

        if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
            test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
        }

        if (!TESTS_QUIET) {
            printf("Component %d - %d events - %s\n", cid,
                cmpinfo->num_native_events, cmpinfo->name);
        }

        if ( strstr(cmpinfo->name, "appio") == NULL) {
            continue;
        }

        code = PAPI_NATIVE_MASK;

        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
        /* Create and populate the EventSet */
        EventSet = PAPI_NULL;

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

        while ( r == PAPI_OK ) {

            retval = PAPI_event_code_to_name( code, event_names[total_events] );
            if ( retval != PAPI_OK ) {
                test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
            }
            
            if (!TESTS_QUIET) {
              printf("Added event %s (code=%#x)\n", event_names[total_events], code);
            }
            event_codes[total_events++] = code;
            r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
        }

    }

    int fdin,fdout;
    const char* infile = "/etc/group";
    printf("This program will read %s and write it to /dev/null\n", infile);
    int bytes = 0;
    char buf[1024];

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

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

    fdin=open(infile, O_RDONLY);
    if (fdin < 0) perror("Could not open file for reading: \n");
    fdout = open("/dev/null", O_WRONLY);
    if (fdout < 0) perror("Could not open /dev/null for writing: \n");

    while ((bytes = read(fdin, buf, 1024)) > 0) {
      write(fdout, buf, bytes);
    }

    retval = PAPI_stop( EventSet, event_values );
    if (retval != PAPI_OK) {
        test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
    }
    close(fdin);
    close(fdout);

    int i;
    if (!TESTS_QUIET) {
        for ( i=0; i<total_events; i++ ) {
            printf("%#x %-24s = %lld\n",
                event_codes[i], event_names[i], event_values[i]);
        }
    }

    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 (total_events==0) {
        test_skip(__FILE__,__LINE__,"No appio events found", 0);
    }

    test_pass( __FILE__, NULL, 0 );

    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);
    }
    return 0;
}
Example #4
0
int main (int argc, char **argv)
{

    int retval,cid,rapl_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long *values;
    int num_events=0;
    int code;
    char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
    char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
    int r,i;
    const PAPI_component_info_t *cmpinfo = NULL;
    PAPI_event_info_t evinfo;
    long long before_time,after_time;
    double elapsed_time;

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

	/* PAPI Initialization */
     retval = PAPI_library_init( PAPI_VER_CURRENT );
     if ( retval != PAPI_VER_CURRENT ) {
	test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
     }

     if (!TESTS_QUIET) {
	printf("Trying all RAPL events\n");
     }

     numcmp = PAPI_num_components();

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

	if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	   test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	}

	if (strstr(cmpinfo->name,"rapl")) {

	   rapl_cid=cid;

	   if (!TESTS_QUIET) {
	      printf("Found rapl component at cid %d\n",rapl_cid);
	   }

           if (cmpinfo->disabled) {
	      if (!TESTS_QUIET) {
		 printf("RAPL component disabled: %s\n",
                        cmpinfo->disabled_reason);
	      } 
              test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
           }
	   break;
	}
     }

     /* Component not found */
     if (cid==numcmp) {
       test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
     }

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

     /* Add all events */

     code = PAPI_NATIVE_MASK;

     r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );

     while ( r == PAPI_OK ) {

        retval = PAPI_event_code_to_name( code, event_names[num_events] );
	if ( retval != PAPI_OK ) {
	   printf("Error translating %#x\n",code);
	   test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	}

	retval = PAPI_get_event_info(code,&evinfo);
	if (retval != PAPI_OK) {
	  test_fail( __FILE__, __LINE__,
             "Error getting event info\n",retval);
	}
	
	strncpy(units[num_events],evinfo.units,PAPI_MIN_STR_LEN);

        retval = PAPI_add_event( EventSet, code );
        if (retval != PAPI_OK) {
	  break; /* We've hit an event limit */
	}
	num_events++;
  	      
        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
     }

     values=calloc(num_events,sizeof(long long));
     if (values==NULL) {
	test_fail(__FILE__, __LINE__, 
                              "No memory",retval);
     }

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

     /* Start Counting */
     before_time=PAPI_get_real_nsec();
     retval = PAPI_start( EventSet);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     /* Run test */
     run_test(TESTS_QUIET);

     /* Stop Counting */
     after_time=PAPI_get_real_nsec();
     retval = PAPI_stop( EventSet, values);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     elapsed_time=((double)(after_time-before_time))/1.0e9;

     if (!TESTS_QUIET) {
        printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
	       elapsed_time);

	printf("Energy measurements:\n");

	for(i=0;i<num_events;i++) {
	   if (strstr(units[i],"nJ")) {

	      printf("%s\t%.6fJ\t(Average Power %.1fW)\n",
		    event_names[i],
		    (double)values[i]/1.0e9,
		    ((double)values[i]/1.0e9)/elapsed_time);
	   }
	}

	printf("\n");
	printf("Fixed values:\n");

	for(i=0;i<num_events;i++) {
	   if (!strstr(units[i],"nJ")) {

	     union {
	       long long ll;
	       double fp;
	     } result;

	     result.ll=values[i];

	      printf("%s\t%0.3f%s\n",
		    event_names[i],
		    result.fp,
		    units[i]);
	   }
	}

     }

     /* Done, clean up */
     retval = PAPI_cleanup_eventset( EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_cleanup_eventset()",retval);
     }

     retval = PAPI_destroy_eventset( &EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_destroy_eventset()",retval);
     }
        
     test_pass( __FILE__, NULL, 0 );
		
     return 0;
}
int main (int argc, char **argv)
{
    int retval,cid,rapl_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long values[MAX_EVENTS];
    int i,code,enum_retval;
    const PAPI_component_info_t *cmpinfo = NULL;
    long long start_time,write_start_time,write_end_time,read_start_time,read_end_time;
    char event_name[BUFSIZ];
    union { long long ll; double dbl; } event_value_union;
    static int num_events=0;
    FILE *fileout;
    
    /* PAPI Initialization */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        fprintf(stderr,"PAPI_library_init failed\n");
	exit(1);
    }
    
    /* Find the libmsr component */
    numcmp = PAPI_num_components();
    for(cid=0; cid<numcmp; cid++) {
	if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
            fprintf(stderr,"PAPI_get_component_info failed\n");
            exit(1);
	}
	if (strstr(cmpinfo->name,"libmsr")) {
            rapl_cid=cid;
            printf("Found libmsr component at cid %d\n", rapl_cid);
            if (cmpinfo->disabled) {
                fprintf(stderr,"No libmsr events found: %s\n", cmpinfo->disabled_reason);
                exit(1);
            }
            break;
	}
    }

    /* Component not found */    
    if (cid==numcmp) {
        fprintf(stderr,"No libmsr component found\n");
        exit(1);
    }
    
    /* Find events in the component */
    code = PAPI_NATIVE_MASK;
    enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
    while ( enum_retval == PAPI_OK ) {
        retval = PAPI_event_code_to_name( code, event_name );
        if ( retval != PAPI_OK ) {
            printf("Error translating %#x\n",code);
            exit(1);
        }
        printf("Found: %s\n",event_name);
        strncpy(events[num_events],event_name,BUFSIZ);
        sprintf(filenames[num_events],"results.%s",event_name);
        num_events++;
        if (num_events==MAX_EVENTS) {
            printf("Too many events! %d\n",num_events);
            exit(1);
        }
        enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
    }
    if (num_events==0) {
        printf("Error!  No libmsr events found!\n");
	exit(1);
    }
    
    /* Open output file */
    char fileoutname[]="libmsr_write_test_output.txt";
    fileout=fopen( fileoutname ,"w" );
    if ( fileout==NULL) { fprintf( stderr,"Could not open %s\n",fileoutname ); exit(1); }

    /* Create EventSet */
    retval = PAPI_create_eventset( &EventSet );
    if (retval != PAPI_OK) {
        fprintf(stderr,"Error creating eventset!\n");
    }
    
    for(i=0;i<num_events;i++) {
        retval = PAPI_add_named_event( EventSet, events[i] );
        if (retval != PAPI_OK) fprintf(stderr,"Error adding event %s\n",events[i]); 
    }
    
    start_time=PAPI_get_real_nsec();
    
    /* Grab the initial values for the events */
    retval = PAPI_start( EventSet);
    if (retval != PAPI_OK) { fprintf(stderr,"PAPI_start() failed\n"); exit(1); }
    /* Initial checking read */
    retval = PAPI_read( EventSet, values);
    if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); }

    /* Write a header line */
    fprintf( fileout, "ACTION TIME-STAMP TIME-FOR-UNIT-WORK TIME-OVERHEAD-RW\t" );
    for(i=0; i<num_events; i++) 
        fprintf( fileout, "%s ", events[i]+9 );
    fprintf( fileout, "\n" );

    /* Read the initial values */
    retval = PAPI_read( EventSet, values);
    if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); }
    fprintf( fileout, "INIT %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 );
    fprintf( fileout, "%8.3e ", 0.0);
    for(i=0; i<num_events; i++) {
        event_value_union.ll = values[i];
        fprintf( fileout, "%8.3f ", event_value_union.dbl );
    }
    fprintf( fileout, "\n" );

    int rpt=0;
    int limit1base=10;
    int limit2base=10;
    while(rpt++<200) {
        //printf("rpt %d\n", rpt);
        
        if ( rpt % 10 == 0 )  {
            for (i=0; i<num_events; i++) {
                event_value_union.ll = values[i];
                if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=limit1base+(rpt/2);
                else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=1.0;
                else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=limit2base+(rpt/2);
                else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=1.0;
                else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=limit1base+(rpt/2);
                else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=1.0;
                else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=limit2base+(rpt/2);
                else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=1.0;
                else event_value_union.dbl=PAPI_NULL;
                values[i]=event_value_union.ll;
            }

            write_start_time=PAPI_get_real_nsec();
            retval = PAPI_write( EventSet, values );
            write_end_time=PAPI_get_real_nsec();
            if (retval != PAPI_OK) { fprintf(stderr,"PAPI_write() failed\n"); exit(1); }

            fprintf( fileout, "SET  %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 );
            fprintf( fileout, "%8.3e ", ((double)(write_end_time-write_start_time))/1.0e9 );
            for(i=0; i<num_events; i++) {
                event_value_union.ll = values[i];
                fprintf( fileout, "%8.3f ", event_value_union.dbl );
            }
            fprintf( fileout, "\n" );
        }
        
        /* DO SOME WORK TO USE ENERGY */
        //usleep(100000);
        double work_start_time=PAPI_get_real_nsec();
        ompcpuloadprimes( 100000 );
        double work_time=PAPI_get_real_nsec()-work_start_time;
        //printf("primescount %d\n", primescount);
        
        /* Read and output the values */
        read_start_time=PAPI_get_real_nsec();
        retval = PAPI_read( EventSet, values );
        read_end_time=PAPI_get_real_nsec();
        if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); }
        fprintf( fileout, "READ %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, work_time/1.0e9 );
        fprintf( fileout, "%8.3e ", ((double)(read_end_time-read_start_time))/1.0e9 );
        for(i=0; i<num_events; i++) {
            event_value_union.ll = values[i];
            fprintf( fileout, "%8.3f ", event_value_union.dbl );
        }
        fprintf( fileout, "\n" );
    }

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

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

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

	hw_info = PAPI_get_hardware_info(  );
	if ( hw_info == NULL ) {
	   test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval );
	}

        numcmp = PAPI_num_components(  );

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

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

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

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

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

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

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

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

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

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

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

	num_flops = NUM_FLOPS * 2;

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

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

	do_flops( num_flops );

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

	/* done with initial test */

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

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

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

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

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

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

	if ( !TESTS_QUIET ) {

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

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

	/* validation */

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

	if (!TESTS_QUIET) {

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

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

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

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

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

	free( ovt );
	for ( i = 0; i < num_events; i++ )
		free( names[i] );
	free( names );
	free( events );
	free( values );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main( int argc, char **argv ) {

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

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

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

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

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

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

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

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

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

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

   PAPI_cpu_option_t cpu_opt;

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

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

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

   PAPI_granularity_option_t gran_opt;

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

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

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

   PAPI_domain_option_t domain_opt;

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

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

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

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


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

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

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

   /* Stop PAPI */
   retval = PAPI_stop( EventSet, values );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }
   retval = PAPI_stop( EventSet2, values2 );
   if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
   }

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

   test_pass( __FILE__, NULL, 0 );

   return 0;
}
Example #8
0
int
main( int argc, char **argv )
{
	
    int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0;
    int retval;
    PAPI_event_info_t info, info1;
    const PAPI_hw_info_t *hwinfo = NULL;
    const PAPI_component_info_t* cmpinfo;
    char *Intel_i7;
    int event_code;
    int numcmp, cid;

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

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

    retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available "
				"native events and hardware "
				"information.\n",
				&hwinfo );
    if ( retval != PAPI_OK ) {
       test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
    }

    numcmp = PAPI_num_components(  );

    /* we need a little exception processing if it's a Core i7 */
    /* Unfortunately, this test never succeeds... */
    Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" );

    /* Loop through all components */
    for( cid = 0; cid < numcmp; cid++ ) {


       cmpinfo = PAPI_get_component_info( cid );

        if (cmpinfo  == NULL)
        {
           test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );
        }

        if (cmpinfo->disabled)
        {
          printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
          printf("   \\-> Disabled: %s\n",cmpinfo->disabled_reason);
          continue;
        }



       /* 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;
       retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );

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

	  /* Skip OFFCORE and UNCORE events  */
	  /* Adding them will fail currently */
	  if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) {
	     if ( !strncmp( info.symbol, "UNC_", 4 ) ) {
		unc_count++;
		continue;
	     }
	     if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) {
		offcore_count++;
		continue;
	     }
	  }

	  /* Enumerate all umasks */
	  k = i;
	  if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) {
	     do {
		retval = PAPI_get_event_info( k, &info1 );
		event_code = ( int ) info1.event_code;
		if ( check_event( event_code, info1.symbol ) ) {
		   add_count++;
		}
		else {
		   err_count++;
		}
	     } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK );
	  } else {
	    /* Event didn't have any umasks */
	    event_code = ( int ) info.event_code;
	    if ( check_event( event_code, info.symbol ) ) {
	       add_count++;
	    }
	    else {
	       err_count++;
	    }
	  }
	  
       } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK );

    }
    printf( "\n\nSuccessfully found and added %d events "
            "(in %d eventsets).\n",
	    add_count , add_count);

    if ( err_count ) {
       printf( "Failed to add %d events.\n", err_count );
    }

    if (( unc_count ) || (offcore_count)) {
       char warning[BUFSIZ];
       sprintf(warning,"%d Uncore and %d Offcore events were ignored",
		   unc_count,offcore_count);
       test_warn( __FILE__, __LINE__, warning, 1 );
    }

    if ( add_count > 0 ) {
       test_pass( __FILE__, NULL, 0 );
    }
    else {
       test_fail( __FILE__, __LINE__, "No events added", 1 );
    }

    exit( 1 );
}
Example #9
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;
}
Example #10
0
int main (int argc, char **argv)
{

    int retval,cid,rapl_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long values[MAX_EVENTS];
    int i,code,enum_retval;
    const PAPI_component_info_t *cmpinfo = NULL;
    long long start_time,before_time,after_time;
    double elapsed_time,total_time;
    char event_name[BUFSIZ];

	/* PAPI Initialization */
     retval = PAPI_library_init( PAPI_VER_CURRENT );
     if ( retval != PAPI_VER_CURRENT ) {
        fprintf(stderr,"PAPI_library_init failed\n");
	exit(1);
     }

     numcmp = PAPI_num_components();

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

	if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	   fprintf(stderr,"PAPI_get_component_info failed\n");
	   exit(1);
	}

	if (strstr(cmpinfo->name,"rapl")) {
	   rapl_cid=cid;
	   printf("Found rapl component at cid %d\n", rapl_cid);

           if (cmpinfo->disabled) {
	     fprintf(stderr,"No rapl events found: %s\n",
		     cmpinfo->disabled_reason);
	     exit(1);
           }
	   break;
	}
     }

     /* Component not found */
     if (cid==numcmp) {
        fprintf(stderr,"No rapl component found\n");
        exit(1);
     }

     /* Find Events */
     code = PAPI_NATIVE_MASK;

     enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );

     while ( enum_retval == PAPI_OK ) {

       retval = PAPI_event_code_to_name( code, event_name );
       if ( retval != PAPI_OK ) {
	  printf("Error translating %#x\n",code);
	  exit(1);
       }

       printf("Found: %s\n",event_name);
       strncpy(events[num_events],event_name,BUFSIZ);
       sprintf(filenames[num_events],"results.%s",event_name);
       num_events++;
       
       if (num_events==MAX_EVENTS) {
	  printf("Too many events! %d\n",num_events);
	  exit(1);
       }

       enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );

     }

     if (num_events==0) {
        printf("Error!  No RAPL events found!\n");
	exit(1);
     }

     /* Open output files */
     for(i=0;i<num_events;i++) {
        fff[i]=fopen(filenames[i],"w");
	if (fff[i]==NULL) {
	   fprintf(stderr,"Could not open %s\n",filenames[i]);
	   exit(1);
	}
     }
				   

     /* Create EventSet */
     retval = PAPI_create_eventset( &EventSet );
     if (retval != PAPI_OK) {
        fprintf(stderr,"Error creating eventset!\n");
     }

     for(i=0;i<num_events;i++) {
	
        retval = PAPI_add_named_event( EventSet, events[i] );
        if (retval != PAPI_OK) {
	   fprintf(stderr,"Error adding event %s\n",events[i]);
	}
     }

  

     start_time=PAPI_get_real_nsec();

     while(1) {

        /* Start Counting */
        before_time=PAPI_get_real_nsec();
        retval = PAPI_start( EventSet);
        if (retval != PAPI_OK) {
           fprintf(stderr,"PAPI_start() failed\n");
	   exit(1);
        }


        usleep(100000);

        /* Stop Counting */
        after_time=PAPI_get_real_nsec();
        retval = PAPI_stop( EventSet, values);
        if (retval != PAPI_OK) {
           fprintf(stderr, "PAPI_start() failed\n");
        }

        total_time=((double)(after_time-start_time))/1.0e9;
        elapsed_time=((double)(after_time-before_time))/1.0e9;

        for(i=0;i<num_events;i++) {

	   fprintf(fff[i],"%.4f %.1f (* Average Power for %s *)\n",
		   total_time,
		   ((double)values[i]/1.0e9)/elapsed_time,
		   events[i]);
	   fflush(fff[i]);
        }
     }
		
     return 0;
}
Example #11
0
int main (int argc, char **argv)
{

    int retval,cid,coretemp_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long values[NUM_EVENTS];
    int code;
    char event_name[PAPI_MAX_STR_LEN];
    int r;
    const PAPI_component_info_t *cmpinfo = NULL;
    PAPI_event_info_t evinfo;
    double temperature;

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

	/* PAPI Initialization */
     retval = PAPI_library_init( PAPI_VER_CURRENT );
     if ( retval != PAPI_VER_CURRENT ) {
	test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
     }

     if (!TESTS_QUIET) {
	printf("Trying all coretemp events\n");
     }

     numcmp = PAPI_num_components();

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

	if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	   test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	}

	if (strstr(cmpinfo->name,"linux-coretemp")) {
	   coretemp_cid=cid;
	   if (!TESTS_QUIET) printf("Found coretemp component at cid %d\n",
				    coretemp_cid);
           if (cmpinfo->num_native_events==0) {
              test_skip(__FILE__,__LINE__,"No coretemp events found",0);
           }
	   break;
	}
     }




     code = PAPI_NATIVE_MASK;

     r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid );

     while ( r == PAPI_OK ) {

        retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK ) {
	   printf("Error translating %x\n",code);
	   test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	}

	retval = PAPI_get_event_info(code,&evinfo);
	if (retval != PAPI_OK) {
	  test_fail( __FILE__, __LINE__,
             "Error getting event info\n",retval);
	}

	   /****************************/
	   /* Print Temperature Inputs */
	   /****************************/
	if (strstr(event_name,"temp")) {
	  
	     /* Only print inputs */
	  if (strstr(event_name,"_input")) {

	     if (!TESTS_QUIET) printf("%s ",event_name);

             EventSet = PAPI_NULL;

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

             retval = PAPI_add_event( EventSet, code );
             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);
	     }

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

	     temperature=(values[0]/1000.0);

             if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
				      temperature,
				      evinfo.long_descr
				      );

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

	   /****************************/
	   /* Print Voltage Inputs */
	   /****************************/
	if (strstr(event_name,".in")) {
	  
	     /* Only print inputs */
	  if (strstr(event_name,"_input")) {

	     if (!TESTS_QUIET) printf("%s ",event_name);

             EventSet = PAPI_NULL;

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

             retval = PAPI_add_event( EventSet, code );
             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);
	     }

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

	     temperature=(values[0]/1000.0);

             if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
				      temperature,
				      evinfo.long_descr
				      );

	     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);
	     }
	  }
	}
	/********************/
	/* Print Fan Inputs */
	/********************/
	else if (strstr(event_name,"fan")) {

	     /* Only print inputs */
	  if (strstr(event_name,"_input")) {
           
             if (!TESTS_QUIET) printf("%s ",event_name);

             EventSet = PAPI_NULL;

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

             retval = PAPI_add_event( EventSet, code );
             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);
	     }

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

             if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0],
				      evinfo.long_descr);

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

	}
	else {
	  /* Skip unknown */
	}
  	      
        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid );
     }
        
     test_pass( __FILE__, NULL, 0 );
		
     return 0;
}
int
main( int argc, char **argv )
{
	
    int i;
    int retval;
    PAPI_event_info_t info;
    int numcmp, cid, our_cid;
    const PAPI_component_info_t* cmpinfo;

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

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

    numcmp = PAPI_num_components(  );


    /* Loop through all components */
    for( cid = 0; cid < numcmp; cid++ )
    {
        cmpinfo = PAPI_get_component_info( cid );

         if (cmpinfo  == NULL)
         {
            test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );
         }

         if (cmpinfo->disabled && !TESTS_QUIET) {
           printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
           printf("   \\-> Disabled: %s\n",cmpinfo->disabled_reason);
           continue;
         }


       i = 0 | PAPI_NATIVE_MASK;
       retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );
       if (retval!=PAPI_OK) continue;

       do {
	   if (PAPI_get_event_info( i, &info ) != PAPI_OK) {
	       if (!TESTS_QUIET) {
		   printf("Getting information about event: %#x failed\n", i);
	       }
	       continue;
	   }
	  our_cid=PAPI_get_event_component(i);

	  if (our_cid!=cid) {
	     if (!TESTS_QUIET) {
	        printf("%d %d %s\n",cid,our_cid,info.symbol);
	     }
             test_fail( __FILE__, __LINE__, "component mismatch", 1 );
	  }

	  if (!TESTS_QUIET) {
	    printf("%d %d %s\n",cid,our_cid,info.symbol);
	  }

	  
       } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK );

    }

    test_pass( __FILE__, NULL, 0 );
   
    return 0;
}
Example #13
0
int
main( int argc, char **argv )
{
	int i, k, add_count = 0, err_count = 0, 
            unc_count = 0, offcore_count = 0;
	int retval;
	PAPI_event_info_t info, info1;
	const PAPI_hw_info_t *hwinfo = NULL;
	char *Intel_i7;
	int event_code;
	const PAPI_component_info_t *s = NULL;
	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 );
	}

	retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available "
				    "native events and hardware "
				    "information.\n",
				    0, &hwinfo );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
	}

	numcmp = PAPI_num_components(  );

	/* we need a little exception processing if it's a Core i7 */
	/* Unfortunately, this test never succeeds... */
	Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" );

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

		if ( ( s = PAPI_get_component_info( cid ) ) == NULL )
			test_fail( __FILE__, __LINE__, "PAPI_get_substrate_info", 2 );

		/* 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_COMPONENT_MASK( cid );
		PAPI_enum_event( &i, PAPI_ENUM_FIRST );

		do {
			retval = PAPI_get_event_info( i, &info );
			if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) {
				if ( !strncmp( info.symbol, "UNC_", 4 ) ) {
					unc_count++;
					continue;
				}
				if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) {
				        offcore_count++;
					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, &info1 );
						event_code = ( int ) info1.event_code;
						if ( check_event
							 ( event_code, info1.symbol ) )
							add_count++;
						else
							err_count++;
					} while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) ==
							  PAPI_OK );
				} else {
					event_code = ( int ) info.event_code;
					if ( check_event( event_code, info.symbol ) )
						add_count++;
					else
						err_count++;
				}
			} else {
				event_code = ( int ) info.event_code;
				if ( s->cntr_groups )
					event_code &= ~PAPI_NTV_GROUP_AND_MASK;
				if ( check_event( event_code, info.symbol ) )
					add_count++;
				else
					err_count++;
			}
		} while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK );

	}
	printf( "\n\nSuccessfully found and added %d events (in %d eventsets).\n",
			add_count , add_count);
	if ( err_count )
		printf( "Failed to add %d events.\n", err_count );
	if (( unc_count ) || (offcore_count)) {
	   char warning[BUFSIZ];
	   sprintf(warning,"%d Uncore and %d Offcore events were ignored",
		   unc_count,offcore_count);
	   test_warn( __FILE__, __LINE__, warning, 1 );
	}
	if ( add_count > 0 )
		test_pass( __FILE__, NULL, 0 );
	else
		test_fail( __FILE__, __LINE__, "No events added", 1 );
	exit( 1 );
}
Example #14
0
void init_energy(pwr_ctx_t *ctx) {
    char buf[1024] = { '\0' };
    int ret, num_comp, cid, code = 0;
    const PAPI_component_info_t *comp_info = NULL;
    PAPI_event_info_t evinfo;

    assert(ctx != NULL);
    assert(pwr_is_initialized(ctx, PWR_MODULE_STRUCT));
    assert(!pwr_is_initialized(ctx, PWR_MODULE_ENERGY));

    // Initialize PAPI
    if ( !PAPI_is_initialized() ) {
        ret = PAPI_library_init(PAPI_VER_CURRENT);
        if (PAPI_VER_CURRENT != ret ) {
            PAPI_shutdown();
            if (ctx->err_fd) {
                fprintf(ctx->err_fd, "Unexpected PAPI version\n");
            }
            ctx->error = PWR_ARCH_UNSUPPORTED;
            return;
        }
    }

    // Search PAPI components for RAPL (Intel energy counting) events
    num_comp = PAPI_num_components();

    for (cid = 0; cid < num_comp; ++cid) {
        comp_info = PAPI_get_component_info(cid);
        if (NULL == comp_info) {
            PAPI_shutdown();
            if (ctx->err_fd) {
                fprintf(ctx->err_fd, "Invalid PAPI module found\n");
            }
            ctx->error = PWR_INIT_ERR;
            return;
        }
        if (strstr(comp_info->name, "rapl")) {
            if (0 == comp_info->num_native_events) {
                PAPI_shutdown();
                if (ctx->err_fd) {
                    fprintf(ctx->err_fd, "RAPL counters not available\n");
                }
                ctx->error = PWR_UNAVAILABLE;
                return;
            }
            break;
        }
    }

    if (cid == num_comp) {
        if (ctx->err_fd) {
            fprintf(ctx->err_fd, "Cannot find RAPL module in PAPI\n");
        }
        ctx->error = PWR_UNAVAILABLE;
        return;
    }

    // Create PAPI event set
    ctx->event_set = PAPI_NULL;
    ret = PAPI_create_eventset(&ctx->event_set);
    if (PAPI_OK != ret) {
        PAPI_shutdown();
        if (ctx->err_fd) {
            fprintf(ctx->err_fd, "Failed to create a PAPI event set\n");
        }
        ctx->error = PWR_INIT_ERR;
        return;
    }

    // count how many counters can be added
    ctx->emeas = malloc(sizeof(*ctx->emeas));
    ctx->emeas->nbValues = 0;
    for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) {
        snprintf(buf, 1024, "PACKAGE_ENERGY:PACKAGE%d", i);
        ret = PAPI_query_named_event(buf);
        if (PAPI_OK != ret) {
            break;
        }
        ++ctx->emeas->nbValues;
    }
    for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) {
        snprintf(buf, 1024, "DRAM_ENERGY:PACKAGE%d", i);
        ret = PAPI_query_named_event(buf);
        if (PAPI_OK != ret) {
            break;
        }
        ++ctx->emeas->nbValues;
    }

    ctx->emeas->values = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->values));
    ctx->emeas->units = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->units));
    ctx->emeas->names = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->names));

    // fetch the counter information
    unsigned int cpt_i = 0;
    for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) {
        snprintf(buf, 1024, "PACKAGE_ENERGY:PACKAGE%d", i);
        ret = PAPI_query_named_event(buf);
        if (PAPI_OK != ret) {
            break;
        }

        ret = PAPI_add_named_event(ctx->event_set, buf);
        PAPI_event_name_to_code(buf, &code);
        PAPI_get_event_info(code, &evinfo);
        ctx->emeas->units[cpt_i] = strdup(evinfo.units);
        ctx->emeas->names[cpt_i] = strdup(buf);
        ++cpt_i;
    }

    // same for DRAM
    for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) {
        snprintf(buf, 1024, "DRAM_ENERGY:PACKAGE%d", i);
        ret = PAPI_query_named_event(buf);
        if (PAPI_OK != ret) {
            break;
        }

        ret = PAPI_add_named_event(ctx->event_set, buf);
        PAPI_event_name_to_code(buf, &code);
        PAPI_get_event_info(code, &evinfo);
        ctx->emeas->units[cpt_i] = strdup(evinfo.units);
        ctx->emeas->names[cpt_i] = strdup(buf);
        ++cpt_i;
    }

    ctx->emeas_running = false;
    ctx->error = PWR_OK;
    ctx->module_init |= (1U << PWR_MODULE_ENERGY);

    return;
}
Example #15
0
int
native(  )
{
	int i, j, k;
	int retval, added;
	const PAPI_component_info_t *c = NULL;
	PAPI_event_info_t info;

	j = 0;
	c = PAPI_get_component_info( 0 );

	/* 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 {
		/* If unit masks are supported, perfmon requires that at least one
		   mask bit be set before adding the event.
		 */
		if ( c->cntr_umasks ) {
			k = i;
			/* modifier = PAPI_NTV_ENUM_UMASKS returns an event code for each
			   unit mask bit defined for this native event. This can be used
			   to get event info for that mask bit. It terminates
			   with PAPI_ENOEVNT at the end of the list.
			 */
			if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
				if ( ( added = add_remove_event( EventSet, k ) ) == PAPI_OK ) {
					show_event_info( i );
					do {
						retval = PAPI_get_event_info( k, &info );
						if ( retval == PAPI_OK ) {
							printf( "    0x%-10x%s  |%s|\n", info.event_code,
									strchr( info.symbol, ':' ),
									strchr( info.long_descr, ':' ) + 1 );
						}
					} while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) ==
							  PAPI_OK );
					j++;
				}
			} else {
				if ( ( added = add_remove_event( EventSet, i ) ) == PAPI_OK ) {
					show_event_info( i );
					j++;
				}
			}
		} else {
			if ( ( added = add_remove_event( EventSet, i ) ) == PAPI_OK ) {
				show_event_info( i );
				j++;
			}
		}
		if ( added == PAPI_OK ) {
			/* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
			   groups id for each group in which this
			   native event lives, in bits 16 - 23 of event code
			   terminating with PAPI_ENOEVNT at the end of the list.
			 */
			if ( c->cntr_groups ) {
				k = i;
				if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) {
					printf( "Groups: " );
					do {
						printf( "%4d",
								( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
								  PAPI_NTV_GROUP_SHIFT ) - 1 );
					} while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==
							  PAPI_OK );
					printf( "\n" );
				}
			}
			printf
				( "-------------------------------------------------------------------------\n" );
		}
Example #16
0
int main (int argc, char **argv)
{

        int retval,cid,numcmp;
	int EventSet = PAPI_NULL;
	long long values[NUM_EVENTS];
	int code;
	char event_name[PAPI_MAX_STR_LEN];
	int total_events=0;
	int r;
	const PAPI_component_info_t *cmpinfo = NULL;

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

	/* PAPI Initialization */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
	}

	if (!TESTS_QUIET) {
	   printf("Trying all vmware events\n");
	}

	/* Find our Component */
	
        numcmp = PAPI_num_components();

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

	   if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	      test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	   }

	   if (strstr(cmpinfo->name,"vmware")) {
	     if (!TESTS_QUIET) printf("\tFound vmware component %d - %s\n", cid, cmpinfo->name);
	   }
	   else {
	     continue;
	   }

	   PAPI_event_info_t info;

	   /* Try all events one by one */

	   code = PAPI_NATIVE_MASK;

           r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );

	   while ( r == PAPI_OK ) {

	      retval=PAPI_get_event_info(code,&info);
	      if (retval!=PAPI_OK) {
		 printf("Error getting event info\n");
	         test_fail( __FILE__, __LINE__, 
                            "PAPI_get_event_info", retval );
	      }

	      retval = PAPI_event_code_to_name( code, event_name );
	      if ( retval != PAPI_OK ) {
		 printf("Error translating %x\n",code);
	         test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	      }

	      if (!TESTS_QUIET) printf("  %s ",event_name);
	     
	      EventSet = PAPI_NULL;

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

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

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

	      /* do something */
	      usleep(100);

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

	      if (!TESTS_QUIET) printf(" value: %lld %s\n",values[0],
				       info.units);

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

	      total_events++;
	      
	      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
	   }
        }

	if (total_events==0) {
	   test_skip(__FILE__,__LINE__,"No vmware events found",0);
	}

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

	test_pass( __FILE__, NULL, 0 );
		
	return 0;
}
Example #17
0
int main (int argc, char **argv)
{

        int retval,i;
	int EventSet = PAPI_NULL;
	long long values[NUM_EVENTS];
	const PAPI_component_info_t *cmpinfo = NULL;
	int numcmp,cid,example_cid=-1;
	int code,maximum_code=0;
	char event_name[PAPI_MAX_STR_LEN];
	PAPI_event_info_t event_info;

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

	/* PAPI Initialization */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
	}

	if (!TESTS_QUIET) {
	   printf( "Testing example component with PAPI %d.%d.%d\n",
			PAPI_VERSION_MAJOR( PAPI_VERSION ),
			PAPI_VERSION_MINOR( PAPI_VERSION ),
			PAPI_VERSION_REVISION( PAPI_VERSION ) );
	}

	/* Find our component */

	numcmp = PAPI_num_components();
	for( cid=0; cid<numcmp; cid++) {
	   if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	      test_fail(__FILE__, __LINE__,
                           "PAPI_get_component_info failed\n", 0);
	   }
	   if (!TESTS_QUIET) {
	      printf("\tComponent %d - %d events - %s\n", cid, 
		     cmpinfo->num_native_events,
		     cmpinfo->name);
	   }
	   if (strstr(cmpinfo->name,"example.c")) {
	      /* FOUND! */
	      example_cid=cid;
	   }
	}
	

	if (example_cid<0) {
	   test_skip(__FILE__, __LINE__,
		     "Example component not found\n", 0);
	}

	if (!TESTS_QUIET) {
	  printf("\nFound Example Component at id %d\n",example_cid);
	  printf("\nListing all events in this component:\n");
	}

	/**************************************************/
	/* Listing all available events in this component */
	/* Along with descriptions                        */
	/**************************************************/
	code = PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK(example_cid);

	retval = PAPI_enum_event( &code, PAPI_ENUM_FIRST );

	while ( retval == PAPI_OK ) {
	  if (PAPI_event_code_to_name( code, event_name )!=PAPI_OK) {
	     printf("Error translating %x\n",code);
	     test_fail( __FILE__, __LINE__, 
		       "PAPI_event_code_to_name", retval );
	  }

	  if (PAPI_get_event_info( code, &event_info)!=PAPI_OK) {
	     printf("Error getting info for event %x\n",code);
	     test_fail( __FILE__, __LINE__, 
		       "PAPI_get_event_info()", retval );
	  }

	  if (!TESTS_QUIET) {
	    printf("\tEvent 0x%x: %s -- %s\n",
		   code,event_name,event_info.long_descr);
	  }

	  maximum_code=code;

	  retval = PAPI_enum_event( &code, PAPI_ENUM_EVENTS );

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

	/**********************************/
	/* Try accessing an invalid event */
	/**********************************/
	
	retval=PAPI_event_code_to_name( maximum_code+10, event_name );
	if (retval!=PAPI_ENOEVNT) {
	   test_fail( __FILE__, __LINE__, 
		    "Failed to return PAPI_ENOEVNT on invalid event", retval );
	}

	/***********************************/
	/* Test the EXAMPLE_ZERO event     */
	/***********************************/

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

	retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_ZERO not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}

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

	if (!TESTS_QUIET) printf("Testing EXAMPLE_ZERO: %lld\n",values[0]);

	if (values[0]!=0) {
	   test_fail(  __FILE__, __LINE__, "Result should be 0!\n", 0);
	}

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

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

	EventSet=PAPI_NULL;


	/***********************************/
	/* Test the EXAMPLE_CONSTANT event */
	/***********************************/

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

	retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_CONSTANT not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}

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

	if (!TESTS_QUIET) printf("Testing EXAMPLE_CONSTANT: %lld\n",values[0]);

	if (values[0]!=42) {
	   test_fail(  __FILE__, __LINE__, "Result should be 42!\n", 0);
	}

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

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

	EventSet=PAPI_NULL;



	/***********************************/
	/* Test the EXAMPLE_AUTOINC event  */
	/***********************************/

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

	retval = PAPI_event_name_to_code("EXAMPLE_AUTOINC", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_AUTOINC not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}

	if (!TESTS_QUIET) printf("Testing EXAMPLE_AUTOINC: ");

	for(i=0;i<10;i++) {

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

	   if (!TESTS_QUIET) printf("%lld ",values[0]);

	   if (values[0]!=i) {
	      test_fail(  __FILE__, __LINE__, "Result wrong!\n", 0);
	   }
	}

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


	/***********************************/
	/* Test multiple reads             */
        /***********************************/
   
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "PAPI_start failed\n",retval );
	}

	for(i=0;i<10;i++) {

	  retval=PAPI_read( EventSet, values);
	  if ( retval != PAPI_OK ) {
	     test_fail(  __FILE__, __LINE__, "PAPI_read failed\n", retval);
	  }
	  if (!TESTS_QUIET) printf("%lld ",values[0]);
	}
	
	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK ) {
	   test_fail(  __FILE__, __LINE__, "PAPI_stop failed\n", retval);
	}
	if (!TESTS_QUIET) printf("%lld\n",values[0]);

	//	if (values[0]!=i) {
	//   test_fail(  __FILE__, __LINE__, "Result wrong!\n", 0);
	//}

	/***********************************/
	/* Test PAPI_reset()               */
	/***********************************/

	retval = PAPI_reset( EventSet);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "PAPI_reset() failed\n",retval );
	}

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

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


	if (!TESTS_QUIET) printf("Testing EXAMPLE_AUTOINC after PAPI_reset(): %lld\n",
				 values[0]);

	if (values[0]!=0) {
	  	   test_fail(  __FILE__, __LINE__, "Result not zero!\n", 0);
	}

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

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

	EventSet=PAPI_NULL;


	/***********************************/
	/* Test multiple events            */
	/***********************************/

   	if (!TESTS_QUIET) printf("Testing Multiple Events: ");
   
   	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_create_eventset() failed\n", retval );
	}

	retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_CONSTANT not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}
   
   	retval = PAPI_event_name_to_code("EXAMPLE_GLOBAL_AUTOINC", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_GLOBAL_AUTOINC not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}
   
   	retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_ZERO not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}

   
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "PAPI_start failed\n",retval );
	}
	
	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK ) {
	   test_fail(  __FILE__, __LINE__, "PAPI_stop failed\n", retval);
	}
	   
        if (!TESTS_QUIET) {
           for(i=0;i<3;i++) {
              printf("%lld ",values[i]);
	   }
	   printf("\n");
	}

	if (values[0]!=42) {
	   test_fail(  __FILE__, __LINE__, "Result should be 42!\n", 0);
	}
   
   	if (values[2]!=0) {
	   test_fail(  __FILE__, __LINE__, "Result should be 0!\n", 0);
	}

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

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

	EventSet=PAPI_NULL;
   
	/***********************************/
	/* Test writing to an event        */
	/***********************************/

   	if (!TESTS_QUIET) printf("Testing Write\n");
   
   	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_create_eventset() failed\n", retval );
	}

	retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_CONSTANT not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}
   
   	retval = PAPI_event_name_to_code("EXAMPLE_GLOBAL_AUTOINC", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_GLOBAL_AUTOINC not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}
   
   	retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "EXAMPLE_ZERO not found\n",retval );
	}

	retval = PAPI_add_event( EventSet, code);
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__,
		      "PAPI_add_events failed\n", retval );
	}

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

        retval = PAPI_read ( EventSet, values );
   	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "PAPI_read failed\n",retval );
	}
   
        if (!TESTS_QUIET) {
	   printf("Before values: ");
           for(i=0;i<3;i++) {
              printf("%lld ",values[i]);
	   }
	   printf("\n");
	}
   
        values[0]=100;
        values[1]=200;
        values[2]=300;
      
        retval = PAPI_write ( EventSet, values );
   	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, 
		      "PAPI_write failed\n",retval );
	}
   
	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK ) {
	   test_fail(  __FILE__, __LINE__, "PAPI_stop failed\n", retval);
	}
	   
        if (!TESTS_QUIET) {
	   printf("After values: ");
           for(i=0;i<3;i++) {
              printf("%lld ",values[i]);
	   }
	   printf("\n");
	}
   

	if (values[0]!=42) {
	   test_fail(  __FILE__, __LINE__, "Result should be 42!\n", 0);
	}
   
   	if (values[1]!=200) {
	   test_fail(  __FILE__, __LINE__, "Result should be 200!\n", 0);
	}
   
   	if (values[2]!=0) {
	   test_fail(  __FILE__, __LINE__, "Result should be 0!\n", 0);
	}

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

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

	EventSet=PAPI_NULL;
   
   
        /************/
        /* All Done */
        /************/
   
	if (!TESTS_QUIET) printf("\n");

	test_pass( __FILE__, NULL, 0 );
		
	return 0;
}
Example #18
0
int
main( int argc, char **argv )
{
	int i, j = 0, k;
	int retval;
	PAPI_event_info_t info;
	const PAPI_hw_info_t *hwinfo = NULL;
	command_flags_t flags;
	int enum_modifier;
	int numcmp, cid;

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

	/* Initialize before parsing the input arguments */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	/* Parse the command-line arguments */
	parse_args( argc, argv, &flags );

	/* Set enum modifier mask */
	if ( flags.dear )
		enum_modifier = PAPI_NTV_ENUM_DEAR;
	else if ( flags.darr )
		enum_modifier = PAPI_NTV_ENUM_DARR;
	else if ( flags.iear )
		enum_modifier = PAPI_NTV_ENUM_IEAR;
	else if ( flags.iarr )
		enum_modifier = PAPI_NTV_ENUM_IARR;
	else if ( flags.opcm )
		enum_modifier = PAPI_NTV_ENUM_OPCM;
	else
		enum_modifier = PAPI_ENUM_EVENTS;


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

	retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
	}


	/* Do this code if an event name was specified on the commandline */
	if ( flags.named ) {
	   if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) {
	      if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
		 printf( "%-30s%s\n%-30s%d\n",
			 "Event name:", info.symbol,
			 "Number of Register Values:", info.count );
		 printf( "%-29s|%s|\n", "Description:", info.long_descr );
		 for ( k = 0; k < ( int ) info.count; k++ )
		     printf( " Register[%2d]:               |%s|\n", 
			     k, info.name[k] );

		     /* if unit masks exist but none specified, process all */
		     if ( !strchr( flags.name, ':' ) ) {
			if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
			   printf( "\nUnit Masks:\n" );
			   do {
			      retval = PAPI_get_event_info( i, &info );
			      if ( retval == PAPI_OK ) {
				 if ( parse_unit_masks( &info ) ) {
				    printf( "%-29s|%s|%s|\n", " Mask Info:",
					    info.symbol, info.long_descr );
				    for ( k = 0; k < ( int ) info.count; k++ )
					printf( "  Register[%2d]:  0x%08x  |%s|\n",
					       k, info.code[k], info.name[k] );
				 }
			      }
			   } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK );
			}
		     }
	      }
	   } else {
	     printf("Sorry, an event by the name '%s' could not be found.\n",
		    flags.name);
	     printf("Is it typed correctly?\n\n");
	     exit( 1 );
	   }
	}
        else {

	   /* Print *ALL* available events */


	   numcmp = PAPI_num_components(  );

	   j = 0;

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

	       const PAPI_component_info_t *component;
	       component=PAPI_get_component_info(cid);

	       /* Skip if requested enumeration not available */
	       if (( flags.dear ) && !( component->cntr_DEAR_events )) {
		 continue;
	       }
	       if (( flags.darr ) && !( component->data_address_range)) {
		 continue;
	       }
               if (( flags.iear ) && !( component->cntr_IEAR_events )) {
		 continue;
	       }
	       if (( flags.iarr ) && !( component->instr_address_range )) {
		 continue;
	       }
	       if (( flags.opcm ) && !( component->cntr_OPCM_events )) {
		 continue;
	       }


	       printf( "===============================================================================\n" );
	       printf( " Events in Component: %s\n",component->name);
	       printf( "===============================================================================\n" );
	     
	       /* Always ASK FOR the first event */
	       /* Don't just assume it'll be the first numeric value */
	       i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid );

	       /* UGH PAPI_enum_event() really needs a component field */
	       PAPI_enum_event( &i, PAPI_ENUM_FIRST );

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

		  /* This event may not exist */
		  if ( retval != PAPI_OK )
		     continue;

		  /* count only events that as supported by host cpu */
		  j++;

		  print_event( &info, 0 );

		  /* Does this matter on anything but perfctr? */
		  if ( flags.details ) {
		     for ( k = 0; k < ( int ) info.count; k++ ) {
			 if ( strlen( info.name[k] ) ) {
			    printf( "  Register[%d] Name: %-20s  Value: 0x%-28x|\n",
				    k, info.name[k], info.code[k] );
			 }
		     }
		  }

/*		modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
			groups id for each group in which this
			native event lives, in bits 16 - 23 of event code
			terminating with PAPI_ENOEVNT at the end of the list.
*/

		  /* This is an IBM Power issue */
		  if ( flags.groups ) {
		     k = i;
		     if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) {
			printf( "Groups: " );
			do {
			  printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
					     PAPI_NTV_GROUP_SHIFT ) - 1 );
			} while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK );
			printf( "\n" );
		     }
		  }

		  /* Print umasks */
		  /* components that don't have them can just ignore */

	          if ( flags.umask ) { 
		     k = i;
		     if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
		        do {
			   retval = PAPI_get_event_info( k, &info );
			   if ( retval == PAPI_OK ) {
			      if ( parse_unit_masks( &info ) )
			         print_event( &info, 2 );
			   }
		        } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK );
		     }

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

	       } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK );
	   }
Example #19
0
int
main( int argc, char **argv )
{
	int status, retval, num_tests = 2, tmp;
	int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL;
	int PAPI_event, PAPI_event2, mask1, mask2;
	int num_events1, num_events2;
	long long **values;
	long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
	char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
	const PAPI_component_info_t *cmpinfo;
	pid_t pid, pid2;
	double ratio1,ratio2;

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

	/* Initialize the library */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	/* get the component info and check if we support attach */
	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 );
	}

	/* fork off first child */
	pid = fork(  );
	if ( pid < 0 ) {
	   test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS );
	}
	if ( pid == 0 ) {
	   exit( wait_for_attach_and_loop( 1 ) );
	}

	/* fork off second child, does twice as much */
	pid2 = fork(  );
	if ( pid2 < 0 ) {
	   test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS );
	}
	if ( pid2 == 0 ) {
	   exit( wait_for_attach_and_loop( 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_events( &num_events1, &PAPI_event, &mask1 );
	EventSet2 = add_two_events( &num_events2, &PAPI_event2, &mask2 );

	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1 ;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didnt return true to WIFSTOPPED", 0 );
	   }
	   
	   if ( ptrace( PTRACE_ATTACH, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
 	      test_fail( __FILE__, __LINE__,
			"Child process didnt return true to WIFSTOPPED", 0 );
	   }
	}

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

	retval = PAPI_attach( EventSet2, ( unsigned long ) pid2 );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_attach", retval ); 
	}

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

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

	values = allocate_test_space( num_tests, num_events1 );

	/* Gather before values */
	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(  );

	/* Wait for the SIGSTOP. */
	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }

	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }
	}

	/* start first child */
	retval = PAPI_start( EventSet1 );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	/* start second child */
	retval = PAPI_start( EventSet2 );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	/* Wait for the SIGSTOP. */
	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }

	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	       perror( "ptrace(PTRACE_ATTACH)" );
	       return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }
	}

	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;

	/* stop first child */
	retval = PAPI_stop( EventSet1, values[0] );
	if ( retval != PAPI_OK ) {
	   printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
				retval );
	}

	/* stop second child */
	retval = PAPI_stop( EventSet2, values[1] );
	if ( retval != PAPI_OK ) {
	   printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
				retval );
	}

	remove_test_events( &EventSet1, mask1 );
	remove_test_events( &EventSet2, mask2 );

	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	}

	if ( waitpid( pid, &status, 0 ) == -1 ) {
	   perror( "waitpid()" );
	   exit( 1 );
	}
	if ( WIFEXITED( status ) == 0 ) {
	   test_fail( __FILE__, __LINE__,
		     "Child process didn't return true to WIFEXITED", 0 );
	}

	if ( waitpid( pid2, &status, 0 ) == -1 ) {
	   perror( "waitpid()" );
	   exit( 1 );
	}
	if ( WIFEXITED( status ) == 0 ) {
		test_fail( __FILE__, __LINE__,
			  "Child process didn't return true to WIFEXITED", 0 );
	}

	/* This code isn't necessary as we know the child has exited, */
	/* it *may* return an error if the component so chooses. You  */
        /* should use read() instead. */

	printf( "Test case: multiple 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" );

	sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid,
			 event_name );
	printf( TAB1, add_event_str, values[0][1] );
	sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", 
		 ( intmax_t ) pid );
	printf( TAB1, add_event_str, values[0][0] );
	sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid2,
			 event_name );
	printf( TAB1, add_event_str,values[1][1] );
	sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", 
		 ( intmax_t ) pid2 );
	printf( TAB1, add_event_str, values[1][0] );
	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: pid %d results should be twice pid %d\n",pid2,pid );

	ratio1=(double)values[1][0]/(double)values[0][0];
	ratio2=(double)values[1][1]/(double)values[0][1];

	printf("\t%lld/%lld = %lf\n",values[1][0],values[0][0],ratio1);
	

	if ((ratio1 >2.15 ) || (ratio1 < 1.85)) {
	  printf("Ratio out of range, should be ~2.0 not %lf\n",ratio1);
	  test_fail( __FILE__, __LINE__,
		    "Error: Counter ratio not two", 0 );
	}

	printf("\t%lld/%lld = %lf\n",values[1][1],values[0][1],ratio2);

	if ((ratio2 >2.75 ) || (ratio2 < 1.25)) {
	  printf("Ratio out of range, should be ~2.0, not %lf\n",ratio2);
	  test_fail( __FILE__, __LINE__,
		    "Known issue: Counter ratio not two", 0 );
	}

	test_pass( __FILE__, values, num_tests );
	return 0;
}
Example #20
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 );
}
Example #21
0
int
main( int argc, char **argv )
{
	int retval;
	int code = PAPI_TOT_CYC, last;
	char event_name[PAPI_MAX_STR_LEN];
	const PAPI_hw_info_t *hwinfo = NULL;
	const PAPI_component_info_t *cmp_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 );

	retval =
		papi_print_header
		( "Test case code2name.c: Check limits and indexing of event tables.\n",
		  &hwinfo );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

	printf( "Looking for PAPI_TOT_CYC...\n" );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
	printf( "Found |%s|\n", event_name );

	code = PAPI_FP_OPS;
	printf( "Looking for highest defined preset event (PAPI_FP_OPS): 0x%x...\n",
			code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
	printf( "Found |%s|\n", event_name );

	code = PAPI_PRESET_MASK | ( PAPI_MAX_PRESET_EVENTS - 1 );
	printf( "Looking for highest allocated preset event: 0x%x...\n", code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK )
		test_continue( "PAPI_event_code_to_name", retval );
	else
		printf( "Found |%s|\n", event_name );

	code = PAPI_PRESET_MASK | ( int ) PAPI_NATIVE_AND_MASK;
	printf( "Looking for highest possible preset event: 0x%x...\n", code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK )
		test_continue( "PAPI_event_code_to_name", retval );
	else
		printf( "Found |%s|\n", event_name );

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

	printf( "Looking for first native event: 0x%x...\n", code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK ) {
	  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
	}
	else {
	  printf( "Found |%s|\n", event_name );
	}

	/* Find the last defined native event */
	cmp_info = PAPI_get_component_info( 0 );
	if ( cmp_info == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_component_info", PAPI_ESBSTR );

	code = PAPI_NATIVE_MASK;
	PAPI_enum_event( &code, PAPI_ENUM_FIRST );

	while ( PAPI_enum_event( &code, PAPI_ENUM_EVENTS ) == PAPI_OK ) {
	  last=code;
	}

	code = last;
	printf( "Looking for last native event: 0x%x...\n", code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
	}
	else {
	   printf( "Found |%s|\n", event_name );
	}

	/* Highly doubtful we have this many natives */
	/* Turn on all bits *except* PRESET bit and COMPONENT bits */
	code = PAPI_PRESET_AND_MASK & PAPI_COMPONENT_AND_MASK;
	printf( "Looking for highest definable native event: 0x%x...\n", code );
	retval = PAPI_event_code_to_name( code, event_name );
	if ( retval != PAPI_OK )
		test_continue( "PAPI_event_code_to_name", retval );
	else
		printf( "Found |%s|\n", event_name );
	if ( ( retval == PAPI_ENOEVNT ) || ( retval == PAPI_OK ) )
		test_pass( __FILE__, 0, 0 );

	test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", PAPI_EBUG );

	exit( 1 );
}
Example #22
0
int main (int argc, char **argv)
{

        int retval,cid,numcmp;
	int EventSet = PAPI_NULL;
	long long values[NUM_EVENTS];
	int code;
	char event_name[PAPI_MAX_STR_LEN];
	int total_events=0;
	int r;
	const PAPI_component_info_t *cmpinfo = NULL;

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

	/* PAPI Initialization */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
	}

        numcmp = PAPI_num_components();

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

	   if (!TESTS_QUIET) {
	      if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	         test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	      }
	      printf("\tComponent %d - %s\n", cid, cmpinfo->name);
	   }

	   code = PAPI_NATIVE_MASK;

           r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );

	   while ( r == PAPI_OK ) {
	      retval = PAPI_event_code_to_name( code, event_name );
	      if ( retval != PAPI_OK ) {
		 printf("Error translating %x\n",code);
	         test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	      }

	      if (!strncmp(event_name,"micpower",8)) {
	         if (!TESTS_QUIET) printf("0x%x %s ",code,event_name);
	     
	         EventSet = PAPI_NULL;

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

	         retval = PAPI_add_event( EventSet, code );
	         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);
		 }

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

	         if (!TESTS_QUIET) printf(" value: %lld\n",values[0]);

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

	         total_events++;
	      }
	      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
	   }
        }

	if (total_events==0) {

	   test_skip(__FILE__,__LINE__,"No coretemp events found",0);
	}

	test_pass( __FILE__, NULL, 0 );
		
	return 0;
}
Example #23
0
void PAPI_HW_COUNTER_open(int tid){
    // set events to measure
    int *Events;
    int EventCode;
    int event_ctr = 0;
    int retval;
  #ifdef MEASURE_TIME
  #endif

  #ifdef MEASURE_CPI
    thr_vars[tid].papi_idx_inst = thr_vars[tid].num_events++;
    thr_vars[tid].papi_idx_cyc = thr_vars[tid].num_events++;
  #endif

  #ifdef MEASURE_MEMACC
    thr_vars[tid].papi_idx_load = thr_vars[tid].num_events++;
    thr_vars[tid].papi_idx_store = thr_vars[tid].num_events++;
  #endif
    
  #ifdef MEASURE_LLCMISS
    thr_vars[tid].papi_idx_llcmiss = thr_vars[tid].num_events++;
  #endif

  #ifdef MEASURE_ICACHEMISS
    thr_vars[tid].papi_idx_icachemiss = thr_vars[tid].num_events++;
  #endif

  #ifdef MEASURE_DCACHEMISS
    thr_vars[tid].papi_idx_l1dcm = thr_vars[tid].num_events++;
    thr_vars[tid].papi_idx_l1dca = thr_vars[tid].num_events++;
  #endif 

  #ifdef MEASURE_ENERGY
  #endif
    
    event_ctr = 0;  // reset event counter

    if((Events=(int*)malloc(sizeof(int)*thr_vars[tid].num_events)) == NULL){
        printf("ERROR: Failed to allocate memory for Events.");
    }
    if((thr_vars[tid].values=(long long int*)malloc(sizeof(long long)*thr_vars[tid].num_events)) == NULL){
        printf("ERROR: Failed to allocate memory for Events.");
    }

  #ifdef __ARM_ARCH_7A__
    // pin processor only on arm arch.
    pid_t pid = getpid();
    int core = 0;
    printf("Pinning thread %d to cores %d..%d\n", pid, 0, 0);
    printf("Observe in terminal via \"ps -p <PID> -L -o pid,tid,psr\"\n");
    pin_cpu(pid, core);
    printf("Pinned to core %d\n", core);
  #endif

    // Open file to output
    char filename_id[2*sizeof(int)];
    snprintf(filename_id, sizeof(filename_id),"%d",tid);
    char* filename_w_id;
    filename_w_id=(char*)malloc(strlen(OUTFILEID)+strlen(OUTFILEEXT)+strlen(filename_id)+1);
    strcpy(filename_w_id, OUTFILEID);
    strcat(filename_w_id, filename_id);
    strcat(filename_w_id, OUTFILEEXT);
    
    thr_vars[tid].f=fopen(filename_w_id, "w");
    if (thr_vars[tid].f == NULL){
        printf("failed to open file %s.\n", filename_w_id);
        exit(1);
    }

    // Measure clock frequency
    long long elapsed_cyc;
    elapsed_cyc = PAPI_get_real_cyc();
    sleep(1);
    elapsed_cyc = PAPI_get_real_cyc()-elapsed_cyc;
    thr_vars[tid].PAPI_CLOCK_RATE = elapsed_cyc;
    printf("Measured clock frequency: %.0lld Hz\n",thr_vars[tid].PAPI_CLOCK_RATE);

    // Set EventSet
    thr_vars[tid].EventSet = PAPI_NULL;/*EventSet*/
    retval=PAPI_create_eventset(&(thr_vars[tid].EventSet));
    if (retval != PAPI_OK){
        papi_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
    }


  #ifdef MEASURE_TIME
  #endif

  #ifdef MEASURE_CPI
    retval = PAPI_event_name_to_code( PAPI_INST , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, inst", retval);
    }
    Events[event_ctr++] = EventCode;
   
    retval = PAPI_event_name_to_code( PAPI_CYC , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, cyc", retval);
    }
    Events[event_ctr++] = EventCode;
  #endif

  #ifdef MEASURE_MEMACC
    retval = PAPI_event_name_to_code( PAPI_MEM_LOAD , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, loads", retval);
    }
    Events[event_ctr++] = EventCode;
    
    retval=PAPI_event_name_to_code( PAPI_MEM_STORE , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, stores", retval);
    }
    Events[event_ctr++] = EventCode;
  #endif
  
  #ifdef MEASURE_LLCMISS
    retval = PAPI_event_name_to_code( PAPI_LLC_MISS , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, llc miss", retval);
    }
    Events[event_ctr++] = EventCode;
  #endif

  #ifdef MEASURE_ICACHEMISS
    retval = PAPI_event_name_to_code( PAPI_IC_MISS , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, llc miss", retval);
    }
    Events[event_ctr++] = EventCode;
  #endif 

  #ifdef MEASURE_DCACHEMISS
    retval = PAPI_event_name_to_code( PAPI_L1_DC_MISS , &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, Level 1 data cache misses", retval);
    }
    Events[event_ctr++] = EventCode;

    retval = PAPI_event_name_to_code( PAPI_L1_DC_ACCESS, &EventCode );
    if (retval != PAPI_OK ) {
        papi_fail(__FILE__, __LINE__,
                "PAPI_event_name_to_code, Level 1 data cache accesses", retval);
    }
    Events[event_ctr++] = EventCode;
  #endif

  #ifdef MEASURE_ENERGY
    printf("Probing all RAPL events\n");

    thr_vars[tid].numcmp = PAPI_num_components();

    for(thr_vars[tid].cid=0; thr_vars[tid].cid<thr_vars[tid].numcmp; thr_vars[tid].cid++) {
        if ( (thr_vars[tid].cmpinfo = PAPI_get_component_info(thr_vars[tid].cid)) == NULL) {
            papi_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
        }
        if (strstr(thr_vars[tid].cmpinfo->name,"rapl")) {
            thr_vars[tid].rapl_cid=thr_vars[tid].cid;
            printf("Found rapl component at cid %d.\n",thr_vars[tid].rapl_cid);
            if (thr_vars[tid].cmpinfo->disabled) {
                printf("RAPL component disabled: %s\n",
                        thr_vars[tid].cmpinfo->disabled_reason);
                exit(EXIT_FAILURE);
            }
            break;
        }
    }

    if (thr_vars[tid].cid==thr_vars[tid].numcmp) {
        // Component not found:
        papi_fail(__FILE__,__LINE__,"No rapl component found\n",0);
    }

    retval = PAPI_create_eventset( &(thr_vars[tid].EnergyEventSet) );
    if (retval != PAPI_OK){
        papi_fail(__FILE__,__LINE__, "PAPI_create_eventset()", retval);
    }

  // Add all events:
  int r;
  thr_vars[tid].code = PAPI_NATIVE_MASK;
  r = PAPI_enum_cmp_event( &(thr_vars[tid].code), PAPI_ENUM_FIRST, thr_vars[tid].rapl_cid );
  while ( r == PAPI_OK ) {
     retval = PAPI_event_code_to_name( thr_vars[tid].code, thr_vars[tid].event_names[thr_vars[tid].num_energy_events] );
     if ( retval != PAPI_OK ) {
        printf("Error translating %#x\n",thr_vars[tid].code);
        papi_fail(__FILE__, __LINE__, 
                  "PAPI_event_code_to_name", retval );
     }

     printf("Found event: %s\n", thr_vars[tid].event_names[thr_vars[tid].num_energy_events]);

     retval = PAPI_get_event_info(thr_vars[tid].code,&(thr_vars[tid].evinfo));
     if (retval != PAPI_OK) {
        papi_fail(__FILE__, __LINE__,
                  "Error getting event info\n",retval);
     }
	
     strncpy(thr_vars[tid].units[thr_vars[tid].num_energy_events],thr_vars[tid].evinfo.units,PAPI_MIN_STR_LEN);
     thr_vars[tid].data_type[thr_vars[tid].num_energy_events] = thr_vars[tid].evinfo.data_type;

     retval = PAPI_add_event(thr_vars[tid].EnergyEventSet, thr_vars[tid].code);
     if (retval != PAPI_OK ) {
         papi_fail( __FILE__, __LINE__, "PAPI_add_event()", retval);
     }
  	      
     r = PAPI_enum_cmp_event( &(thr_vars[tid].code), PAPI_ENUM_EVENTS, thr_vars[tid].rapl_cid );
     thr_vars[tid].num_energy_events++;
  }

    if((thr_vars[tid].energy_values=(long long int*)malloc(sizeof(long long)*thr_vars[tid].num_energy_events)) == NULL){
        printf("ERROR: Failed to allocate memory for Events.");
    }

  #endif

  #ifdef MEASURE_HW_COUNTER
    int k;
    for(k = 0; k < thr_vars[tid].num_events; k++){
        retval = PAPI_add_event(thr_vars[tid].EventSet, Events[k]);
        if (retval != PAPI_OK ) {
           printf("At event %d:\n",k); 
           papi_fail( __FILE__, __LINE__, "PAPI_add_event()", retval);
        }
    }

    retval=PAPI_start(thr_vars[tid].EventSet);
    if (retval != PAPI_OK){
        papi_fail(__FILE__, __LINE__, "PAPI_start()", retval);
    }
  #endif

  #ifdef MEASURE_ENERGY
    retval=PAPI_start(thr_vars[tid].EnergyEventSet);
    if (retval != PAPI_OK){
        papi_fail(__FILE__, __LINE__, "PAPI_start() on energy", retval);
    }
  #endif
}
int main (int argc, char **argv)
{
    int retval,cid,numcmp;
    int EventSet = PAPI_NULL;
    long long value;
    int code;
    char event_name[PAPI_MAX_STR_LEN];
    int total_events=0;
    int r;
    const PAPI_component_info_t *cmpinfo = NULL;

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

    /* PAPI Initialization */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
    }

    if (!TESTS_QUIET) {
        printf("Trying all net events\n");
    }

    numcmp = PAPI_num_components();

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

        if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
            test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
        }

        if (!TESTS_QUIET) {
            printf("Component %d - %d events - %s\n", cid,
                cmpinfo->num_native_events, cmpinfo->name);
        }

        if ( strstr(cmpinfo->name, "infiniband") == NULL) {
            continue;
        }

        code = PAPI_NATIVE_MASK;

        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
        while ( r == PAPI_OK ) {

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

            if (!TESTS_QUIET) {
                printf("%#x %-24s = ", code, event_name);
            }

            EventSet = PAPI_NULL;

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

            retval = PAPI_add_event( EventSet, code );
            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);
            }

            if (strcmp(event_name, "_recv") == 0) {
                /* XXX figure out a general method to  generate some traffic 
                 * for infiniband
                 * the operation should take more than one second in order
                 * to guarantee that the network counters are updated */
                retval = system("ping -c 4 " PINGADDR " > /dev/null");
                if (retval < 0) {
					test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
				}
            }

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

            if (!TESTS_QUIET) printf("%lld\n", value);

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

            total_events++;

            r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
        }

    }

    if (total_events==0) {
        test_skip(__FILE__,__LINE__,"No net events found", 0);
    }

    test_pass( __FILE__, NULL, 0 );

    return 0;
}
Example #25
0
int main (int argc, char **argv)
{

	int retval,cid,rapl_cid=-1,numcmp;
	int EventSet = PAPI_NULL;
	long long *values;
	int num_events=0;
	int code;
	char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
	char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
	int data_type[MAX_RAPL_EVENTS];
	int r,i, do_wrap = 0;
	const PAPI_component_info_t *cmpinfo = NULL;
	PAPI_event_info_t evinfo;
	long long before_time,after_time;
	double elapsed_time;

	/* Set TESTS_QUIET variable */
	tests_quiet( argc, argv );
	if ( argc > 1 )
		if ( strstr( argv[1], "-w" ) )
			do_wrap = 1;

	/* PAPI Initialization */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
	}

	if (!TESTS_QUIET) {
		printf("Trying all RAPL events\n");
	}

	numcmp = PAPI_num_components();

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

		if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
			test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
		}

		if (strstr(cmpinfo->name,"rapl")) {

			rapl_cid=cid;

			if (!TESTS_QUIET) {
				printf("Found rapl component at cid %d\n",rapl_cid);
			}

			if (cmpinfo->disabled) {
				if (!TESTS_QUIET) {
					printf("RAPL component disabled: %s\n",
							cmpinfo->disabled_reason);
				} 
				test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
			}
			break;
		}
	}

	/* Component not found */
	if (cid==numcmp) {
		test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
	}

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

	/* Add all events */

	code = PAPI_NATIVE_MASK;

	r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );

	while ( r == PAPI_OK ) {

		retval = PAPI_event_code_to_name( code, event_names[num_events] );
		if ( retval != PAPI_OK ) {
			printf("Error translating %#x\n",code);
			test_fail( __FILE__, __LINE__, 
					"PAPI_event_code_to_name", retval );
		}

		retval = PAPI_get_event_info(code,&evinfo);
		if (retval != PAPI_OK) {
			test_fail( __FILE__, __LINE__,
					"Error getting event info\n",retval);
		}

		strncpy(units[num_events],evinfo.units,sizeof(units[0])-1);
		// buffer must be null terminated to safely use strstr operation on it below
		units[num_events][sizeof(units[0])-1] = '\0';

		data_type[num_events] = evinfo.data_type;

		retval = PAPI_add_event( EventSet, code );
		if (retval != PAPI_OK) {
			break; /* We've hit an event limit */
		}
		num_events++;

		r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
	}

	values=calloc(num_events,sizeof(long long));
	if (values==NULL) {
		test_fail(__FILE__, __LINE__, 
				"No memory",retval);
	}

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

	/* Start Counting */
	before_time=PAPI_get_real_nsec();
	retval = PAPI_start( EventSet);
	if (retval != PAPI_OK) {
		test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
	}

	/* Run test */
	run_test(TESTS_QUIET);

	/* Stop Counting */
	after_time=PAPI_get_real_nsec();
	retval = PAPI_stop( EventSet, values);
	if (retval != PAPI_OK) {
		test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
	}

	elapsed_time=((double)(after_time-before_time))/1.0e9;

	if (!TESTS_QUIET) {
		printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
				elapsed_time);

		printf("Scaled energy measurements:\n");

		for(i=0;i<num_events;i++) {
			if (strstr(units[i],"nJ")) {

				printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
						event_names[i],
						(double)values[i]/1.0e9,
						((double)values[i]/1.0e9)/elapsed_time);
			}
		}

		printf("\n");
		printf("Energy measurement counts:\n");

		for(i=0;i<num_events;i++) {
			if (strstr(event_names[i],"ENERGY_CNT")) {
				printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
			}
		}

		printf("\n");
		printf("Scaled Fixed values:\n");

		for(i=0;i<num_events;i++) {
			if (!strstr(event_names[i],"ENERGY")) {
				if (data_type[i] == PAPI_DATATYPE_FP64) {

					union {
						long long ll;
						double fp;
					} result;

					result.ll=values[i];
					printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]);
				}
			}
		}

		printf("\n");
		printf("Fixed value counts:\n");

		for(i=0;i<num_events;i++) {
			if (!strstr(event_names[i],"ENERGY")) {
				if (data_type[i] == PAPI_DATATYPE_UINT64) {
					printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
				}
			}
		}

	}

#ifdef WRAP_TEST
	double max_time;
	unsigned long long max_value = 0;
	int repeat;

	for(i=0;i<num_events;i++) {
		if (strstr(event_names[i],"ENERGY_CNT")) {
			if (max_value < (unsigned) values[i]) {
				max_value = values[i];
			}
		}
	}
	max_time = elapsed_time * (0xffffffff / max_value);
	printf("\n");
	printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n", 
			max_time, max_time/60);

	if (do_wrap) {
		printf ("Beginning wraparound execution.");
		/* Start Counting */
		before_time=PAPI_get_real_nsec();
		retval = PAPI_start( EventSet);
		if (retval != PAPI_OK) {
			test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
		}

		/* Run test */
		repeat = (int)(max_time/elapsed_time);
		for (i=0;i< repeat;i++) {
			run_test(1);
			printf("."); fflush(stdout);
		}
		printf("\n");

		/* Stop Counting */
		after_time=PAPI_get_real_nsec();
		retval = PAPI_stop( EventSet, values);
		if (retval != PAPI_OK) {
			test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
		}

		elapsed_time=((double)(after_time-before_time))/1.0e9;
		printf("\nStopping measurements, took %.3fs\n\n", elapsed_time);

		printf("Scaled energy measurements:\n");

		for(i=0;i<num_events;i++) {
			if (strstr(units[i],"nJ")) {

				printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
						event_names[i],
						(double)values[i]/1.0e9,
						((double)values[i]/1.0e9)/elapsed_time);
			}
		}
		printf("\n");
		printf("Energy measurement counts:\n");

		for(i=0;i<num_events;i++) {
			if (strstr(event_names[i],"ENERGY_CNT")) {
				printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
			}
		}
	}

#endif

	/* Done, clean up */
	retval = PAPI_cleanup_eventset( EventSet );
	if (retval != PAPI_OK) {
		test_fail(__FILE__, __LINE__, 
				"PAPI_cleanup_eventset()",retval);
	}

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

	test_pass( __FILE__, NULL, 0 );

	return 0;
}
Example #26
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long values0[2],values1[2],values2[2];
	int num_flops = 3000000, retval;
	int mythreshold = 1000000;
	char event_name1[PAPI_MAX_STR_LEN];
        int PAPI_event;
	int cid,numcmp,rapl_cid;
	const PAPI_component_info_t *cmpinfo = NULL;

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

	quiet=TESTS_QUIET;

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

	numcmp = PAPI_num_components();

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

	  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	    test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	  }

	  if (strstr(cmpinfo->name,"linux-rapl")) {
	    rapl_cid=cid;
	    if (!TESTS_QUIET) printf("Found rapl component at cid %d\n",
				     rapl_cid);
	    if (cmpinfo->num_native_events==0) {
              test_skip(__FILE__,__LINE__,"No rapl events found",0);
	    }
	    break;
	  }
	}

	/* Component not found */
	if (cid==numcmp) {
	  test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
	}


	/* add PAPI_TOT_CYC and PAPI_TOT_INS */
	retval=PAPI_create_eventset(&EventSet);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

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

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

	/* Add some RAPL events */
	retval=PAPI_create_eventset(&EventSet2);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}
	
	PAPI_event=PAPI_TOT_CYC;

	/* arbitrary */
	mythreshold = 2000000;
	if (!TESTS_QUIET) {
	   printf("Using %x for the overflow event, threshold %d\n",
		  PAPI_event,mythreshold);
	}

	/* Start the run calibration run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( 3000000 );

	/* stop the calibration run */
	retval = PAPI_stop( EventSet, values0 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}


	/* set up overflow handler */
	retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_overflow",retval);
	}

	/* Start overflow run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}
	retval = PAPI_start( EventSet2 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( num_flops );

	/* stop overflow run */
	retval = PAPI_stop( EventSet, values1 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}

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

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

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

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]);
	}

	retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 );
	if (retval != PAPI_OK) {
	  test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval);
	}

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]);
	}

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

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

	if (rapl_backward) {
	   test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0);
	}

	test_pass( __FILE__, NULL, 0 );


	return 0;
}
Example #27
0
File: papi.c Project: DundalkIT/pcp
static int
papi_internal_init(pmdaInterface *dp)
{
    int ec;
    int sts;
    PAPI_event_info_t info;
    char entry[PAPI_HUGE_STR_LEN+12]; // the length papi uses for the symbol name
    unsigned int i = 0;
    pmID pmid;

    sts = sprintf(papi_version, "%d.%d.%d", PAPI_VERSION_MAJOR(PAPI_VERSION),
	    PAPI_VERSION_MINOR(PAPI_VERSION), PAPI_VERSION_REVISION(PAPI_VERSION));
    if (sts < 0) {
	__pmNotifyErr(LOG_ERR, "%s failed to create papi version metric.\n",pmProgname);
	return PM_ERR_GENERIC;
    }

    if ((sts = __pmNewPMNS(&papi_tree)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s failed to create dynamic papi pmns: %s\n",
		      pmProgname, pmErrStr(sts));
	papi_tree = NULL;
	return PM_ERR_GENERIC;
    }

    number_of_counters = PAPI_num_counters();
    if (number_of_counters < 0) {
	__pmNotifyErr(LOG_ERR, "hardware does not support performance counters\n");
	return PM_ERR_APPVERSION;
    }
    else if (number_of_counters == 0) {
	__pmNotifyErr(LOG_WARNING, "no performance counters\n");
    }

    sts = PAPI_library_init(PAPI_VER_CURRENT);
    if (sts != PAPI_VER_CURRENT) {
	__pmNotifyErr(LOG_ERR, "PAPI_library_init error (%d)\n", sts);
	return PM_ERR_GENERIC;
    }

    ec = PAPI_PRESET_MASK;
    PAPI_enum_event(&ec, PAPI_ENUM_FIRST);
    do {
	if (PAPI_get_event_info(ec, &info) == PAPI_OK) {
	    if (info.count && PAPI_PRESET_ENUM_AVAIL) {
		expand_papi_info(i);
		memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t));
		memcpy(&papi_info[i].papi_string_code, info.symbol + 5, strlen(info.symbol)-5);
		snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code);
		pmid = pmid_build(dp->domain, CLUSTER_PAPI, i);
		papi_info[i].pmid = pmid;
		__pmAddPMNSNode(papi_tree, pmid, entry);
		memset(&entry[0], 0, sizeof(entry));
		papi_info[i].position = -1;
		papi_info[i].metric_enabled = 0;
		expand_values(i);
		i++;
	    }
	}
    } while(PAPI_enum_event(&ec, 0) == PAPI_OK);

#if defined(HAVE_PAPI_DISABLED_COMP)
    char *tokenized_string;
    int number_of_components;
    int component_id;
    int native;

    number_of_components = PAPI_num_components();
    native = 0 | PAPI_NATIVE_MASK;
    for (component_id = 0; component_id < number_of_components; component_id++) {
	const PAPI_component_info_t *component;
	component = PAPI_get_component_info(component_id);
	if (component->disabled || (strcmp("perf_event", component->name)
				    && strcmp("perf_event_uncore", component->name)))
	    continue;
	sts = PAPI_enum_cmp_event (&native, PAPI_ENUM_FIRST, component_id);
	if (sts == PAPI_OK)
	do {
	    if (PAPI_get_event_info(native, &info) == PAPI_OK) {
		char local_native_metric_name[PAPI_HUGE_STR_LEN] = "";
		int was_tokenized = 0;
		expand_papi_info(i);
		memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t));
		tokenized_string = strtok(info.symbol, "::: -");
		while (tokenized_string != NULL) {
		    size_t remaining = sizeof(local_native_metric_name) -
			strlen(local_native_metric_name) - 1;
		    if (remaining < 1)
			break;
		    strncat(local_native_metric_name, tokenized_string, remaining);
		    was_tokenized = 1;
		    tokenized_string=strtok(NULL, "::: -");
		    if (tokenized_string) {
			remaining = sizeof(local_native_metric_name) -
			    strlen(local_native_metric_name) - 1;
			if (remaining < 1)
			    break;
			strncat(local_native_metric_name, ".", remaining);
		    }
		}
		if (!was_tokenized) {
		    strncpy(papi_info[i].papi_string_code, info.symbol,
			    sizeof(papi_info[i].papi_string_code) - 1);
		}
		else {
		    strncpy(papi_info[i].papi_string_code,
			    local_native_metric_name,
			    sizeof(papi_info[i].papi_string_code) - 1);
		}
		snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code);
		pmid = pmid_build(dp->domain, CLUSTER_PAPI, i);
		papi_info[i].pmid = pmid;
		__pmAddPMNSNode(papi_tree, pmid, entry);
		memset(&entry[0], 0, sizeof(entry));
		papi_info[i].position = -1;
		papi_info[i].metric_enabled = 0;
		expand_values(i);
		i++;
	    }
	} while (PAPI_enum_cmp_event(&native, PAPI_ENUM_EVENTS, component_id) == PAPI_OK);
    }
#endif
    pmdaTreeRebuildHash(papi_tree, number_of_events);

    /* Set one-time settings for all future EventSets. */
    if ((sts = PAPI_set_domain(PAPI_DOM_ALL)) != PAPI_OK) {
	handle_papi_error(sts, 0);
	return PM_ERR_GENERIC;
    }
    if ((sts = PAPI_multiplex_init()) != PAPI_OK) {
	handle_papi_error(sts, 0);
	return PM_ERR_GENERIC;
    }

    sts = refresh_metrics(0);
    if (sts != PAPI_OK)
	return PM_ERR_GENERIC;
    return 0;
}