Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move xbt_modinter.h to src/include/xbt/.
[simgrid.git] / src / mc / remote / AppSide.cpp
index 665da7d..abf4c25 100644 (file)
@@ -6,7 +6,9 @@
 #include "src/mc/remote/AppSide.hpp"
 #include "src/internal_config.h"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/mc/checker/SimcallInspector.hpp"
+#include "src/kernel/actor/SimcallObserver.hpp"
+#include "src/mc/remote/RemoteProcess.hpp"
+#include "xbt/xbt_modinter.h" /* mmalloc_preinit to get the default mmalloc arena address */
 #include <simgrid/modelchecker.h>
 
 #include <cerrno>
@@ -17,9 +19,6 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 
-// We won't need those once the separation MCer/MCed is complete:
-#include "src/mc/mc_smx.hpp"
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic");
 
 namespace simgrid {
@@ -65,6 +64,11 @@ AppSide* AppSide::initialize()
   if (errno != 0 || raise(SIGSTOP) != 0)
     xbt_die("Could not wait for the model-checker (errno = %d: %s)", errno, strerror(errno));
 
+  s_mc_message_initial_addresses_t message{
+      MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), simgrid::kernel::actor::get_maxpid_addr(),
+      simgrid::simix::simix_global_get_actors_addr(), simgrid::simix::simix_global_get_dead_actors_addr()};
+  xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses.");
+
   instance_->handle_messages();
   return instance_.get();
 }
@@ -85,22 +89,18 @@ void AppSide::handle_deadlock_check(const s_mc_message_t*) const
   s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, deadlock};
   xbt_assert(channel_.send(answer) == 0, "Could not send response");
 }
-void AppSide::handle_continue(const s_mc_message_t*) const
-{
-  /* Nothing to do */
-}
-void AppSide::handle_simcall(const s_mc_message_simcall_handle_t* message) const
+void AppSide::handle_simcall_execute(const s_mc_message_simcall_handle_t* message) const
 {
-  kernel::actor::ActorImpl* process = kernel::actor::ActorImpl::by_PID(message->pid);
-  xbt_assert(process != nullptr, "Invalid pid %lu", message->pid);
-  process->simcall_handle(message->value);
+  kernel::actor::ActorImpl* process = kernel::actor::ActorImpl::by_pid(message->pid_);
+  xbt_assert(process != nullptr, "Invalid pid %lu", message->pid_);
+  process->simcall_handle(message->times_considered_);
   if (channel_.send(MessageType::WAITING))
     xbt_die("Could not send MESSAGE_WAITING to model-checker");
 }
 
 void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const
 {
-  bool res = simgrid::mc::actor_is_enabled(kernel::actor::ActorImpl::by_PID(msg->aid));
+  bool res = simgrid::mc::actor_is_enabled(kernel::actor::ActorImpl::by_pid(msg->aid));
   s_mc_message_int_t answer{MessageType::ACTOR_ENABLED_REPLY, res};
   channel_.send(answer);
 }
