Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / mc / checker / SafetyChecker.cpp
index f74ab5f..4198071 100644 (file)
@@ -21,7 +21,6 @@
 #include "src/mc/mc_private.hpp"
 #include "src/mc/mc_record.hpp"
 #include "src/mc/mc_request.hpp"
-#include "src/mc/mc_smx.hpp"
 
 #include "src/xbt/mmalloc/mmprivate.h"
 
@@ -62,11 +61,8 @@ RecordTrace SafetyChecker::get_record_trace() // override
 std::vector<std::string> SafetyChecker::get_textual_trace() // override
 {
   std::vector<std::string> trace;
-  for (auto const& state : stack_) {
-    int value         = state->transition_.argument_;
-    smx_simcall_t req = &state->executed_req_;
-    trace.push_back(api::get().request_to_string(req, value, RequestType::executed));
-  }
+  for (auto const& state : stack_)
+    trace.push_back(state->transition_.textual);
   return trace;
 }
 
@@ -89,7 +85,7 @@ void SafetyChecker::run()
 
     XBT_DEBUG("**************************************************");
     XBT_VERB("Exploration depth=%zu (state=%p, num %d)(%zu interleave)", stack_.size(), state, state->num_,
-             state->interleave_size());
+             state->count_todo());
 
     api::get().mc_inc_visited_states();
 
@@ -124,16 +120,16 @@ void SafetyChecker::run()
 
     // If there are processes to interleave and the maximum depth has not been
     // reached then perform one step of the exploration algorithm.
-    XBT_DEBUG("Execute: %s", api::get().request_to_string(req, state->transition_.argument_, RequestType::simix).c_str());
+    XBT_DEBUG("Execute: %s", api::get().request_to_string(req, state->transition_.times_considered_).c_str());
 
     std::string req_str;
     if (dot_output != nullptr)
-      req_str = api::get().request_get_dot_output(req, state->transition_.argument_);
+      req_str = api::get().request_get_dot_output(req, state->transition_.times_considered_);
 
     api::get().mc_inc_executed_trans();
 
     /* Actually answer the request: let execute the selected request (MCed does one step) */
-    api::get().execute(state->transition_);
+    api::get().execute(state->transition_, &state->executed_req_);
 
     /* Create the new expanded state (copy the state of MCed into our MCer data) */
     ++expanded_states_count_;
