void rapl_finalize( struct rapl_state_s *s, int reset_limits){ int package; if(s->f == NULL){ printf("\n Error: File pointer should not be null. Something went wrong"); return; } if( s==NULL ){ printf("\n Error: State pointer should not be null. Something went wrong"); s = &no_caller_rapl_state; } if(s->initializedTick){ uint64_t tsc = rdtsc(); // require 10ms between ticks if(tsc_delta(&lastNonzeroTick, &tsc, &tsc_rate) > 0.01) rapl_tick(s, 0); } for(package=0; package<NUM_PACKAGES; package++){ get_all_status(package, s); if(reset_limits){ // Rest all limits. // This is currently the default limit on rzmerl. printf("\nRESETTING LIMITS\n"); write_msr( package, MSR_PKG_POWER_LIMIT, APPRO_DEFAULT_PKG_POWER_LIMIT); /* write_msr( package, MSR_PP0_POWER_LIMIT, 0 ); #ifdef ARCH_062D write_msr( package, MSR_DRAM_POWER_LIMIT, 0 ); #endif */ // These are currently locked out. //We had disabled turbo. The default is to leave this enabled. enable_turbo(package); } } // Now the print statement from hell. Call this only if it is not a dry-run //I.E., if we are in the read-only or the read-write modes. //Otherwise, the file should be empty. if(s->mode.dry_run_flag == 1 && s->mode.read_only_flag ==0 && s->mode.read_write_flag == 0){ fprintf(stdout, "\nIn DRY_RUN mode.\n"); finalize_msr(); } else { //This is either read-only or read_write mode. print_rapl_state(s); finalize_msr(); } }
void restore_defaults() { //No one else can enter now. in_handler = 1; int package; // Reset all limits. for(package=0; package<NUM_PACKAGES; package++){ write_msr( package, MSR_PKG_POWER_LIMIT, 0x6845000148398 ); /* write_msr( package, MSR_PP0_POWER_LIMIT, 0 ); #ifdef ARCH_062D write_msr( package, MSR_DRAM_POWER_LIMIT, 0 ); # endif */ // These are currently locked out. //Default is enabled for turbo boost enable_turbo(package); } //Close the /dev/cpu/msr files, in case they are open... finalize_msr(); //Now exit. //printf("In_handler is %d", in_handler); _exit(EXIT_FAILURE); //You can't reach here, so the value of in_handler stays 1 until we exit. No one //else can get in while it is 1 }
int main(int argc, char** argv){ #ifdef MPI MPI_Init(&argc, &argv); #endif int power; init_msr(); struct rapl_data r[NUM_SOCKETS]; int socket; for(socket=0; socket<NUM_SOCKETS; socket++) r[socket].flags = RDF_REENTRANT | RDF_INIT; // Initialize r for(socket=0; socket<NUM_SOCKETS; socket++) read_rapl_data(socket, &r[socket]); sleep(1); perform_rapl_measurement(r); for(power=5; power<150; power+=10) { rapl_set_test(power); sleep(10); perform_rapl_measurement(r); } finalize_msr(); #ifdef MPI MPI_Finalize(); #endif return 0; }