Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
put all of the host_energy plugin in one file only
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Feb 2017 14:51:36 +0000 (15:51 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Feb 2017 14:51:48 +0000 (15:51 +0100)
src/surf/cpu_interface.cpp
src/surf/plugins/energy.hpp [deleted file]
src/surf/plugins/host_energy.cpp [moved from src/surf/plugins/energy.cpp with 79% similarity]
tools/cmake/DefinePackages.cmake

index 8e9569f..260f49c 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <xbt/dynar.h>
 #include "cpu_interface.hpp"
 
 #include <xbt/dynar.h>
 #include "cpu_interface.hpp"
-#include "plugins/energy.hpp"
 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
 
 XBT_LOG_EXTERNAL_CATEGORY(surf_kernel);
 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
 
 XBT_LOG_EXTERNAL_CATEGORY(surf_kernel);
diff --git a/src/surf/plugins/energy.hpp b/src/surf/plugins/energy.hpp
deleted file mode 100644 (file)
index 26fa299..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/* energy.hpp: internal interface to the energy plugin                      */
-
-/* Copyright (c) 2014-2016. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include <xbt/base.h>
-
-#include <utility>
-
-#include "src/surf/HostImpl.hpp"
-
-#ifndef ENERGY_CALLBACK_HPP_
-#define ENERGY_CALLBACK_HPP_
-
-namespace simgrid {
-namespace energy {
-
-class XBT_PRIVATE HostEnergy;
-
-class PowerRange {
-  public: 
-  double idle;
-  double min;
-  double max;
-
-  PowerRange(double idle, double min, double max) : idle(idle), min(min), max(max) {
-  }
-};
-
-class HostEnergy {
-public:
-  static simgrid::xbt::Extension<simgrid::s4u::Host, HostEnergy> EXTENSION_ID;
-
-  explicit HostEnergy(simgrid::s4u::Host *ptr);
-  ~HostEnergy();
-
-  double getCurrentWattsValue(double cpu_load);
-  double getConsumedEnergy();
-  double getWattMinAt(int pstate);
-  double getWattMaxAt(int pstate);
-  void update();
-
-private:
-  void initWattsRangeList();
-  simgrid::s4u::Host *host = nullptr;
-  std::vector<PowerRange> power_range_watts_list;   /*< List of (min_power,max_power) pairs corresponding to each cpu pstate */
-public:
-  double watts_off = 0.0; /*< Consumption when the machine is turned off (shutdown) */
-  double total_energy = 0.0; /*< Total energy consumed by the host */
-  double last_updated;       /*< Timestamp of the last energy update event*/
-};
-
-}
-}
-
-#endif /* ENERGY_CALLBACK_HPP_ */
similarity index 79%
rename from src/surf/plugins/energy.cpp
rename to src/surf/plugins/host_energy.cpp
index c063cd3..7a3029a 100644 (file)
@@ -7,7 +7,6 @@
 #include "simgrid/simix.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "simgrid/simix.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
