Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize common code to cancel actions when a resource is turned off.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 8 Jun 2023 20:35:40 +0000 (22:35 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 8 Jun 2023 20:39:25 +0000 (22:39 +0200)
src/deprecated.cpp
src/kernel/EngineImpl.hpp
src/kernel/resource/CpuImpl.cpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/Resource.hpp
src/kernel/resource/StandardLinkImpl.cpp
src/kernel/resource/models/cpu_cas01.cpp
src/kernel/resource/models/cpu_ti.cpp
src/kernel/xml/sg_platf.cpp

index 79b6a89..0881f54 100644 (file)
@@ -16,6 +16,8 @@
 #define SIMIX_H_NO_DEPRECATED_WARNING // avoid deprecation warning on include (remove with XBT_ATTRIB_DEPRECATED_v335)
 #include <simgrid/simix.h>
 
+#include <cmath>
+
 void simcall_comm_send(simgrid::kernel::actor::ActorImpl* sender, simgrid::kernel::activity::MailboxImpl* mbox,
                        double task_size, double rate, void* src_buff, size_t src_buff_size,
                        bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
index 33a12dd..4c25e54 100644 (file)
@@ -19,7 +19,6 @@
 #include "src/kernel/activity/SleepImpl.hpp"
 #include "src/kernel/activity/Synchro.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/kernel/resource/SplitDuplexLinkImpl.hpp"
 
 #include <boost/intrusive/list.hpp>
 #include <map>
index 313b3fc..acd7aa4 100644 (file)
@@ -4,7 +4,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/resource/CpuImpl.hpp"
-#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/models/cpu_ti.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/simgrid/math_utils.h"
@@ -157,16 +156,7 @@ void CpuImpl::turn_off()
 {
   if (is_on()) {
     Resource::turn_off();
-
-    const kernel::lmm::Element* elem = nullptr;
-    double now                       = EngineImpl::get_clock();
-    while (const auto* var = get_constraint()->get_variable(&elem)) {
-      Action* action = var->get_id();
-      if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) {
-        action->set_finish_time(now);
-        action->set_state(Action::State::FAILED);
-      }
-    }
+    cancel_actions();
   }
 }
 
index a231432..20c23ac 100644 (file)
@@ -71,16 +71,7 @@ void DiskImpl::turn_off()
     Resource::turn_off();
     s4u::Disk::on_onoff(piface_);
     piface_.on_this_onoff(piface_);
-
-    const kernel::lmm::Element* elem = nullptr;
-    double now                       = EngineImpl::get_clock();
-    while (const auto* var = get_constraint()->get_variable(&elem)) {
-      Action* action = var->get_id();
-      if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) {
-        action->set_finish_time(now);
-        action->set_state(Action::State::FAILED);
-      }
-    }
+    cancel_actions();
   }
 }
 
index 9e2f284..1ed1e35 100644 (file)
@@ -7,6 +7,7 @@
 #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
 
 #include "simgrid/forward.h"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/actor/Simcall.hpp"
 #include "src/kernel/lmm/maxmin.hpp" // Constraint
 #include "src/kernel/resource/profile/Event.hpp"
@@ -72,6 +73,21 @@ template <class AnyResource> class Resource_T : public Resource {
   Model* model_                = nullptr;
   lmm::Constraint* constraint_ = nullptr;
 
+protected:
+  void cancel_actions()
+  {
+    const kernel::lmm::Element* elem = nullptr;
+    double now                       = EngineImpl::get_clock();
+    while (const auto* var = get_constraint()->get_variable(&elem)) {
+      Action* action = var->get_id();
+      if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED ||
+          action->get_state() == Action::State::IGNORED) {
+        action->set_finish_time(now);
+        action->set_state(Action::State::FAILED);
+      }
+    }
+  }
+
 public:
   using Resource::Resource;
   /** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */
index a7661a1..9df40d0 100644 (file)
@@ -5,7 +5,6 @@
 
 #include <simgrid/s4u/Engine.hpp>
 
-#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/StandardLinkImpl.hpp"
 #include <numeric>
 
@@ -93,16 +92,7 @@ void StandardLinkImpl::turn_off()
     Resource::turn_off();
     s4u::Link::on_onoff(piface_);
     piface_.on_this_onoff(piface_);
-
-    const kernel::lmm::Element* elem = nullptr;
-    double now                       = EngineImpl::get_clock();
-    while (const auto* var = get_constraint()->get_variable(&elem)) {
-      Action* action = var->get_id();
-      if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) {
-        action->set_finish_time(now);
-        action->set_state(Action::State::FAILED);
-      }
-    }
+    cancel_actions();
   }
 }
 
index c938624..35af6fa 100644 (file)
@@ -113,20 +113,8 @@ void CpuCas01::apply_event(profile::Event* event, double value)
         get_iface()->turn_on();
       }
     } else {
-      const lmm::Element* elem = nullptr;
-      double date              = EngineImpl::get_clock();
-
       get_iface()->turn_off();
-
-      while (const auto* var = get_constraint()->get_variable(&elem)) {
-        Action* action = var->get_id();
-
-        if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED ||
-            action->get_state() == Action::State::IGNORED) {
-          action->set_finish_time(date);
-          action->set_state(Action::State::FAILED);
-        }
-      }
+      cancel_actions();
     }
     unref_state_event();
 
index c927bec..6b522bb 100644 (file)
@@ -387,13 +387,13 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value)
       }
     } else {
       get_iface()->turn_off();
-      double date = EngineImpl::get_clock();
 
       /* put all action running on cpu to failed */
+      double now = EngineImpl::get_clock();
       for (CpuTiAction& action : action_set_) {
         if (action.get_state() == Action::State::INITED || action.get_state() == Action::State::STARTED ||
             action.get_state() == Action::State::IGNORED) {
-          action.set_finish_time(date);
+          action.set_finish_time(now);
           action.set_state(Action::State::FAILED);
           get_model()->get_action_heap().remove(&action);
         }
index 0d64feb..b4b4a32 100644 (file)
@@ -23,6 +23,7 @@
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
 #include "src/kernel/resource/HostImpl.hpp"
+#include "src/kernel/resource/StandardLinkImpl.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/kernel/xml/platf.hpp"
 #include "src/kernel/xml/platf_private.hpp"