Exemple #1
0
int main(int argc, char** argv) {
  int n = 0;
  int i;
  const int MAX = atoi(argv[1]);

  int apps[1024];

   if(getenv("HEARTBEAT_ENABLED_DIR") == NULL) {
     fprintf(stderr, "ERROR: need to define environment variable HEARTBEAT_ENABLED_DIR (see README)\n");
     return 1;
   }

  heart_data_t* records = (heart_data_t*) malloc(MAX*sizeof(heart_data_t));
  int last_tag = -1;

  while(n == 0) {
    n = get_heartbeat_apps(apps);
  }

  //printf("apps[0] = %d\n", apps[0]);

  // For this test we only allow one heartbeat enabled app
  assert(n==1);

#if 1
  int rc = heart_rate_monitor_init(&heart, apps[0]);

  if (rc != 0)
    printf("Error attaching memory\n");

  printf("buffer depth is %lld\n", (long long int) heart.state->buffer_depth);

  i = 0;
  int current_tag = -1;
  while(last_tag < MAX-1) {
    heartbeat_record_t record;

    while(current_tag == last_tag) {
      int rc = -1;
      while (rc != 0)
	rc = hrm_get_current(&heart, &record);
      current_tag = record.tag;
    }
    records[i].tag = last_tag = current_tag;
    records[i].rate = record.window_rate;
    //printf("System: %d  %d\n", current_tag, last_tag);
    //    printf("System: %d, %f\n", records[i].tag, records[i].rate);
    i++;
  }

  //printf("System: Global heart rate: %f, Current heart rate: %f\n", heart.global_heartrate, heart.window_heartrate);

  for(i = 0; i < MAX; i++) {
    printf("%d, %f\n", records[i].tag, records[i].rate);
  }
  heart_rate_monitor_finish(&heart);
#endif

  return 0;
}
int main(int argc, char** argv) {
  int n = 0;
  int i;
  const int MAX = atoi(argv[1]);
  const int CORES = atoi(argv[2]);
  int ncpus=0;

  int apps[1024];

/**/
        extern char *optarg;
	extern int optind, opterr, optopt;
	int ret = 0, cont = 1;
	unsigned int cpu = 0;
	//unsigned int cpu_defined = 0;
        unsigned long  min_available_freq = 0;
        unsigned long max_available_freq = 0;  
        unsigned long current_freq = 0;
        unsigned long initial_freq = 0;
        struct cpufreq_available_frequencies *freqs;
        int retr =0;

	setlinebuf(stdout);

   ncpus=get_cpus();

if(!CORES){
           CORES == ncpus;
           }


if (CORES > ncpus){
 printf("Wrong number of inital cores");
 exit(2);
}

  ret= get_hardware_limits(cpu);

  min_available_freq = min;
  max_available_freq = max;

  ret= set_policy(CORES);

  freqs = cpufreq_get_available_frequencies(0);

/*if (freqs==null){
  goto out;
}*/

  current = get_available_freqs_size(freqs);

  unsigned long* available_freqs = (unsigned long *) malloc(current*sizeof(unsigned long));


  ret = store_available_freqs( freqs, available_freqs, current);

  int current_counter = get_init_frequency(available_freqs, cpu);

  /*if (ret!=0){
               goto out;
                }*/


  current_freq = cpufreq_get_freq_kernel(cpu);


   if(getenv("HEARTBEAT_ENABLED_DIR") == NULL) {
     fprintf(stderr, "ERROR: need to define environment variable HEARTBEAT_ENABLED_DIR (see README)\n");
     return 1;
   }

  heart_data_t* records = (heart_data_t*) malloc(MAX*sizeof(heart_data_t));
  int last_tag = -1;

  while(n == 0) {
    n = get_heartbeat_apps(apps);
  }

  printf("apps[0] = %d\n", apps[0]);

  // For this test we only allow one heartbeat enabled app
 // assert(n==1);
  if (n>1) {
     printf("too many apps!!!!!!!!!!!!!!\n");
     exit(2);
  }

/*  sleep(5);*/

#if 1
  int rc = heart_rate_monitor_init(&heart, apps[0]);

  if (rc != 0)
    printf("Error attaching memory\n");

  printf("buffer depth is %lld\n", (long long int) heart.state->buffer_depth);

  i = 0;
      printf(" rate interval is %f - %f\n", hrm_get_min_rate(&heart), hrm_get_max_rate(&heart));


printf("beat\trate\tfreq\tcores\ttact\twait\n");

  int64_t window_size =  hrm_get_window_size(&heart);
  int wait_for = (int) window_size;
  int current_beat = 0;
  int current_beat_prev= 0;
  int nprocs = 1;
  unsigned int set_freq = min;
 

  // return 1;  
    
  while(current_beat < MAX) {
    int rc = -1;
    heartbeat_record_t record;
    char command[256];


      while (rc != 0 || record.window_rate == 0.0000 ){
	rc = hrm_get_current(&heart, &record);
	current_beat = record.beat;
      }
        
       
      if(current_beat_prev == current_beat)
      continue;
    /*  printf(" rc: %d, current_beat:%d \n", rc,current_beat);*/
    /*Situation where doesn't happen nothing*/   
      if( current_beat < wait_for){
          current_beat_prev= current_beat;
         /* printf("I am in situation wait_for\n");*/
                current_freq = cpufreq_get_freq_kernel(0);
		print_status(&record, wait_for, current_freq, '.', CORES);
        continue;
      }


    /*  printf("Current beat is %d, wait_for = %d, %f\n", current_beat, wait_for, record.window_rate);*/

       /*Situation where frequency is up-scaled*/
      if(record.window_rate < hrm_get_min_rate(&heart)) {  
 

  	wait_for = current_beat + window_size;      
        

         if (current_counter > 0){

          int cpu;
              current_counter--;  
             set_freq = get_speed(available_freqs[current_counter]);

             for (cpu=0; cpu <=CORES; cpu++) {
	    /*   sprintf(command, "cpufreq-set -c %d -f %luMHZ", cpu,set_freq);*/
	       /* printf("Executing %s\n", command);*/
             /*  system(command);*/
		cpufreq_set_frequency(cpu, available_freqs[current_counter]);

             }

             current_freq = cpufreq_get_freq_kernel(0);
		print_status(&record, wait_for, current_freq, '+', CORES);
            }

       else {
          current_freq = cpufreq_get_freq_kernel(0);
		print_status(&record, wait_for, current_freq, 'M', CORES);

         }
      }

     /*Situation where frequency is downscaled*/

      else if(record.window_rate > hrm_get_max_rate(&heart)) {
	wait_for = current_beat + window_size;       
       if (current_counter < current){
          current_counter++;
          set_freq = get_speed(available_freqs[current_counter]);
          for (cpu=0; cpu <=CORES; cpu++) {
         /* sprintf(command, " cpufreq-set -c %d -f %uMHZ", cpu,set_freq);*/
	 /* printf("Executing %s\n", command);*/
	  /*system(command);*/
		cpufreq_set_frequency(cpu, available_freqs[current_counter]);
          }
        
         current_freq = cpufreq_get_freq_kernel(0);
		print_status(&record, wait_for, current_freq, '-', CORES);
          }
	

        else {
          current_freq = cpufreq_get_freq_kernel(0);
		print_status(&record, wait_for, current_freq, 'm', CORES);

        }
		

      }

      else {
	wait_for = current_beat+1;
	print_status(&record, wait_for, current_freq, '=', CORES);
      }
      current_beat_prev= current_beat;
      records[i].tag = current_beat;
      records[i].rate = record.window_rate;
      i++;
   

  }

  //printf("System: Global heart rate: %f, Current heart rate: %f\n", heart.global_heartrate, heart.window_heartrate);

/*  for(i = 0; i < MAX; i++) {
    printf("%d, %f\n", records[i].tag, records[i].rate);
  }*/
  heart_rate_monitor_finish(&heart);
#endif

  return 0;
}
Exemple #3
0
int main(int argc, char** argv) {
  int n = 0;
  int i;
  const int MAX = atoi(argv[1]);

  int apps[1024];

   if(getenv("HEARTBEAT_ENABLED_DIR") == NULL) {
     fprintf(stderr, "ERROR: need to define environment variable HEARTBEAT_ENABLED_DIR (see README)\n");
     return 1;
   }

  heart_data_t* records = (heart_data_t*) malloc(MAX*sizeof(heart_data_t));
  int last_tag = -1;

  while(n == 0) {
    n = get_heartbeat_apps(apps);
  }

  //printf("apps[0] = %d\n", apps[0]);

  // For this test we only allow one heartbeat enabled app
  assert(n==1);

  sleep(5);

#if 1
  int rc = heart_rate_monitor_init(&heart, apps[0]);

  if (rc != 0)
    printf("Error attaching memory\n");

  printf("buffer depth is %lld\n", (long long int) heart.state->buffer_depth);

  i = 0;


  int64_t window_size =  hrm_get_window_size(&heart);
  int wait_for = (int) window_size;
  int current_beat = 0;
  int nprocs = 1;
  printf("Current beat is %d, wait_for = %d\n", current_beat, wait_for);

  // return 1;  
    
  while(current_beat < MAX-1) {
    int rc = -1;
    heartbeat_record_t record;
    char command[256];


      while (rc != 0 || record.window_rate == 0.0000 ){
	rc = hrm_get_current(&heart, &record);
	current_beat = record.beat;
      }
   
      if( current_beat < wait_for)
	continue;

      printf("Current beat is %d, wait_for = %d, %f\n", current_beat, wait_for, record.window_rate);

      if(record.window_rate < hrm_get_min_rate(&heart)) {
	nprocs++;
	sprintf(command, "taskset -pc 0-%d %d >& /dev/null",nprocs-1,apps[0]);
	printf("Executing %s\n", command);
	system(command);
	wait_for = current_beat + window_size;	
      }
      else if(record.window_rate > hrm_get_max_rate(&heart)) {
	nprocs--;
	sprintf(command, "taskset -pc 0-%d %d >& /dev/null",nprocs-1,apps[0]);
	system(command);	
	wait_for = current_beat + window_size;
      }
      else {
	wait_for = current_beat+1;
      }
      records[i].tag = current_beat;
      records[i].rate = record.window_rate;
      i++;
   

  }

  //printf("System: Global heart rate: %f, Current heart rate: %f\n", heart.global_heartrate, heart.window_heartrate);

  for(i = 0; i < MAX; i++) {
    printf("%d, %f\n", records[i].tag, records[i].rate);
  }
  heart_rate_monitor_finish(&heart);
#endif

  return 0;
}
Exemple #4
0
int main(int argc, char **argv)
{
	int n_apps = 0;
	int apps[16];
	int err;
	int i;
	int64_t window_size;
	int64_t skip_until_beat = 0;
	int64_t last_beat = 0;
	heartbeat_record_t current;
	int core_count;
	int opt;
	int max_beats = INT_MAX;
	
	extern int actuator_count;
	extern actuator_t *controls;
	actuator_t *next_ctl;
	
	decision_function_t decision_f = machine_state_controller;
	int acted;

	/* we want to see this in realtime even when it's piped through tee */
	setlinebuf(stdout);
	
	/* getting rich with stock options */	
	while ((opt = getopt(argc, argv, "d:")) != -1) switch (opt) {
		case 'd':
			if (strcmp(optarg, "core_heuristics") == 0) decision_f = core_heuristics;
			else if (strcmp(optarg, "freq_heuristics") == 0) decision_f = freq_heuristics;
			else if (strcmp(optarg, "uncoordinated_heuristics") == 0) decision_f = uncoordinated_heuristics;
			else if (strcmp(optarg, "step_heuristics") == 0) decision_f = step_heuristics;
			else if (strcmp(optarg, "core_controller") == 0) decision_f = core_controller;
			else if (strcmp(optarg, "machine_state_controller") == 0) decision_f = machine_state_controller;
			else {
				fprintf(stderr, "%s: unknown decision function\n", argv[0]);
				exit(1);
			}
			break;
		default:
			fprintf(stderr, "Usage: %s [-d decision_function]\n", argv[0]);
			exit(1);
	}	
	argc -= optind;
	argv += optind;	
	if (argc > 1)
		max_beats = argv[1];
	
	/* setupping arbit */
	heartbeat_dir = getenv("HEARTBEAT_ENABLED_DIR");
	fail_if(heartbeat_dir == NULL, "environment variable HEARTBEAT_ENABLED_DIR undefined");
	
	while (n_apps == 0)
		n_apps = get_heartbeat_apps(apps, sizeof(apps)/sizeof(apps[0]));
	fail_if(n_apps != 1, "this service only supports a single app. please delete c:\\system32");
	printf("monitoring process %d\n", apps[0]);
	
	/* initrogenizing old river control structure */
	core_count = get_core_count();
	actuator_count = core_count + 3;
	
	controls = malloc(sizeof(actuator_t) * actuator_count);
	fail_if(!controls, "could not allocate actuators");
	/* PROBLEM!!!!! the machine speed actuator needs to init last, but act first! WHAT NOW */
	/* create the list in action order, but init in special order... QUICK AND DIRTY = OPTIMAL */
	next_ctl = controls;
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_MACHINE_SPD, .core = -1, .pid = apps[0], .init_f = machine_speed_init, .action_f = machine_speed_act };
	for (i = 0; i < core_count; i++)
		*next_ctl++ = (actuator_t) { .id = ACTUATOR_SINGLE_FREQ, .core = i,  .pid = -1,      .init_f = single_freq_init,   .action_f = single_freq_act };
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_GLOBAL_FREQ, .core = -1, .pid = -1,      .init_f = global_freq_init,   .action_f = global_freq_act };
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_CORE_COUNT,  .core = -1, .pid = apps[0], .init_f = core_init,          .action_f = core_act };
	
	
	for (i = 1; i < actuator_count; i++) {
		err = controls[i].init_f(&controls[i]);
		fail_if(err, "cannot initialize actuator");
	}
	/* initialize machine speed actuator last! */
	err = controls[0].init_f(&controls[0]);
	fail_if(err, "cannot initialize actuator");
	
	/* begin monitoration of lone protoss */
	err = heart_rate_monitor_init(&hrm, apps[0]);
	fail_if(err, "cannot start heart rate monitor");
	
	window_size = hrm_get_window_size(&hrm);
	current.beat = -1;
	
	do {
		do {
			err = hrm_get_current(&hrm, &current);
		} while (err || current.beat <= last_beat || current.window_rate == 0.0);

		last_beat = current.beat;
		if (current.beat < skip_until_beat) {
			print_status(&current, skip_until_beat, '.', actuator_count, controls);
			continue;
		}
		
		/*printf("Current beat: %lld, tag: %d, window: %lld, window_rate: %f\n",
			   current.beat, current.tag, window_size, current.window_rate);*/
		
		decision_f(&current, actuator_count, controls);
		
		acted = 0;
		for (i = 0; i < actuator_count; i++) {
			actuator_t *act = &controls[i];
			if (act->set_value != act->value) {
#if DEBUG
				printf("act %d: %d -> %d\n", i, act->value, act->set_value);
#endif
				err = act->action_f(act);	/* TODO: handle error */
				if (err) fprintf(stderr, "action %d failed: %s\n", act->id, strerror(errno));
				acted = 1;
			}
		}
		/* this is horrible but necessary */
		controls[0].value = get_current_speed(&controls[0]);

		skip_until_beat = current.beat + (acted ? window_size : 1);
		
		print_status(&current, skip_until_beat, acted ? '*' : '=', actuator_count, controls);
	} while (current.beat < max_beats);
	
	heart_rate_monitor_finish(&hrm);
	
	return 0;
fail:
	return 1;
}

/* here are some globals without lexical scoping, just to mix things up! */
int actuator_count;
actuator_t *controls;