@@ -153,7 +149,7 @@ void SafetyChecker::run()
       for (auto& remoteActor : actors) {
         auto actor = remoteActor.copy.get_buffer();
         if (api::get().actor_is_enabled(actor->get_pid())) {
-          next_state->add_interleaving_set(actor);
+          next_state->mark_todo(actor);
           if (reductionMode_ == ReductionMode::dpor)
             break; // With DPOR, we take the first enabled transition
         }
@@ -178,11 +174,7 @@ void SafetyChecker::backtrack()
 {
   stack_.pop_back();
 
-  /* Check for deadlocks */
-  if (api::get().mc_check_deadlock()) {
-    api::get().mc_show_deadlock();
-    throw DeadlockError();
-  }
+  api::get().mc_check_deadlock();
 
   /* Traverse the stack backwards until a state with a non empty interleave set is found, deleting all the states that
    *  have it empty in the way. For each deleted state, check if the request that has generated it (from its
@@ -193,45 +185,43 @@ void SafetyChecker::backtrack()
     std::unique_ptr<State> state = std::move(stack_.back());
     stack_.pop_back();
     if (reductionMode_ == ReductionMode::dpor) {
-      smx_simcall_t req = &state->internal_req_;
-      if (req->call_ == simix::Simcall::MUTEX_LOCK || req->call_ == simix::Simcall::MUTEX_TRYLOCK)
+      auto call = state->executed_req_.call_;
+      const kernel::actor::ActorImpl* issuer = api::get().simcall_get_issuer(&state->executed_req_);
+      if (call == simix::Simcall::MUTEX_LOCK)
         xbt_die("Mutex is currently not supported with DPOR,  use --cfg=model-check/reduction:none");
 
-      const kernel::actor::ActorImpl* issuer = api::get().simcall_get_issuer(req);
       for (auto i = stack_.rbegin(); i != stack_.rend(); ++i) {
         State* prev_state = i->get();
-        if (api::get().simcall_check_dependency(req, &prev_state->internal_req_)) {
+        if (state->executed_req_.issuer_ == prev_state->executed_req_.issuer_) {
+          XBT_DEBUG("Simcall %s and %s with same issuer", SIMIX_simcall_name(call),
+                    SIMIX_simcall_name(prev_state->executed_req_.call_));
+          break;
+        } else if (api::get().simcall_check_dependency(&state->internal_req_, &prev_state->internal_req_)) {
           if (XBT_LOG_ISENABLED(mc_safety, xbt_log_priority_debug)) {
             XBT_DEBUG("Dependent Transitions:");
-            int value              = prev_state->transition_.argument_;
+            int value              = prev_state->transition_.times_considered_;
             smx_simcall_t prev_req = &prev_state->executed_req_;
-            XBT_DEBUG("%s (state=%d)", api::get().request_to_string(prev_req, value, RequestType::internal).c_str(),
-                      prev_state->num_);
-            value    = state->transition_.argument_;
+            XBT_DEBUG("%s (state=%d)", api::get().request_to_string(prev_req, value).c_str(), prev_state->num_);
+            value    = state->transition_.times_considered_;
             prev_req = &state->executed_req_;
-            XBT_DEBUG("%s (state=%d)", api::get().request_to_string(prev_req, value, RequestType::executed).c_str(),
-                      state->num_);
+            XBT_DEBUG("%s (state=%d)", api::get().request_to_string(prev_req, value).c_str(), state->num_);
           }
 
           if (not prev_state->actor_states_[issuer->get_pid()].is_done())
-            prev_state->add_interleaving_set(issuer);
+            prev_state->mark_todo(issuer);
           else
-            XBT_DEBUG("Process %p is in done set", req->issuer_);
-          break;
-        } else if (req->issuer_ == prev_state->internal_req_.issuer_) {
-          XBT_DEBUG("Simcall %s and %s with same issuer", api::get().simcall_get_name(req->call_),
-                    api::get().simcall_get_name(prev_state->internal_req_.call_));
+            XBT_DEBUG("Actor %s %ld is in done set", issuer->get_cname(), issuer->get_pid());
           break;
         } else {
-          const kernel::actor::ActorImpl* previous_issuer = api::get().simcall_get_issuer(&prev_state->internal_req_);
+          const kernel::actor::ActorImpl* previous_issuer = api::get().simcall_get_issuer(&prev_state->executed_req_);
           XBT_DEBUG("Simcall %s, process %ld (state %d) and simcall %s, process %ld (state %d) are independent",
-                    api::get().simcall_get_name(req->call_), issuer->get_pid(), state->num_,
-                    api::get().simcall_get_name(prev_state->internal_req_.call_), previous_issuer->get_pid(), prev_state->num_);
+                    SIMIX_simcall_name(call), issuer->get_pid(), state->num_,
+                    SIMIX_simcall_name(prev_state->executed_req_.call_), previous_issuer->get_pid(), prev_state->num_);
         }
       }
     }
 
-    if (state->interleave_size() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
+    if (state->count_todo() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
       /* We found a back-tracking point, let's loop */
       XBT_DEBUG("Back-tracking to state %d at depth %zu", state->num_, stack_.size() + 1);
       stack_.push_back(std::move(state));
@@ -249,7 +239,7 @@ void SafetyChecker::restore_state()
   /* Intermediate backtracking */
   const State* last_state = stack_.back().get();
   if (last_state->system_state_) {
-    Api::get().restore_state(last_state->system_state_);
+    api::get().restore_state(last_state->system_state_);
     return;
   }
 
@@ -260,7 +250,7 @@ void SafetyChecker::restore_state()
   for (std::unique_ptr<State> const& state : stack_) {
     if (state == stack_.back())
       break;
-    api::get().execute(state->transition_);
+    api::get().execute(state->transition_, &state->executed_req_);
     /* Update statistics */
     api::get().mc_inc_visited_states();
     api::get().mc_inc_executed_trans();
@@ -296,7 +286,7 @@ SafetyChecker::SafetyChecker() : Checker()
   auto actors = api::get().get_actors();
   for (auto& actor : actors)
     if (api::get().actor_is_enabled(actor.copy.get_buffer()->get_pid())) {
-      initial_state->add_interleaving_set(actor.copy.get_buffer());
+      initial_state->mark_todo(actor.copy.get_buffer());
       if (reductionMode_ != ReductionMode::none)
         break;
     }