JNIEXPORT jlong JNICALL Java_virtualtime_EventNotifiervtonly__1getPapiRealTime (JNIEnv *, jclass) { #if USING_PERFCTR == 0 return PAPI_get_real_nsec(); #else return PERFCTR_getRT(); #endif }
LevelDBBlockStore::LevelDBBlockStore() { opened = false; std::ostringstream oss; oss << "temp_block_store_" << PAPI_get_real_nsec(); Open(oss.str()); #ifdef ASYNC_BSTORE // start a thread to consume key-value pairs in the queue multi_thread_running = true; pthread_create(&write_thread, NULL, &writeThreadFunction, this); #endif }
const pwr_emeas_t *pwr_stop_energy_count(pwr_ctx_t *ctx) { // fast status check here if (ctx == NULL || !(ctx->module_init & (1U << PWR_MODULE_ENERGY))) { return &emeas_zero; } if (!ctx->emeas_running) { ctx->error = PWR_UNAVAILABLE; return &emeas_zero; } PAPI_stop(ctx->event_set, ctx->emeas->values); ctx->emeas->duration = (PAPI_get_real_nsec() - ctx->emeas->duration) / 1e9; ctx->emeas_running = false; ctx->error = PWR_OK; return ctx->emeas; }
void pwr_start_energy_count(pwr_ctx_t *ctx) { if (ctx == NULL) { ctx->error = PWR_INIT_ERR; return; } if (!pwr_is_initialized(ctx, PWR_MODULE_ENERGY)) { ctx->error = PWR_UNINITIALIZED; return; } ctx->error = PWR_OK; if (ctx->emeas_running) { pwr_stop_energy_count(ctx); } PAPI_reset(ctx->event_set); ctx->emeas->duration = PAPI_get_real_nsec(); ctx->emeas_running = true; PAPI_start(ctx->event_set); }
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 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; }
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; }
void initBlockStore() { ostringstream oss; oss << "temp_block_store_" << PAPI_get_real_nsec(); _blockStore = new ConfigurableBlockStore(oss.str()); _ram = new RAMImpl(_blockStore); }