-#include "src/surf/plugins/energy.hpp"
 #include <utility>
 
 /** @addtogroup SURF_plugin_energy
 #include <utility>
 
 /** @addtogroup SURF_plugin_energy
@@ -16,7 +15,8 @@
 This is the energy plugin, enabling to account not only for computation time,
 but also for the dissipated energy in the simulated platform.
 
 This is the energy plugin, enabling to account not only for computation time,
 but also for the dissipated energy in the simulated platform.
 
-The energy consumption of a CPU depends directly of its current load. Specify that consumption in your platform file as follows:
+The energy consumption of a CPU depends directly of its current load. Specify that consumption in your platform file as
+follows:
 
 \verbatim
 <host id="HostA" power="100.0Mf" >
 
 \verbatim
 <host id="HostA" power="100.0Mf" >
@@ -54,17 +54,50 @@ and then use the following function to retrieve the consumption of a given host:
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF energy plugin");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF energy plugin");
 
-using simgrid::energy::HostEnergy;
-
 namespace simgrid {
 namespace energy {
 
 namespace simgrid {
 namespace energy {
 
+class XBT_PRIVATE HostEnergy;
+
+class PowerRange {
+public:
+  double idle;
+  double min;
+  double max;
+
+  PowerRange(double idle, double min, double max) : idle(idle), min(min), max(max) {}
+};
+
+class HostEnergy {
+public:
+  static simgrid::xbt::Extension<simgrid::s4u::Host, HostEnergy> EXTENSION_ID;
+
+  explicit HostEnergy(simgrid::s4u::Host* ptr);
+  ~HostEnergy();
+
+  double getCurrentWattsValue(double cpu_load);
+  double getConsumedEnergy();
+  double getWattMinAt(int pstate);
+  double getWattMaxAt(int pstate);
+  void update();
+
+private:
+  void initWattsRangeList();
+  simgrid::s4u::Host* host = nullptr;
+  std::vector<PowerRange>
+      power_range_watts_list; /*< List of (min_power,max_power) pairs corresponding to each cpu pstate */
+public:
+  double watts_off    = 0.0; /*< Consumption when the machine is turned off (shutdown) */
+  double total_energy = 0.0; /*< Total energy consumed by the host */
+  double last_updated;       /*< Timestamp of the last energy update event*/
+};
+
 simgrid::xbt::Extension<simgrid::s4u::Host, HostEnergy> HostEnergy::EXTENSION_ID;
 
 /* Computes the consumption so far.  Called lazily on need. */
 void HostEnergy::update()
 {
 simgrid::xbt::Extension<simgrid::s4u::Host, HostEnergy> HostEnergy::EXTENSION_ID;
 
 /* Computes the consumption so far.  Called lazily on need. */
 void HostEnergy::update()
 {
-  double start_time = this->last_updated;
+  double start_time  = this->last_updated;
   double finish_time = surf_get_clock();
   double cpu_load;
   if (host->pimpl_cpu->getPstateSpeedCurrent() <= 0)
   double finish_time = surf_get_clock();
   double cpu_load;
   if (host->pimpl_cpu->getPstateSpeedCurrent() <= 0)
@@ -96,7 +129,7 @@ void HostEnergy::update()
   else
     instantaneous_consumption = this->getCurrentWattsValue(cpu_load);
 
   else
     instantaneous_consumption = this->getCurrentWattsValue(cpu_load);
 
-  double energy_this_step = instantaneous_consumption*(finish_time-start_time);
+  double energy_this_step = instantaneous_consumption * (finish_time - start_time);
 
   this->total_energy = previous_energy + energy_this_step;
   this->last_updated = finish_time;
 
   this->total_energy = previous_energy + energy_this_step;
   this->last_updated = finish_time;
@@ -106,7 +139,7 @@ void HostEnergy::update()
       host->cname(), start_time, finish_time, host->pimpl_cpu->speed_.peak, previous_energy, energy_this_step);
 }
 
       host->cname(), start_time, finish_time, host->pimpl_cpu->speed_.peak, previous_energy, energy_this_step);
 }
 
-HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) : host(ptr), last_updated(surf_get_clock())
+HostEnergy::HostEnergy(simgrid::s4u::Hostptr) : host(ptr), last_updated(surf_get_clock())
 {
   initWattsRangeList();
 
 {
   initWattsRangeList();
 
@@ -119,7 +152,7 @@ HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) : host(ptr), last_updated(surf_g
   /* watts_off is 0 by default */
 }
 
   /* watts_off is 0 by default */
 }
 
-HostEnergy::~HostEnergy()=default;
+HostEnergy::~HostEnergy() = default;
 
 double HostEnergy::getWattMinAt(int pstate)
 {
 
 double HostEnergy::getWattMinAt(int pstate)
 {
@@ -161,7 +194,7 @@ double HostEnergy::getCurrentWattsValue(double cpu_load)
      * (maxCpuLoad is by definition 1)
      */
     double power_slope;
      * (maxCpuLoad is by definition 1)
      */
     double power_slope;
-    int coreCount = host->coreCount();
+    int coreCount         = host->coreCount();
     double coreReciprocal = static_cast<double>(1) / static_cast<double>(coreCount);
     if (coreCount > 1)
       power_slope = (max_power - min_power) / (1 - coreReciprocal);
     double coreReciprocal = static_cast<double>(1) / static_cast<double>(coreCount);
     if (coreCount > 1)
       power_slope = (max_power - min_power) / (1 - coreReciprocal);
@@ -169,8 +202,7 @@ double HostEnergy::getCurrentWattsValue(double cpu_load)
       power_slope = 0; // Should be 0, since max_power == min_power (in this case)
 
     current_power = min_power + (cpu_load - coreReciprocal) * power_slope;
       power_slope = 0; // Should be 0, since max_power == min_power (in this case)
 
     current_power = min_power + (cpu_load - coreReciprocal) * power_slope;
-  }
-  else { /* Our machine is idle, take the dedicated value! */
+  } else { /* Our machine is idle, take the dedicated value! */
     current_power = range.idle;
   }
 
     current_power = range.idle;
   }
 
