Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix energy plugin wrt idle time
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 3 Feb 2015 00:17:09 +0000 (01:17 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 3 Feb 2015 00:50:49 +0000 (01:50 +0100)
- Count the last idle period when the host is destroyed
- More informative debug messages in the plugin
- More informative messages in the example (to make computations
  manually enforcable)

examples/msg/energy/e2/e2.c
src/surf/plugins/energy.cpp

index 1be86ff..ee19dd8 100644 (file)
@@ -24,51 +24,55 @@ int dvfs(int argc, char *argv[])
 {
   msg_host_t host = NULL;
   msg_task_t task1 = NULL;
 {
   msg_host_t host = NULL;
   msg_task_t task1 = NULL;
-  double task_time = 0;
   host = MSG_get_host_by_name("MyHost1");
 
 
   host = MSG_get_host_by_name("MyHost1");
 
 
-  double current_peak = MSG_get_host_current_power_peak(host);
-  XBT_INFO("Current power peak=%f", current_peak);
+  XBT_INFO("Energetic profile: %s",
+                 MSG_host_get_property_value(host,"watt_per_state"));
+  XBT_INFO("Initial power peak=%.0E flop/s; Consumed energy (Joules)=%.0E J",
+                 MSG_get_host_current_power_peak(host), MSG_get_host_consumed_energy(host));
 
 
-  double consumed_energy = MSG_get_host_consumed_energy(host);
-  XBT_INFO("Total energy (Joules): %f", consumed_energy);
+  double start = MSG_get_clock();
+  XBT_INFO("Sleep for 10 seconds");
+  MSG_process_sleep(10);
+  XBT_INFO("Done sleeping (duration: %.2f s). Current power peak=%.0E; Current consumed energy=%.2f J",
+                 MSG_get_clock()-start,
+                 MSG_get_host_current_power_peak(host), MSG_get_host_consumed_energy(host));
 
   // Run a task
 
   // Run a task
+  start = MSG_get_clock();
+  XBT_INFO("Run a task for 100E6 flops");
   task1 = MSG_task_create ("t1", 100E6, 0, NULL);
   MSG_task_execute (task1);
   MSG_task_destroy(task1);
   task1 = MSG_task_create ("t1", 100E6, 0, NULL);
   MSG_task_execute (task1);
   MSG_task_destroy(task1);
-
-  task_time = MSG_get_clock();
-  XBT_INFO("Task1 simulation time: %e", task_time);
-  consumed_energy = MSG_get_host_consumed_energy(host);
-  XBT_INFO("Total energy (Joules): %f", consumed_energy);
+  XBT_INFO("Task done (duration: %.2f s). Current power peak=%.0E flop/s; Current consumed energy=%.0f J",
+                 MSG_get_clock()-start,
+                 MSG_get_host_current_power_peak(host), MSG_get_host_consumed_energy(host));
 
   // ========= Change power peak =========
 
   // ========= Change power peak =========
-  int peak_index=2;
-  double peak_at = MSG_get_host_power_peak_at(host, peak_index);
-  XBT_INFO("=========Changing power peak value to %f (at index %d)", peak_at, peak_index);
-
-  MSG_set_host_power_peak_at(host, peak_index);
+  int pstate=2;
+  MSG_set_host_power_peak_at(host, pstate);
+  XBT_INFO("========= Requesting pstate %d (power should be of %.2f flop/s and is of %.2f flop/s",
+                 pstate,
+                 MSG_get_host_power_peak_at(host, pstate),
+                 MSG_get_host_current_power_peak(host));
 
   // Run a second task
 
   // Run a second task
+  start = MSG_get_clock();
+  XBT_INFO("Run a task for 100E6 flops");
   task1 = MSG_task_create ("t2", 100E6, 0, NULL);
   MSG_task_execute (task1);
   MSG_task_destroy(task1);
   task1 = MSG_task_create ("t2", 100E6, 0, NULL);
   MSG_task_execute (task1);
   MSG_task_destroy(task1);
+  XBT_INFO("Task done (duration: %.2f s). Current power peak=%.0E flop/s; Current consumed energy=%.0f J",
+                 MSG_get_clock()-start,
+                 MSG_get_host_current_power_peak(host), MSG_get_host_consumed_energy(host));
 
 
-  task_time = MSG_get_clock() - task_time;
-  XBT_INFO("Task2 simulation time: %e", task_time);
-
-  consumed_energy = MSG_get_host_consumed_energy(host);
-  XBT_INFO("Total energy (Joules): %f", consumed_energy);
-
-
-  MSG_process_sleep(3);
-
-  task_time = MSG_get_clock() - task_time;
-  XBT_INFO("Task3 (sleep) simulation time: %e", task_time);
-  consumed_energy = MSG_get_host_consumed_energy(host);
-  XBT_INFO("Total energy (Joules): %f", consumed_energy);
+  start = MSG_get_clock();
+  XBT_INFO("Sleep for 10 seconds");
+  MSG_process_sleep(4);
+  XBT_INFO("Done sleeping (duration: %.2f s). Current power peak=%.0E flop/s; Current consumed energy=%.0f J",
+                 MSG_get_clock()-start,
+                 MSG_get_host_current_power_peak(host), MSG_get_host_consumed_energy(host));
 
   return 0;
 }
 
   return 0;
 }
@@ -97,7 +101,7 @@ int main(int argc, char *argv[])
 
   res = MSG_main();
 
 
   res = MSG_main();
 
-  XBT_INFO("Total simulation time: %e", MSG_get_clock());
+  XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
 
   if (res == MSG_OK)
     return 0;
 
   if (res == MSG_OK)
     return 0;
index 6c55cf4..1ade83f 100644 (file)
@@ -23,12 +23,31 @@ static void energyCpuCreatedCallback(CpuPtr cpu){
   (*surf_energy)[cpu] = new CpuEnergy(cpu);
 }
 
   (*surf_energy)[cpu] = new CpuEnergy(cpu);
 }
 
