Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Pass the remote app as a parameter to all exploration signals
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 4 Aug 2022 19:10:48 +0000 (21:10 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 4 Aug 2022 19:10:54 +0000 (21:10 +0200)
When we'll have reforks in the future, the remote app may change
during the exploration, so we don't want to seal the current remote
app in the callback closure. We want to use the fresh one instead.

src/mc/explo/CommunicationDeterminismChecker.cpp
src/mc/explo/DFSExplorer.cpp
src/mc/explo/DFSExplorer.hpp

index 109a220..082b0eb 100644 (file)
@@ -329,18 +329,20 @@ Exploration* create_communication_determinism_checker(RemoteApp& remote_app)
   auto base      = new DFSExplorer(remote_app);
   auto extension = new CommDetExtension(*base);
 
-  DFSExplorer::on_exploration_start([extension]() {
+  DFSExplorer::on_exploration_start([extension](RemoteApp&) {
     XBT_INFO("Check communication determinism");
     extension->exploration_start();
   });
-  DFSExplorer::on_backtracking([extension]() { extension->initial_communications_pattern_done = true; });
-  DFSExplorer::on_state_creation(
-      [extension, &remote_app](State* state) { state->extension_set(new StateCommDet(*extension, remote_app)); });
+  DFSExplorer::on_backtracking([extension](RemoteApp&) { extension->initial_communications_pattern_done = true; });
+  DFSExplorer::on_state_creation([extension](State* state, RemoteApp& remote_app) {
+    state->extension_set(new StateCommDet(*extension, remote_app));
+  });
 
-  DFSExplorer::on_restore_system_state(
-      [extension, &remote_app](State* state) { extension->restore_communications_pattern(state, remote_app); });
+  DFSExplorer::on_restore_system_state([extension](State* state, RemoteApp& remote_app) {
+    extension->restore_communications_pattern(state, remote_app);
+  });
 
-  DFSExplorer::on_restore_initial_state([extension, &remote_app]() {
+  DFSExplorer::on_restore_initial_state([extension](RemoteApp& remote_app) {
     const unsigned long maxpid = remote_app.get_maxpid();
     assert(maxpid == extension->incomplete_communications_pattern.size());
     assert(maxpid == extension->initial_communications_pattern.size());
@@ -350,10 +352,10 @@ Exploration* create_communication_determinism_checker(RemoteApp& remote_app)
     }
   });
 
-  DFSExplorer::on_transition_replay([extension](Transition* t) { extension->handle_comm_pattern(t); });
-  DFSExplorer::on_transition_execute([extension](Transition* t) { extension->handle_comm_pattern(t); });
+  DFSExplorer::on_transition_replay([extension](Transition* t, RemoteApp&) { extension->handle_comm_pattern(t); });
+  DFSExplorer::on_transition_execute([extension](Transition* t, RemoteApp&) { extension->handle_comm_pattern(t); });
 
-  DFSExplorer::on_log_state([extension]() {
+  DFSExplorer::on_log_state([extension](RemoteApp&) {
     if (_sg_mc_comms_determinism) {
       if (extension->send_deterministic && not extension->recv_deterministic) {
         XBT_INFO("*******************************************************");
index a60383e..edd9eee 100644 (file)
@@ -26,17 +26,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dfs, mc, "DFS exploration algorithm of the mo
 
 namespace simgrid::mc {
 
-xbt::signal<void()> DFSExplorer::on_exploration_start_signal;
-xbt::signal<void()> DFSExplorer::on_backtracking_signal;
+xbt::signal<void(RemoteApp&)> DFSExplorer::on_exploration_start_signal;
+xbt::signal<void(RemoteApp&)> DFSExplorer::on_backtracking_signal;
 
-xbt::signal<void(State*)> DFSExplorer::on_state_creation_signal;
+xbt::signal<void(State*, RemoteApp&)> DFSExplorer::on_state_creation_signal;
 
-xbt::signal<void(State*)> DFSExplorer::on_restore_system_state_signal;
-xbt::signal<void()> DFSExplorer::on_restore_initial_state_signal;
-xbt::signal<void(Transition*)> DFSExplorer::on_transition_replay_signal;
-xbt::signal<void(Transition*)> DFSExplorer::on_transition_execute_signal;
+xbt::signal<void(State*, RemoteApp&)> DFSExplorer::on_restore_system_state_signal;
+xbt::signal<void(RemoteApp&)> DFSExplorer::on_restore_initial_state_signal;
+xbt::signal<void(Transition*, RemoteApp&)> DFSExplorer::on_transition_replay_signal;
+xbt::signal<void(Transition*, RemoteApp&)> DFSExplorer::on_transition_execute_signal;
 
-xbt::signal<void()> DFSExplorer::on_log_state_signal;
+xbt::signal<void(RemoteApp&)> DFSExplorer::on_log_state_signal;
 
 void DFSExplorer::check_non_termination(const State* current_state)
 {
@@ -76,7 +76,7 @@ std::vector<std::string> DFSExplorer::get_textual_trace() // override
 
 void DFSExplorer::log_state() // override
 {
-  on_log_state_signal();
+  on_log_state_signal(get_remote_app());
   XBT_INFO("DFS exploration ended. %ld unique states visited; %ld backtracks (%lu transition replays, %lu states "
            "visited overall)",
            State::get_expanded_states(), backtrack_count_, mc_model_checker->get_visited_states(),
@@ -85,7 +85,7 @@ void DFSExplorer::log_state() // override
 
 void DFSExplorer::run()
 {
-  on_exploration_start_signal();
+  on_exploration_start_signal(get_remote_app());
   /* This function runs the DFS algorithm the state space.
    * We do so iteratively instead of recursively, dealing with the call stack manually.
    * This allows one to explore the call stack at will. */
@@ -140,7 +140,7 @@ void DFSExplorer::run()
 
     /* Actually answer the request: let's execute the selected request (MCed does one step) */
     state->execute_next(next);
-    on_transition_execute_signal(state->get_transition());
+    on_transition_execute_signal(state->get_transition(), get_remote_app());
 
     // If there are processes to interleave and the maximum depth has not been
     // reached then perform one step of the exploration algorithm.
@@ -149,7 +149,7 @@ void DFSExplorer::run()
 
     /* Create the new expanded state (copy the state of MCed into our MCer data) */
     auto next_state = std::make_unique<State>(get_remote_app());
-    on_state_creation_signal(next_state.get());
+    on_state_creation_signal(next_state.get(), get_remote_app());
 
     if (_sg_mc_termination)
       this->check_non_termination(next_state.get());
@@ -188,7 +188,7 @@ void DFSExplorer::backtrack()
 {
   backtrack_count_++;
   XBT_VERB("Backtracking from %s", get_record_trace().to_string().c_str());
-  on_backtracking_signal();
+  on_backtracking_signal(get_remote_app());
   stack_.pop_back();
 
   get_remote_app().check_deadlock();
@@ -247,20 +247,20 @@ void DFSExplorer::restore_state()
   State* last_state = stack_.back().get();
   if (const auto* system_state = last_state->get_system_state()) {
     Api::get().restore_state(system_state);
-    on_restore_system_state_signal(last_state);
+    on_restore_system_state_signal(last_state, get_remote_app());
     return;
   }
 
   /* if no snapshot, we need to restore the initial state and replay the transitions */
   get_remote_app().restore_initial_state();
-  on_restore_initial_state_signal();
+  on_restore_initial_state_signal(get_remote_app());
 
   /* Traverse the stack from the state at position start and re-execute the transitions */
   for (std::unique_ptr<State> const& state : stack_) {
     if (state == stack_.back()) /* If we are arrived on the target state, don't replay the outgoing transition */
       break;
     state->get_transition()->replay();
-    on_transition_replay_signal(state->get_transition());
+    on_transition_replay_signal(state->get_transition(), get_remote_app());
     /* Update statistics */
     mc_model_checker->inc_visited_states();
   }
index 0eaac54..161781b 100644 (file)
@@ -21,17 +21,17 @@ class XBT_PRIVATE DFSExplorer : public Exploration {
   ReductionMode reductionMode_ = ReductionMode::unset;
   long backtrack_count_        = 0;
 
-  static xbt::signal<void()> on_exploration_start_signal;
-  static xbt::signal<void()> on_backtracking_signal;
+  static xbt::signal<void(RemoteApp&)> on_exploration_start_signal;
+  static xbt::signal<void(RemoteApp&)> on_backtracking_signal;
 
-  static xbt::signal<void(State*)> on_state_creation_signal;
+  static xbt::signal<void(State*, RemoteApp&)> on_state_creation_signal;
 
-  static xbt::signal<void(State*)> on_restore_system_state_signal;
-  static xbt::signal<void()> on_restore_initial_state_signal;
-  static xbt::signal<void(Transition*)> on_transition_replay_signal;
-  static xbt::signal<void(Transition*)> on_transition_execute_signal;
+  static xbt::signal<void(State*, RemoteApp&)> on_restore_system_state_signal;
+  static xbt::signal<void(RemoteApp&)> on_restore_initial_state_signal;
+  static xbt::signal<void(Transition*, RemoteApp&)> on_transition_replay_signal;
+  static xbt::signal<void(Transition*, RemoteApp&)> on_transition_execute_signal;
 
-  static xbt::signal<void()> on_log_state_signal;
+  static xbt::signal<void(RemoteApp&)> on_log_state_signal;
 
 public:
   explicit DFSExplorer(RemoteApp& remote_app);
@@ -41,31 +41,43 @@ public:
   void log_state() override;
 
   /** Called once when the exploration starts */
-  static void on_exploration_start(std::function<void()> const& f) { on_exploration_start_signal.connect(f); }
+  static void on_exploration_start(std::function<void(RemoteApp& remote_app)> const& f)
+  {
+    on_exploration_start_signal.connect(f);
+  }
   /** Called each time that the exploration backtracks from a exploration end */
-  static void on_backtracking(std::function<void()> const& f) { on_backtracking_signal.connect(f); }
+  static void on_backtracking(std::function<void(RemoteApp& remote_app)> const& f)
+  {
+    on_backtracking_signal.connect(f);
+  }
   /** Called each time that a new state is create */
-  static void on_state_creation(std::function<void(State*)> const& f) { on_state_creation_signal.connect(f); }
+  static void on_state_creation(std::function<void(State*, RemoteApp& remote_app)> const& f)
+  {
+    on_state_creation_signal.connect(f);
+  }
   /** Called when rollbacking directly onto a previously checkpointed state */
-  static void on_restore_system_state(std::function<void(State*)> const& f)
+  static void on_restore_system_state(std::function<void(State*, RemoteApp& remote_app)> const& f)
   {
     on_restore_system_state_signal.connect(f);
   }
   /** Called when the state to which we backtrack was not checkpointed state, forcing us to restore the initial state
    * before replaying some transitions */
-  static void on_restore_initial_state(std::function<void()> const& f) { on_restore_initial_state_signal.connect(f); }
+  static void on_restore_initial_state(std::function<void(RemoteApp& remote_app)> const& f)
+  {
+    on_restore_initial_state_signal.connect(f);
+  }
   /** Called when replaying a transition that was previously executed, to reach a backtracked state */
-  static void on_transition_replay(std::function<void(Transition*)> const& f)
+  static void on_transition_replay(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
   {
     on_transition_replay_signal.connect(f);
   }
   /** Called when executing a new transition */
-  static void on_transition_execute(std::function<void(Transition*)> const& f)
+  static void on_transition_execute(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
   {
     on_transition_execute_signal.connect(f);
   }
   /** Called when displaying the statistics at the end of the exploration */
-  static void on_log_state(std::function<void()> const& f) { on_log_state_signal.connect(f); }
+  static void on_log_state(std::function<void(RemoteApp&)> const& f) { on_log_state_signal.connect(f); }
 
 private:
   void check_non_termination(const State* current_state);