@@ -195,9 +227,9 @@ void HostEnergy::initWattsRangeList()
     return;
 
   xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
     return;
 
   xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
-  int pstate_nb = xbt_dynar_length(all_power_values);
+  int pstate_nb                = xbt_dynar_length(all_power_values);
 
 
-  for (int i=0; i< pstate_nb; i++) {
+  for (int i = 0; i < pstate_nb; i++) {
     /* retrieve the power values associated with the current pstate */
     xbt_dynar_t current_power_values = xbt_str_split(xbt_dynar_get_as(all_power_values, i, char*), ":");
     xbt_assert(xbt_dynar_length(current_power_values) == 3,
     /* retrieve the power values associated with the current pstate */
     xbt_dynar_t current_power_values = xbt_str_split(xbt_dynar_get_as(all_power_values, i, char*), ":");
     xbt_assert(xbt_dynar_length(current_power_values) == 3,
@@ -209,11 +241,9 @@ void HostEnergy::initWattsRangeList()
     char* msg_idle = bprintf("Invalid idle value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_min  = bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_max  = bprintf("Invalid max value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_idle = bprintf("Invalid idle value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_min  = bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_max  = bprintf("Invalid max value for pstate %d on host %s: %%s", i, host->cname());
-    PowerRange range(
-      xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 0, char*), msg_idle),
-      xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 1, char*), msg_min),
-      xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 2, char*), msg_max)
-    );
+    PowerRange range(xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 0, char*), msg_idle),
+                     xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 1, char*), msg_min),
+                     xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 2, char*), msg_max));
     power_range_watts_list.push_back(range);
     xbt_free(msg_idle);
     xbt_free(msg_min);
     power_range_watts_list.push_back(range);
     xbt_free(msg_idle);
     xbt_free(msg_min);
@@ -223,18 +253,21 @@ void HostEnergy::initWattsRangeList()
   }
   xbt_dynar_free(&all_power_values);
 }
   }
   xbt_dynar_free(&all_power_values);
 }
-
 }
 }
 
 }
 }
 
+using simgrid::energy::HostEnergy;
+
 /* **************************** events  callback *************************** */
 /* **************************** events  callback *************************** */
-static void onCreation(simgrid::s4u::Host& host) {
+static void onCreation(simgrid::s4u::Host& host)
+{
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
   host.extension_set(new HostEnergy(&host));
 }
 
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
   host.extension_set(new HostEnergy(&host));
 }
 
-static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf::Action::State previous) {
+static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf::Action::State previous)
+{
   for (simgrid::surf::Cpu* cpu : action->cpus()) {
     simgrid::s4u::Host* host = cpu->getHost();
     if (host == nullptr)
   for (simgrid::surf::Cpu* cpu : action->cpus()) {
     simgrid::s4u::Host* host = cpu->getHost();
     if (host == nullptr)
@@ -253,21 +286,23 @@ static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf:
   }
 }
 
   }
 }
 
-static void onHostStateChange(simgrid::s4u::Host &host) {
+static void onHostStateChange(simgrid::s4u::Host& host)
+{
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
-  HostEnergy *host_energy = host.extension<HostEnergy>();
+  HostEnergyhost_energy = host.extension<HostEnergy>();
 
 
-  if(host_energy->last_updated < surf_get_clock())
+  if (host_energy->last_updated < surf_get_clock())
     host_energy->update();
 }
 
     host_energy->update();
 }
 
