Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Actually, read()=0 is not an issue in the AppSide
[simgrid.git] / src / mc / remote / AppSide.cpp
index 4617ec7c9dee3491707b6abe3f772ea2a9f5a948..447f7db0f48cfe1b07d1c53ba5cf5e712e0540ed 100644 (file)
@@ -11,7 +11,7 @@
 #include "src/kernel/actor/SimcallObserver.hpp"
 #include "src/mc/mc_base.hpp"
 #include "src/mc/mc_config.hpp"
-#include "src/mc/remote/RemoteProcess.hpp"
+#include "src/mc/sosp/RemoteProcessMemory.hpp"
 #if HAVE_SMPI
 #include "src/smpi/include/private.hpp"
 #endif
@@ -45,7 +45,7 @@ AppSide* AppSide::initialize()
   if (instance_)
     return instance_.get();
 
-  simgrid::mc::cfg_do_model_check = true;
+  simgrid::mc::model_checking_mode = ModelCheckingMode::APP_SIDE;
 
   setvbuf(stdout, nullptr, _IOLBF, 0);
 
@@ -75,12 +75,6 @@ AppSide* AppSide::initialize()
   xbt_assert(errno == 0 && raise(SIGSTOP) == 0, "Could not wait for the model-checker (errno = %d: %s)", errno,
              strerror(errno));
 
-  s_mc_message_initial_addresses_t message = {};
-  message.type                = MessageType::INITIAL_ADDRESSES;
-  message.mmalloc_default_mdp = mmalloc_get_current_heap();
-  message.maxpid              = kernel::actor::ActorImpl::get_maxpid_addr();
-  xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses.");
-
   instance_->handle_messages();
   return instance_.get();
 }
@@ -153,6 +147,14 @@ void AppSide::handle_finalize(const s_mc_message_int_t* msg) const
   if (terminate_asap)
     ::_Exit(0);
 }
+void AppSide::handle_initial_addresses()
+{
+  this->need_memory_info_                       = true;
+  s_mc_message_initial_addresses_reply_t answer = {};
+  answer.type                                   = MessageType::INITIAL_ADDRESSES_REPLY;
+  answer.mmalloc_default_mdp                    = mmalloc_get_current_heap();
+  xbt_assert(channel_.send(answer) == 0, "Could not send response with initial addresses.");
+}
 void AppSide::handle_actors_status() const
 {
   auto const& actor_list = kernel::EngineImpl::get_instance()->get_actor_list();
@@ -224,12 +226,19 @@ void AppSide::handle_actors_status() const
       xbt_assert(channel_.send(probe) == 0, "Could not send ACTOR_TRANSITION_PROBE payload");
   }
 }
+void AppSide::handle_actors_maxpid() const
+{
+  s_mc_message_int_t answer = {};
+  answer.type               = MessageType::ACTORS_MAXPID_REPLY;
+  answer.value              = kernel::actor::ActorImpl::get_maxpid();
+  xbt_assert(channel_.send(answer) == 0, "Could not send response");
+}
 
 #define assert_msg_size(_name_, _type_)                                                                                \
   xbt_assert(received_size == sizeof(_type_), "Unexpected size for " _name_ " (%zd != %zu)", received_size,            \
              sizeof(_type_))
 
-void AppSide::handle_messages() const
+void AppSide::handle_messages()
 {
   while (true) { // Until we get a CONTINUE message
     XBT_DEBUG("Waiting messages from model-checker");
@@ -237,6 +246,10 @@ void AppSide::handle_messages() const
     std::array<char, MC_MESSAGE_LENGTH> message_buffer;
     ssize_t received_size = channel_.receive(message_buffer.data(), message_buffer.size());
 
+    if (received_size == 0) {
+      XBT_DEBUG("Socket closed on the Checker side, bailing out.");
+      ::_Exit(0); // Nobody's listening to that process anymore => exit as quickly as possible.
+    }
     xbt_assert(received_size >= 0, "Could not receive commands from the model-checker");
     xbt_assert(static_cast<size_t>(received_size) >= sizeof(s_mc_message_t), "Cannot handle short message (size=%zd)",
                received_size);
@@ -262,11 +275,21 @@ void AppSide::handle_messages() const
         handle_finalize((s_mc_message_int_t*)message_buffer.data());
         break;
 
+      case MessageType::INITIAL_ADDRESSES:
+        assert_msg_size("INITIAL_ADDRESSES", s_mc_message_t);
+        handle_initial_addresses();
+        break;
+
       case MessageType::ACTORS_STATUS:
         assert_msg_size("ACTORS_STATUS", s_mc_message_t);
         handle_actors_status();
         break;
 
+      case MessageType::ACTORS_MAXPID:
+        assert_msg_size("ACTORS_MAXPID", s_mc_message_t);
+        handle_actors_maxpid();
+        break;
+
       default:
         xbt_die("Received unexpected message %s (%i)", to_c_str(message->type), static_cast<int>(message->type));
         break;
@@ -274,7 +297,7 @@ void AppSide::handle_messages() const
   }
 }
 
-void AppSide::main_loop() const
+void AppSide::main_loop()
 {
   simgrid::mc::processes_time.resize(simgrid::kernel::actor::ActorImpl::get_maxpid());
   MC_ignore_heap(simgrid::mc::processes_time.data(),
@@ -290,7 +313,7 @@ void AppSide::main_loop() const
   }
 }
 
-void AppSide::report_assertion_failure() const
+void AppSide::report_assertion_failure()
 {
   xbt_assert(channel_.send(MessageType::ASSERTION_FAILED) == 0, "Could not send assertion to model-checker");
   this->handle_messages();
@@ -298,7 +321,7 @@ void AppSide::report_assertion_failure() const
 
 void AppSide::ignore_memory(void* addr, std::size_t size) const
 {
-  if (not MC_is_active())
+  if (not MC_is_active() || not need_memory_info_)
     return;
 
   s_mc_message_ignore_memory_t message = {};
@@ -310,7 +333,7 @@ void AppSide::ignore_memory(void* addr, std::size_t size) const
 
 void AppSide::ignore_heap(void* address, std::size_t size) const
 {
-  if (not MC_is_active())
+  if (not MC_is_active() || not need_memory_info_)
     return;
 
   const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
@@ -333,7 +356,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
 
 void AppSide::unignore_heap(void* address, std::size_t size) const
 {
-  if (not MC_is_active())
+  if (not MC_is_active() || not need_memory_info_)
     return;
 
   s_mc_message_ignore_memory_t message = {};
@@ -345,8 +368,10 @@ void AppSide::unignore_heap(void* address, std::size_t size) const
 
 void AppSide::declare_symbol(const char* name, int* value) const
 {
-  if (not MC_is_active())
+  if (not MC_is_active() || not need_memory_info_) {
+    XBT_CRITICAL("Ignore AppSide::declare_symbol(%s)", name);
     return;
+  }
 
   s_mc_message_register_symbol_t message = {};
   message.type = MessageType::REGISTER_SYMBOL;
@@ -365,7 +390,7 @@ void AppSide::declare_symbol(const char* name, int* value) const
  */
 void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
 {
-  if (not MC_is_active())
+  if (not MC_is_active() || not need_memory_info_)
     return;
 
   const s_xbt_mheap_t* heap = mmalloc_get_current_heap();