コード例 #1
0
ファイル: msr_rapl.c プロジェクト: tpatki/rapl-old-data
//Peter's version.
void
rapl_tick(struct rapl_state_s *s, const char * const filename){

  if(s==NULL){
		//printf("\n Error: State is null here.");
		//exit(1);
		s = &no_caller_rapl_state;
	}
	
//	printf("\n In rapl_tick");

  int package, core;
  if( !s->initializedTick ){
    s->initializedTick=1;
    s->tickFile = fopen( filename, "w" );
    for( package=0; package<NUM_PACKAGES; package++ ){
      gettimeofday( &(s->start[package]), NULL );
      gettimeofday( &(s->finish[package]), NULL );
      get_all_info(  package, s);
      get_all_limit( package, s);
      get_all_status(package, s);
      get_effective_frequencies(package, s);
      fprintf( s->tickFile,
               "ts_%d\telapsed_%d\tpkg_%d\tpp0_%d\tdram_%d\t",
               package, package, package, package, package);
      for(core = 0; core < NUM_CORES_PER_PACKAGE; core++)
        fprintf(s->tickFile, "freq_ratio_%d_%d\tc0_ratio_%d_%d\t",
                package, core, package, core);
    }
    fprintf( s->tickFile, "\n" );
    return;
  }

  for( package = 0; package < NUM_PACKAGES; package++ ){
    get_all_status(package, s);
    get_effective_frequencies(package, s);
    fprintf(s->tickFile, "%ld.%06ld\t%lf\t%lf\t%lf\t%lf\t",
             s->finish[package].tv_sec,
             s->finish[package].tv_usec,
             s->interval[package],
             s->avg_watts[package][PKG_DOMAIN],
             s->avg_watts[package][PP0_DOMAIN],
             s->avg_watts[package][DRAM_DOMAIN]);
    //s->effective_freq_ratio[package] );
    for(core = 0; core < NUM_CORES_PER_PACKAGE; core++)
      fprintf(s->tickFile, "%lf\t%lf\t",
              s->effective_freq_ratio[package * NUM_CORES_PER_PACKAGE + core],
              s->c0_ratio[package * NUM_CORES_PER_PACKAGE + core]);
  }
  fprintf( s->tickFile, "\n");
}
コード例 #2
0
ファイル: msr_rapl.c プロジェクト: ngholka/patki-power
void
rapl_tick(const char *filetag){
	static char filename[4097];
	int package;
	static struct rapl_state_s s;
	static int initialized=0;
	if( !initialized ){
		initialized=1;
		if( filetag == NULL ){
			filetag = "anonymous";
		}
		snprintf( filename, 4096, "%s.tick.out", filetag );
		s.f = fopen( filename, "w" );
		for( package=0; package<NUM_PACKAGES; package++ ){
			gettimeofday( &(s.start[package]), NULL );
			gettimeofday( &(s.finish[package]), NULL );
			get_all_info(  package, &s);
			get_all_limit( package, &s);
			get_all_status(package, &s);
			s.effective_frequency[package] = get_effective_frequency(package);
			fprintf( s.f, "ts_%d elapsed_%d pkg_%d pp0_%d dram_%d ef_%d",
			      package, package, package, package, package, package );
		}
		fprintf( s.f, "\n" );
		return;	
	}

	for( package=0; package<NUM_PACKAGES; package++ ){
		get_all_status(package, &s);
		s.effective_frequency[package] = get_effective_frequency(package);
		fprintf( s.f, "%ld.%06ld %lf ", s.finish[package].tv_sec, s.finish[package].tv_usec, s.elapsed[package] );
		fprintf( s.f, "%lf %lf %lf ", 
				s.avg_watts[package][PKG_DOMAIN],
				s.avg_watts[package][PP0_DOMAIN],
				s.avg_watts[package][DRAM_DOMAIN]);
		fprintf( s.f, "%lf ", s.effective_frequency[package] );
	}
	fprintf( s.f, "\n");
}
コード例 #3
0
Add DragonFly support (kernel poc can return pids of 0 and -1, skip these)

--- proctree.c.orig	2013-07-13 07:23:21.078939000 +0000
+++ proctree.c
@@ -170,6 +170,7 @@ int update_tree(void del(void*))
 #ifdef HAVE_PROCESS_SYSCTL
 	el = get_all_info(&pi);
 	for(i = 0; i < el; i++) {
+		if (pi[i].kp_pid < 1) continue;
 		p = validate_proc(pi[i].kp_pid);
 		q = validate_proc(pi[i].kp_ppid);
 #else
コード例 #4
0
ファイル: msr_opt.c プロジェクト: ngholka/patki-power
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();	
		}
	}
}