Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce differences between host and link energy plugin
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 28 Nov 2017 00:28:09 +0000 (01:28 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 28 Nov 2017 00:28:09 +0000 (01:28 +0100)
examples/s4u/energy-link/s4u-energy-link.tesh
src/surf/plugins/host_energy.cpp
src/surf/plugins/link_energy.cpp

index 2622a4b..2be5e34 100644 (file)
@@ -10,8 +10,8 @@ $ ${bindir:=.}/s4u-energy-link$EXEEXT ${srcdir:=.}/../platforms/energy_platform.
 > [  0.000000] (2:receiver@MyHost2) Receiving 1 flows ...
 > [ 10.250000] (2:receiver@MyHost2) receiver done.
 > [ 10.250000] (1:sender@MyHost1) sender done.
-> [ 10.250000] (0:maestro@) Link 'bus' total consumption: 10.750000
 > [ 10.250000] (0:maestro@) Total energy over all links: 10.750000
+> [ 10.250000] (0:maestro@) Energy consumption of link 'bus': 10.750000 Joules
 
 p And now test with 500000 bytes
 
@@ -23,6 +23,5 @@ $ ${bindir:=.}/s4u-energy-link$EXEEXT ${srcdir:=.}/../platforms/energy_platform.
 > [  0.000000] (2:receiver@MyHost2) Receiving 1 flows ...
 > [510.000000] (2:receiver@MyHost2) receiver done.
 > [510.000000] (1:sender@MyHost1) sender done.
-> [510.000000] (0:maestro@) Link 'bus' total consumption: 1510.000000
 > [510.000000] (0:maestro@) Total energy over all links: 1510.000000
-
+> [510.000000] (0:maestro@) Energy consumption of link 'bus': 1510.000000 Joules
index 21853c6..fbd887a 100644 (file)
@@ -413,9 +413,8 @@ static void onHostDestruction(simgrid::s4u::Host& host)
   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
     return;
 
-  HostEnergy* host_energy = host.extension<HostEnergy>();
-  host_energy->update();
-  XBT_INFO("Energy consumption of host %s: %f Joules", host.getCname(), host_energy->getConsumedEnergy());
+  XBT_INFO("Energy consumption of host %s: %f Joules", host.getCname(),
+           host.extension<HostEnergy>()->getConsumedEnergy());
 }
 
 static void onSimulationEnd()
index f3b3055..499fe6c 100644 (file)
@@ -52,7 +52,7 @@ public:
   ~LinkEnergy();
 
   void initWattsRangeList();
-  double getTotalEnergy();
+  double getConsumedEnergy();
   void update();
 
 private:
@@ -135,9 +135,10 @@ double LinkEnergy::getPower()
   return idle_ + dynamic_power;
 }
 
-double LinkEnergy::getTotalEnergy()
+double LinkEnergy::getConsumedEnergy()
 {
-  update();
+  if (lastUpdated_ < surf_get_clock()) // We need to simcall this as it modifies the environment
+    simgrid::simix::kernelImmediate(std::bind(&LinkEnergy::update, this));
   return this->totalEnergy_;
 }
 }
@@ -168,9 +169,7 @@ static void onSimulationEnd()
 
   double total_energy = 0.0; // Total dissipated energy (whole platform)
   for (const auto link : links) {
-    double link_energy = link->extension<LinkEnergy>()->getTotalEnergy();
-    if (strcmp(link->getCname(), "__loopback__"))
-      XBT_INFO("Link '%s' total consumption: %f", link->getCname(), link_energy);
+    double link_energy = link->extension<LinkEnergy>()->getConsumedEnergy();
     total_energy += link_energy;
   }
 
@@ -199,7 +198,9 @@ void sg_link_energy_plugin_init()
   });
 
   simgrid::s4u::Link::onDestruction.connect([](simgrid::s4u::Link& link) {
-    link.extension<LinkEnergy>()->update();
+    if (strcmp(link.getCname(), "__loopback__"))
+      XBT_INFO("Energy consumption of link '%s': %f Joules", link.getCname(),
+               link.extension<LinkEnergy>()->getConsumedEnergy());
   });
 
   simgrid::s4u::Link::onCommunicationStateChange.connect([](simgrid::surf::NetworkAction* action) {
@@ -213,4 +214,15 @@ void sg_link_energy_plugin_init()
   simgrid::s4u::onSimulationEnd.connect(&onSimulationEnd);
 }
 
+/** @ingroup plugin_energy
+ *  @brief Returns the total energy consumed by the link so far (in Joules)
+ *
+ *  Please note that since the consumption is lazily updated, it may require a simcall to update it.
+ *  The result is that the actor requesting this value will be interrupted,
+ *  the value will be updated in kernel mode before returning the control to the requesting actor.
+ */
+double sg_link_get_consumed_energy(sg_link_t link)
+{
+  return link->extension<LinkEnergy>()->getConsumedEnergy();
+}
 SG_END_DECL()