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;
}
示例#2
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;
}
示例#3
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;
}
示例#4
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;
}
示例#5
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;
}
示例#6
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 );
}
示例#7
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;
}
示例#8
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;
}
示例#9
0
文件: rapl_plot.c 项目: FMCalisto/SMP
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;
}
示例#10
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
}
示例#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;
}
示例#12
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;
}
示例#13
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,
			int cidx)
{
	/* 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( cidx );
     if ( s == NULL ) {
	test_fail( __FILE__, __LINE__, 
			   "PAPI_get_component_info", PAPI_ECMP );
     }

     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_cmp_event( &i, PAPI_ENUM_FIRST, cidx );

     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_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == 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_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == 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_cmp_event( &i, PAPI_ENUM_EVENTS, cidx ) == 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;
}
示例#14
0
文件: papi.c 项目: 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;
}
int main( int argc, char **argv ) {

  int i, k, num_umasks;
    int retval,rc;
    PAPI_event_info_t info;
    int numcmp, cid;
    int quiet;
    char test_string[]="Checking for event create race...";
    char *ptr;
    char temp_name[BUFSIZ];

    pthread_attr_t attr;
    pthread_t threads[NUM_THREADS];

    quiet=test_quiet();

	/* Initialize PAPI library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
       test_fail(test_string);
    }

    numcmp = PAPI_num_components(  );

    num_events = 0;

    for(cid=0; cid<numcmp; cid++ ) {
       i = 0 | PAPI_NATIVE_MASK;
       PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );

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

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

	      /* save the main event name */
	  strncpy(temp_name,info.symbol,BUFSIZ);

	      /* Handle umasks */
		
	  k = i;
	  num_umasks=0;
	  if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
	     do {
		retval = PAPI_get_event_info( k, &info );
		if ( retval == PAPI_OK ) {
		      /* handle libpfm4-style events which have a */
		      /* pmu::event type event name               */
                   if ((ptr=strstr(info.symbol, "::"))) {
                      ptr+=2;
		   }
                   else {
                      ptr=info.symbol;
		   }

                   if ( ( strchr( ptr, ':' ) ) == NULL ) {
		      /* shouldn't happen */
		      if (!quiet) printf("Weird umask!\n");
		      test_fail(test_string);
		   }
		   else {
		     //	      if (!quiet) printf("%s\n",info.symbol);
		      num_umasks++;
	              if (num_events<MAX_EVENTS) {
			 strncpy(event_names[num_events],info.symbol,BUFSIZ);
		      }
		      num_events++;
		   }
		}
	     } while ( PAPI_enum_event( &k,PAPI_NTV_ENUM_UMASKS) == PAPI_OK );
		  
	  }
	  if (num_umasks==0) {
	    //	     if (!quiet) printf("%s\n",temp_name);
	     if (num_events<MAX_EVENTS) {
	        strncpy(event_names[num_events],temp_name,BUFSIZ);
	     }
	     num_events++;
	  }

       } while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK );

    }

    if (!quiet) printf( "Total events reported: %d\n", num_events );
    if (num_events>MAX_EVENTS) num_events=MAX_EVENTS;


    /* shut down the library */
    PAPI_shutdown();
    
	/* Initialize PAPI library again */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
       test_fail(test_string);
    }

    //    for(i=0;i<num_events;i++) {
    //  PAPI_event_name_to_code (event_names[i], &event_codes[i]);
    //}


    /* start some threads */


    retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) 
			       ( pthread_self ) );

    pthread_attr_init( &attr );

    if (!quiet) printf("Starting threads...\n");

    for(i=0;i<NUM_THREADS;i++) {
      rc = pthread_create( &threads[i], &attr, our_thread, NULL);
      if ( rc ) {
         test_fail( test_string);
      }
    }


    pthread_attr_destroy( &attr );

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

    if (!quiet) printf("Done with threads...\n");

    for(i=0;i<num_events;i++) {
      if (!quiet) printf("%x %s\n",event_codes[i],event_names[i]);
    }

    /* shut down the library again */
    PAPI_shutdown();

    test_pass(test_string);

    //    pthread_exit( NULL );


    return 0;

}