Exemple #1
0
void
get_env_variables(struct rapl_state_s *s){

	char *env = NULL;


	int package;

	int retVal = -1; 

	env = getenv("READ_ONLY");
	if(env == NULL){
		//Read only flag has not been set.
		//Ensure that it is still zero.
		s->mode.read_only_flag = 0;
	}
	if(env){
		s->mode.read_only_flag = strtoll(env,NULL,0);
	}

	env = getenv("READ_WRITE");
	
	if(env == NULL){
		//Read_write flag has not been set.
		//Ensure that it is still zero.
		s->mode.read_write_flag = 0;
	}
	if(env){
		s->mode.read_write_flag = strtoll(env,NULL,0);
	}

/* We are dealing with MSRs and need to be very careful, hence, if the 
 * environment variables contain any thing other than 1, none of the code
 * should run and it should default to the dry-run.
 * The dry_run_flag is always 1.
 * If read_write_flag is 1, it should not matter what the value of read_only_flag is. 
 *
 * If read_only_flag is 1, the read_write_flag has to be ZERO.
 *
 * */

	if(s->mode.dry_run_flag == 1){

              retVal = init_msr();
              if(retVal == -1){
                    fprintf(stderr, "Error in initialization. Exiting.\n");
                     _exit(EXIT_FAILURE);
              }
		
		/*READ_ONLY_MODE*/		
		if(s->mode.read_only_flag == 1){
			/*Need to determine what to do here. Output should probably be a file 
 			* with the measured power values. So, call init_msr(), 
 			* followed by the get_rapl_data(), followed by finalize_msr(). */ 	

			fprintf(stdout, "\nIn READ-ONLY mode.\n");

			//Now that the permissions are correct, first disable turbo.
			
			for(package=0;package<NUM_PACKAGES; package++){
				disable_turbo(package);
			}
	
//			You want to do this in here and not in rapl_init because it is safer to do it in here.
//			Also, in the dry run, none of this info should be printed.
//			You need to have read_msr access to be able to get the info/limit/status.
				
  			print_rapl_state_header(s);
       			 for(package=0; package<NUM_PACKAGES; package++){
                		get_all_info(  package, s);
              			get_all_limit( package, s);
               		 	get_all_status(package, s);
               	 		gettimeofday( &(s->start[package]), NULL );
       			 }

		}
	
		/*READ_WRITE_MODE. Care should be taken that the user has the right permissions, and
 		* that even if the environment variable is set, you can't write to MSRs unless 
 		* you have the right permissions. 
 		* Also, if both the read_write and read_only_flag are set, it should default to read_only 
 		* under the assumption that the use is not clear about how to use the library correctly */
	 

		if(s->mode.read_write_flag == 1 && s->mode.read_only_flag == 0){	

			fprintf(stdout, "\nIn READ-WRITE mode.\n");

			//Now that the permissions are correct, first disable turbo.
			
			for(package=0;package<NUM_PACKAGES; package++){
				disable_turbo(package);
			}
	
//			You want to do this in here and not in rapl_init because it is safer to do it in here.
  			print_rapl_state_header(s);
                         for(package=0; package<NUM_PACKAGES; package++){
			        get_all_info(  package, s);
                                get_all_limit( package, s);
                                get_all_status(package, s);
                                gettimeofday( &(s->start[package]), NULL );
                         }

			//Write to the POWER registers
			set_power_bounds();	
		}
	}
}
Exemple #2
0
static void mainboard_init(void *chip_info)
{
#if !CONFIG(ENABLE_TURBO)
	disable_turbo();
#endif
}