Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Give the _this_ variants to the Link signals
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 23 May 2023 19:50:15 +0000 (21:50 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 23 May 2023 22:27:09 +0000 (00:27 +0200)
docs/source/Plugins.rst
docs/source/app_s4u.rst
include/simgrid/s4u/Link.hpp
src/kernel/resource/StandardLinkImpl.cpp
src/plugins/host_energy.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp

index 073c904..865e1c2 100644 (file)
@@ -107,12 +107,16 @@ Partial list of existing signals in s4u:
   :cpp:func:`Host::on_this_state_change <simgrid::s4u::Host::on_this_state_change_cb>`
   :cpp:func:`Host::on_speed_change <simgrid::s4u::Host::on_speed_change_cb>`
   :cpp:func:`Host::on_this_speed_change <simgrid::s4u::Host::on_this_speed_change_cb>`
+  :cpp:func:`Host::on_exec_state_change <simgrid::s4u::Host::on_exec_state_change_cb>`
 - :cpp:func:`Io::on_start <simgrid::s4u::Io::on_start_cb>`
   :cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
 - :cpp:func:`Link::on_creation <simgrid::s4u::Link::on_creation_cb>`
   :cpp:func:`Link::on_destruction <simgrid::s4u::Link::on_destruction_cb>`
+  :cpp:func:`Link::on_this_destruction <simgrid::s4u::Link::on_this_destruction_cb>`
   :cpp:func:`Link::on_state_change <simgrid::s4u::Link::on_state_change_cb>`
-  :cpp:func:`Link::on_speed_change <simgrid::s4u::Link::on_bandwidth_change_cb>`
+  :cpp:func:`Link::on_this_state_change <simgrid::s4u::Link::on_this_state_change_cb>`
+  :cpp:func:`Link::on_bandwidth_change <simgrid::s4u::Link::on_bandwidth_change_cb>`
+  :cpp:func:`Link::on_this_bandwidth_change <simgrid::s4u::Link::on_this_bandwidth_change_cb>`
   :cpp:func:`Link::on_communication_state_change <simgrid::s4u::Link::on_communication_state_change_cb>`
 - :cpp:func:`NetZone::on_creation <simgrid::s4u::NetZone::on_creation_cb>`
   :cpp:func:`NetZone::on_seal <simgrid::s4u::NetZone::on_seal_cb>`
index 05ed9cd..8a3bf67 100644 (file)
@@ -1712,10 +1712,13 @@ Signals
    .. group-tab:: C++
 
       .. doxygenfunction:: simgrid::s4u::Link::on_bandwidth_change_cb
+      .. doxygenfunction:: simgrid::s4u::Link::on_this_bandwidth_change_cb
       .. doxygenfunction:: simgrid::s4u::Link::on_communication_state_change_cb
       .. doxygenfunction:: simgrid::s4u::Link::on_creation_cb
       .. doxygenfunction:: simgrid::s4u::Link::on_destruction_cb
+      .. doxygenfunction:: simgrid::s4u::Link::on_this_destruction_cb
       .. doxygenfunction:: simgrid::s4u::Link::on_state_change_cb
+      .. doxygenfunction:: simgrid::s4u::Link::on_this_state_change_cb
 
 .. _API_s4u_NetZone:
 
index ca87ddc..1ddca13 100644 (file)
@@ -158,28 +158,46 @@ private:
 #ifndef DOXYGEN
   static xbt::signal<void(Link&)> on_creation;
   static xbt::signal<void(Link const&)> on_state_change;
+  xbt::signal<void(Link const&)> on_this_state_change;
   static xbt::signal<void(Link const&)> on_bandwidth_change;
+  xbt::signal<void(Link const&)> on_this_bandwidth_change;
   static xbt::signal<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>
       on_communication_state_change;
   static xbt::signal<void(Link const&)> on_destruction;
+  xbt::signal<void(Link const&)> on_this_destruction;
 #endif
 
 public:
   /* The signals */
   /** @brief Add a callback fired when a new Link is created */
   static void on_creation_cb(const std::function<void(Link&)>& cb) { on_creation.connect(cb); }
-  /** @brief Add a callback fired when the state of a Link changes (when it is turned on or off) */
+  /** @brief Add a callback fired when the state of any Link changes (when it is turned on or off) */
   static void on_state_change_cb(const std::function<void(Link const&)>& cb) { on_state_change.connect(cb); }
-  /** @brief Add a callback fired when the bandwidth of a Link changes */
+  /** @brief Add a callback fired when the state of this specific Link changes (when it is turned on or off) */
+  void on_this_state_change_cb(const std::function<void(Link const&)>& cb)
+  {
+    on_this_state_change.connect(cb);
+  }
+  /** @brief Add a callback fired when the bandwidth of any Link changes */
   static void on_bandwidth_change_cb(const std::function<void(Link const&)>& cb) { on_bandwidth_change.connect(cb); }
+  /** @brief Add a callback fired when the bandwidth of this specific Link changes */
+  void on_this_bandwidth_change_cb(const std::function<void(Link const&)>& cb)
+  {
+    on_this_bandwidth_change.connect(cb);
+  }
   /** @brief Add a callback fired when a communication changes it state (ready/done/cancel) */
   static void on_communication_state_change_cb(
       const std::function<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>& cb)
   {
     on_communication_state_change.connect(cb);
   }
-  /** @brief Add a callback fired when a Link is destroyed */
+  /** @brief Add a callback fired when any Link is destroyed */
   static void on_destruction_cb(const std::function<void(Link const&)>& cb) { on_destruction.connect(cb); }
+  /** @brief Add a callback fired when this specific Link is destroyed */
+  void on_this_destruction_cb(const std::function<void(Link const&)>& cb)
+  {
+    on_this_destruction.connect(cb);
+  }
 };
 
 /**
index 59a07d1..2d9f437 100644 (file)
@@ -37,6 +37,7 @@ void StandardLinkImpl::Deleter::operator()(resource::StandardLinkImpl* link) con
 void StandardLinkImpl::destroy()
 {
   s4u::Link::on_destruction(piface_);
+  piface_.on_this_destruction(piface_);
   delete this;
 }
 
@@ -115,6 +116,7 @@ void StandardLinkImpl::seal()
 void StandardLinkImpl::on_bandwidth_change() const
 {
   s4u::Link::on_bandwidth_change(piface_);
+  piface_.on_this_bandwidth_change(piface_);
 }
 
 void StandardLinkImpl::set_bandwidth_profile(profile::Profile* profile)
index 5f6a0e4..fb2b119 100644 (file)
@@ -505,7 +505,7 @@ void sg_host_energy_plugin_init()
   simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end);
   // We may only have one actor on a node. If that actor executes something like
   //   compute -> recv -> compute
-  // the recv operation will not trigger a "CpuAction::on_state_change". This means
+  // the recv operation will not trigger a "Host::on_exec_state_change_cb". This means
   // that the next trigger would be the 2nd compute, hence ignoring the idle time
   // during the recv call. By updating at the beginning of a compute, we can
   // fix that. (If the cpu is not idle, this is not required.)
index 1e301fe..496b1f9 100644 (file)
@@ -103,6 +103,7 @@ void Host::turn_on()
       this->pimpl_cpu_->turn_on();
       this->pimpl_->turn_on();
       on_state_change(*this);
+      on_this_state_change(*this);
     });
   }
 }
@@ -117,6 +118,7 @@ void Host::turn_off()
       this->pimpl_->turn_off(self);
 
       on_state_change(*this);
+      on_this_state_change(*this);
     });
   }
 }
index 4280066..d64a457 100644 (file)
@@ -137,11 +137,19 @@ double Link::get_load() const
 
 void Link::turn_on()
 {
-  kernel::actor::simcall_answered([this]() { this->pimpl_->turn_on(); });
+  kernel::actor::simcall_answered([this]() {
+    this->pimpl_->turn_on();
+    on_state_change(*this);
+    on_this_state_change(*this);
+  });
 }
 void Link::turn_off()
 {
-  kernel::actor::simcall_answered([this]() { this->pimpl_->turn_off(); });
+  kernel::actor::simcall_answered([this]() {
+    this->pimpl_->turn_off();
+    on_state_change(*this);
+    on_this_state_change(*this);
+  });
 }
 Link* Link::seal()
 {