+static void update_consumption(CpuPtr cpu, CpuEnergyPtr cpu_energy) {
+       double cpu_load = lmm_constraint_get_usage(cpu->getConstraint()) / cpu->m_powerPeak;
+       double start_time = cpu_energy->last_updated;
+       double finish_time = surf_get_clock();
+
+       double current_energy = cpu_energy->total_energy;
+       double action_energy = cpu_energy->getCurrentWattsValue(cpu_load)*(finish_time-start_time);
+
+       cpu_energy->total_energy = current_energy + action_energy;
+       cpu_energy->last_updated = finish_time;
+
+       XBT_DEBUG("[cpu_update_energy] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
+                 start_time, finish_time, cpu->m_powerPeak, current_energy, action_energy);
+}
+
 static void energyCpuDestructedCallback(CpuPtr cpu){
 static void energyCpuDestructedCallback(CpuPtr cpu){
-  std::map<CpuPtr, CpuEnergyPtr>::iterator cpuIt = surf_energy->find(cpu);
-  xbt_assert(cpuIt != surf_energy->end(), "The cpu is not in surf_energy.");
-  XBT_INFO("Total energy (Joules) of host %s: %f", cpu->getName(), cpuIt->second->getConsumedEnergy());
-  delete cpuIt->second;
-  surf_energy->erase(cpuIt);
+  std::map<CpuPtr, CpuEnergyPtr>::iterator cpu_energy_it = surf_energy->find(cpu);
+  xbt_assert(cpu_energy_it != surf_energy->end(), "The cpu is not in surf_energy.");
+
+  CpuEnergyPtr cpu_energy = cpu_energy_it->second;
+  update_consumption(cpu, cpu_energy);
+
+  XBT_INFO("Total energy of host %s: %f Joules", cpu->getName(), cpu_energy->getConsumedEnergy());
+  delete cpu_energy_it->second;
+  surf_energy->erase(cpu_energy_it);
 }
 
 static void energyCpuActionStateChangedCallback(CpuActionPtr action, e_surf_action_state_t old, e_surf_action_state_t cur){
 }
 
 static void energyCpuActionStateChangedCallback(CpuActionPtr action, e_surf_action_state_t old, e_surf_action_state_t cur){
@@ -36,21 +55,7 @@ static void energyCpuActionStateChangedCallback(CpuActionPtr action, e_surf_acti
   CpuEnergyPtr cpu_energy = (*surf_energy)[cpu];
 
   if(cpu_energy->last_updated < surf_get_clock()) {
   CpuEnergyPtr cpu_energy = (*surf_energy)[cpu];
 
   if(cpu_energy->last_updated < surf_get_clock()) {
-       double cpu_load = lmm_constraint_get_usage(cpu->getConstraint()) / cpu->m_powerPeak;
-    double start_time = cpu_energy->last_updated;
-    double finish_time = surf_get_clock();
-
-    /*XBT_DEBUG("[cpu_update_energy] action time interval=(%f-%f), current power peak=%f, current pstate=%d",
-                 start_time, finish_time, cpu->m_powerPeak, cpu->m_pstate);*/
-    XBT_DEBUG("[cpu_update_energy] action time interval=(%f-%f), current power peak=%f",
-                 start_time, finish_time, cpu->m_powerPeak);
-    double current_energy = cpu_energy->total_energy;
-    double action_energy = cpu_energy->getCurrentWattsValue(cpu_load)*(finish_time-start_time);
-
-    cpu_energy->total_energy = current_energy + action_energy;
-    cpu_energy->last_updated = finish_time;
-
-    XBT_DEBUG("[cpu_update_energy] old_energy_value=%f, action_energy_value=%f", current_energy, action_energy);
+         update_consumption(cpu, cpu_energy);
   }
 }
 
   }
 }