@@ -111,7 +111,7 @@ void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) cons
 
 void AppSide::handle_messages() const
 {
-  while (true) {
+  while (true) { // Until we get a CONTINUE message
     XBT_DEBUG("Waiting messages from model-checker");
 
     std::array<char, MC_MESSAGE_LENGTH> message_buffer;
@@ -128,35 +128,20 @@ void AppSide::handle_messages() const
 
       case MessageType::CONTINUE:
         assert_msg_size("MESSAGE_CONTINUE", s_mc_message_t);
-        handle_continue(message);
         return;
 
       case MessageType::SIMCALL_HANDLE:
         assert_msg_size("SIMCALL_HANDLE", s_mc_message_simcall_handle_t);
-        handle_simcall((s_mc_message_simcall_handle_t*)message_buffer.data());
-        break;
-
-      case MessageType::SIMCALL_IS_PENDING: {
-        assert_msg_size("SIMCALL_IS_PENDING", s_mc_message_simcall_is_pending_t);
-        auto msg_simcall                = (s_mc_message_simcall_is_pending_t*)message_buffer.data();
-        kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_PID(msg_simcall->aid);
-        xbt_assert(actor != nullptr, "Invalid pid %d", msg_simcall->aid);
-        xbt_assert(actor->simcall_.inspector_, "The transition of %s has no inspector", actor->get_cname());
-        bool value = actor->simcall_.inspector_->is_pending(msg_simcall->time_considered);
-
-        // Send result:
-        s_mc_message_simcall_is_pending_answer_t answer{MessageType::SIMCALL_IS_PENDING_ANSWER, value};
-        xbt_assert(channel_.send(answer) == 0, "Could not send response");
+        handle_simcall_execute((s_mc_message_simcall_handle_t*)message_buffer.data());
         break;
-      }
 
       case MessageType::SIMCALL_IS_VISIBLE: {
         assert_msg_size("SIMCALL_IS_VISIBLE", s_mc_message_simcall_is_visible_t);
         auto msg_simcall                = (s_mc_message_simcall_is_visible_t*)message_buffer.data();
-        kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_PID(msg_simcall->aid);
+        const kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(msg_simcall->aid);
         xbt_assert(actor != nullptr, "Invalid pid %d", msg_simcall->aid);
-        xbt_assert(actor->simcall_.inspector_, "The transition of %s has no inspector", actor->get_cname());
-        bool value = actor->simcall_.inspector_->is_visible();
+        xbt_assert(actor->simcall_.observer_, "The transition of %s has no observer", actor->get_cname());
+        bool value = actor->simcall_.observer_->is_visible();
 
         // Send result:
         s_mc_message_simcall_is_visible_answer_t answer{MessageType::SIMCALL_IS_VISIBLE_ANSWER, value};
@@ -167,14 +152,14 @@ void AppSide::handle_messages() const
       case MessageType::SIMCALL_TO_STRING: {
         assert_msg_size("SIMCALL_TO_STRING", s_mc_message_simcall_to_string_t);
         auto msg_simcall                = (s_mc_message_simcall_to_string_t*)message_buffer.data();
-        kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_PID(msg_simcall->aid);
+        const kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(msg_simcall->aid);
         xbt_assert(actor != nullptr, "Invalid pid %d", msg_simcall->aid);
-        xbt_assert(actor->simcall_.inspector_, "The transition of %s has no inspector", actor->get_cname());
-        std::string value = actor->simcall_.inspector_->to_string(msg_simcall->time_considered);
+        xbt_assert(actor->simcall_.observer_, "The transition of %s has no observer", actor->get_cname());
+        std::string value = actor->simcall_.observer_->to_string(msg_simcall->time_considered);
 
         // Send result:
-        s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, 0};
-        strcat(answer.value, value.c_str());
+        s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
+        value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
         xbt_assert(channel_.send(answer) == 0, "Could not send response");
         break;
       }
@@ -182,14 +167,14 @@ void AppSide::handle_messages() const
       case MessageType::SIMCALL_DOT_LABEL: {
         assert_msg_size("SIMCALL_DOT_LABEL", s_mc_message_simcall_to_string_t);
         auto msg_simcall                = (s_mc_message_simcall_to_string_t*)message_buffer.data();
-        kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_PID(msg_simcall->aid);
+        const kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(msg_simcall->aid);
         xbt_assert(actor != nullptr, "Invalid pid %d", msg_simcall->aid);
-        xbt_assert(actor->simcall_.inspector_, "The transition of %s has no inspector", actor->get_cname());
-        std::string value = actor->simcall_.inspector_->dot_label();
+        xbt_assert(actor->simcall_.observer_, "The transition of %s has no observer", actor->get_cname());
+        std::string value = actor->simcall_.observer_->dot_label();
 
         // Send result:
-        s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, 0};
-        strcat(answer.value, value.c_str());
+        s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
+        value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
         xbt_assert(channel_.send(answer) == 0, "Could not send response");
         break;
       }
@@ -199,6 +184,18 @@ void AppSide::handle_messages() const
         handle_actor_enabled((s_mc_message_actor_enabled_t*)message_buffer.data());
         break;
 
+      case MessageType::FINALIZE: {
+#if HAVE_SMPI
+        XBT_INFO("Finalize. Smpi_enabled: %d", (int)smpi_enabled());
+        simix_global->display_all_actor_status();
+        if (smpi_enabled())
+          SMPI_finalize();
+#endif
+        s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, 0};
+        xbt_assert(channel_.send(answer) == 0, "Could answer to FINALIZE");
+        break;
+      }
+
       default:
         xbt_die("Received unexpected message %s (%i)", to_c_str(message->type), static_cast<int>(message->type));
         break;
@@ -209,7 +206,7 @@ void AppSide::handle_messages() const
 void AppSide::main_loop() const
 {
   while (true) {
-    simgrid::mc::wait_for_requests();
+    simgrid::mc::execute_actors();
     xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send WAITING message to model-checker");
     this->handle_messages();
   }