-static void onHostDestruction(simgrid::s4u::Host& host) {
+static void onHostDestruction(simgrid::s4u::Host& host)
+{
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
-  HostEnergy *host_energy = host.extension<HostEnergy>();
+  HostEnergyhost_energy = host.extension<HostEnergy>();
   host_energy->update();
   XBT_INFO("Total energy of host %s: %f Joules", host.cname(), host_energy->getConsumedEnergy());
 }
   host_energy->update();
   XBT_INFO("Total energy of host %s: %f Joules", host.cname(), host_energy->getConsumedEnergy());
 }
@@ -275,7 +310,8 @@ static void onHostDestruction(simgrid::s4u::Host& host) {
 /* **************************** Public interface *************************** */
 /** \ingroup SURF_plugin_energy
  * \brief Enable energy plugin
 /* **************************** Public interface *************************** */
 /** \ingroup SURF_plugin_energy
  * \brief Enable energy plugin
- * \details Enable energy plugin to get joules consumption of each cpu. You should call this function before #MSG_init().
+ * \details Enable energy plugin to get joules consumption of each cpu. You should call this function before
+ * #MSG_init().
  */
 void sg_host_energy_plugin_init()
 {
  */
 void sg_host_energy_plugin_init()
 {
@@ -294,21 +330,24 @@ void sg_host_energy_plugin_init()
  *
  *  See also @ref SURF_plugin_energy.
  */
  *
  *  See also @ref SURF_plugin_energy.
  */
-double sg_host_get_consumed_energy(sg_host_t host) {
+double sg_host_get_consumed_energy(sg_host_t host)
+{
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
-    "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+             "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
   return host->extension<HostEnergy>()->getConsumedEnergy();
 }
 
 /** @brief Get the amount of watt dissipated at the given pstate when the host is idling */
   return host->extension<HostEnergy>()->getConsumedEnergy();
 }
 
 /** @brief Get the amount of watt dissipated at the given pstate when the host is idling */
-double sg_host_get_wattmin_at(sg_host_t host, int pstate) {
+double sg_host_get_wattmin_at(sg_host_t host, int pstate)
+{
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
-    "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+             "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
   return host->extension<HostEnergy>()->getWattMinAt(pstate);
 }
 /** @brief  Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100% */
   return host->extension<HostEnergy>()->getWattMinAt(pstate);
 }
 /** @brief  Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100% */
-double sg_host_get_wattmax_at(sg_host_t host, int pstate) {
+double sg_host_get_wattmax_at(sg_host_t host, int pstate)
+{
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
-    "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+             "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
   return host->extension<HostEnergy>()->getWattMaxAt(pstate);
 }
   return host->extension<HostEnergy>()->getWattMaxAt(pstate);
 }
index e90c9ef..c9e4e98 100644 (file)
@@ -56,7 +56,6 @@ set(EXTRA_DIST
   src/surf/network_ib.hpp
   src/surf/ns3/ns3_interface.h
   src/surf/ns3/ns3_simulator.h
   src/surf/network_ib.hpp
   src/surf/ns3/ns3_interface.h
   src/surf/ns3/ns3_simulator.h
-  src/surf/plugins/energy.hpp
   src/surf/xml/simgrid.dtd
   src/surf/xml/simgrid_dtd.h
   src/surf/xml/simgrid_dtd.c
   src/surf/xml/simgrid.dtd
   src/surf/xml/simgrid_dtd.h
   src/surf/xml/simgrid_dtd.c
@@ -319,7 +318,7 @@ set(SURF_SRC
   src/surf/network_cm02.cpp
   src/surf/network_constant.cpp
   src/surf/network_interface.cpp
   src/surf/network_cm02.cpp
   src/surf/network_constant.cpp
   src/surf/network_interface.cpp
-  src/surf/plugins/energy.cpp
+  src/surf/plugins/host_energy.cpp
   src/surf/PropertyHolder.cpp
   src/surf/sg_platf.cpp
   src/surf/storage_interface.cpp
   src/surf/PropertyHolder.cpp
   src/surf/sg_platf.cpp
   src/surf/storage_interface.cpp