Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into fix/execute_benched
[simgrid.git] / src / surf / plugins / host_energy.cpp
index bc636d3..21853c6 100644 (file)
@@ -66,7 +66,7 @@ the time, and our model holds.
 ### What if the host has only one core?
 
 In this case, the parameters \b OneCore and \b AllCores are obviously the same.
-Actually, SimGrid expect an energetic profile formated as 'Idle:Running' for mono-cores hosts.
+Actually, SimGrid expect an energetic profile formatted as 'Idle:Running' for mono-cores hosts.
 If you insist on passing 3 parameters in this case, then you must have the same value for \b OneCore and \b AllCores.
 
 \code{.xml}
@@ -110,7 +110,7 @@ before you can get accurate energy predictions.
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF energy plugin");
 
 namespace simgrid {
-namespace energy {
+namespace plugin {
 
 class PowerRange {
 public:
@@ -174,7 +174,7 @@ void HostEnergy::update()
       // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN
       cpu_load = 1;
     else
-      cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / current_speed;
+      cpu_load = host->pimpl_cpu->constraint()->get_usage() / current_speed;
 
     /** Divide by the number of cores here **/
     cpu_load /= host->pimpl_cpu->coreCount();
@@ -200,7 +200,7 @@ void HostEnergy::update()
 
     double energy_this_step = instantaneous_consumption * (finish_time - start_time);
 
-    // TODO Trace: Trace energy_this_step from start_time to finish_time in host->name()
+    // TODO Trace: Trace energy_this_step from start_time to finish_time in host->getName()
 
     this->total_energy = previous_energy + energy_this_step;
     this->last_updated = finish_time;
@@ -250,6 +250,14 @@ double HostEnergy::getCurrentWattsValue(double cpu_load)
 {
   xbt_assert(not power_range_watts_list.empty(), "No power range properties specified for host %s", host->getCname());
 
+ /*
+  *    * Return watts_off if pstate == pstate_off
+  *       * this happens when host is off
+  */
+  if (this->pstate == pstate_off) {
+    return watts_off;
+  }
+
   /* min_power corresponds to the power consumed when only one core is active */
   /* max_power is the power consumed at 100% cpu load       */
   auto range           = power_range_watts_list.at(this->pstate);
@@ -310,7 +318,7 @@ void HostEnergy::initWattsRangeList()
   XBT_DEBUG("%s: profile: %s, cores: %d", host->getCname(), all_power_values_str, host->getCoreCount());
 
   int i = 0;
-  for (auto current_power_values_str : all_power_values) {
+  for (auto const& current_power_values_str : all_power_values) {
     /* retrieve the power values associated with the current pstate */
     std::vector<std::string> current_power_values;
     boost::split(current_power_values, current_power_values_str, boost::is_any_of(":"));
@@ -325,7 +333,7 @@ void HostEnergy::initWattsRangeList()
       } else { // size == 3
         xbt_assert((current_power_values.at(1)) == (current_power_values.at(2)),
                    "Power properties incorrectly defined for host %s.\n"
-                   "The energy profile of mono-cores should be formated as 'Idle:FullSpeed' only.\n"
+                   "The energy profile of mono-cores should be formatted as 'Idle:FullSpeed' only.\n"
                    "If you go for a 'Idle:OneCore:AllCores' power profile on mono-cores, then OneCore and AllCores "
                    "must be equal.",
                    host->getCname());
@@ -355,7 +363,7 @@ void HostEnergy::initWattsRangeList()
 }
 }
 
-using simgrid::energy::HostEnergy;
+using simgrid::plugin::HostEnergy;
 
 /* **************************** events  callback *************************** */
 static void onCreation(simgrid::s4u::Host& host)
@@ -363,14 +371,14 @@ static void onCreation(simgrid::s4u::Host& host)
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
-  //TODO Trace: set to zero the energy variable associated to host->name()
+  // TODO Trace: set to zero the energy variable associated to host->getName()
 
   host.extension_set(new HostEnergy(&host));
 }
 
 static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf::Action::State previous)
 {
-  for (simgrid::surf::Cpu* cpu : action->cpus()) {
+  for (simgrid::surf::Cpu* const& cpu : action->cpus()) {
     simgrid::s4u::Host* host = cpu->getHost();
     if (host != nullptr) {
 
@@ -432,7 +440,7 @@ static void onSimulationEnd()
 }
 
 /* **************************** Public interface *************************** */
-SG_BEGIN_DECL()
+extern "C" {
 
 /** \ingroup plugin_energy
  * \brief Enable host energy plugin
@@ -464,7 +472,7 @@ void sg_host_energy_update_all()
   simgrid::simix::kernelImmediate([]() {
     std::vector<simgrid::s4u::Host*> list;
     simgrid::s4u::Engine::getInstance()->getHostList(&list);
-    for (auto host : list)
+    for (auto const& host : list)
       if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host) == nullptr) // Ignore virtual machines
         host->extension<HostEnergy>()->update();
   });
@@ -510,8 +518,7 @@ double sg_host_get_current_consumption(sg_host_t host)
 {
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
              "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
-  double cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / host->getSpeed();
+  double cpu_load = host->pimpl_cpu->constraint()->get_usage() / host->getSpeed();
   return host->extension<HostEnergy>()->getCurrentWattsValue(cpu_load);
 }
-
-SG_END_DECL()
+}