X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/93998c2ed02609cdbf9f8039a0c6f364940df8cb..b84ee33b90701d14bed35a4119b3a70827177dca:/src/mc/api/RemoteApp.cpp diff --git a/src/mc/api/RemoteApp.cpp b/src/mc/api/RemoteApp.cpp index 4addcf58c8..d7fa9773a8 100644 --- a/src/mc/api/RemoteApp.cpp +++ b/src/mc/api/RemoteApp.cpp @@ -4,14 +4,9 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/mc/api/RemoteApp.hpp" -#include "src/internal_config.h" // HAVE_SMPI #include "src/mc/explo/Exploration.hpp" #include "src/mc/mc_config.hpp" #include "xbt/asserts.h" -#if HAVE_SMPI -#include "smpi/smpi.h" -#include "src/smpi/include/private.hpp" -#endif #include "src/mc/api/State.hpp" #include "src/mc/mc_config.hpp" #include "src/mc/mc_exit.hpp" @@ -102,12 +97,6 @@ XBT_ATTRIB_NORETURN static void run_child_process(int socket, const std::vector< RemoteApp::RemoteApp(const std::vector& args) { -#if HAVE_SMPI - smpi_init_options(); // only performed once - xbt_assert(smpi_cfg_privatization() != SmpiPrivStrategies::MMAP, - "Please use the dlopen privatization schema when model-checking SMPI code"); -#endif - // Create an AF_LOCAL socketpair used for exchanging messages // between the model-checker process (ourselves) and the model-checked // process: @@ -128,22 +117,23 @@ RemoteApp::RemoteApp(const std::vector& args) xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?"); - auto process = std::make_unique(pid); + auto process = std::make_unique(pid); model_checker_ = std::make_unique(std::move(process), sockets[1]); mc_model_checker = model_checker_.get(); model_checker_->start(); /* Take the initial snapshot */ - model_checker_->wait_for_requests(); - initial_snapshot_ = std::make_shared(0, page_store_); + wait_for_requests(); + initial_snapshot_ = + std::make_shared(0, page_store_, model_checker_->get_remote_process_memory()); } RemoteApp::~RemoteApp() { initial_snapshot_ = nullptr; if (model_checker_) { - model_checker_->shutdown(); + shutdown(); model_checker_ = nullptr; mc_model_checker = nullptr; } @@ -151,12 +141,24 @@ RemoteApp::~RemoteApp() void RemoteApp::restore_initial_state() const { - this->initial_snapshot_->restore(&model_checker_->get_remote_process()); + this->initial_snapshot_->restore(model_checker_->get_remote_process_memory()); } unsigned long RemoteApp::get_maxpid() const { - return model_checker_->get_remote_process().get_maxpid(); + // note: we could maybe cache it and count the actor creation on checker side too. + // But counting correctly accross state checkpoint/restore would be annoying. + + model_checker_->get_channel().send(MessageType::ACTORS_MAXPID); + s_mc_message_int_t answer; + ssize_t answer_size = model_checker_->get_channel().receive(answer); + xbt_assert(answer_size != -1, "Could not receive message"); + xbt_assert(answer_size == sizeof answer, "Broken message (size=%zd; expected %zu)", answer_size, sizeof answer); + xbt_assert(answer.type == MessageType::ACTORS_MAXPID_REPLY, + "Received unexpected message %s (%i); expected MessageType::ACTORS_MAXPID_REPLY (%i)", + to_c_str(answer.type), (int)answer.type, (int)MessageType::ACTORS_MAXPID_REPLY); + + return answer.value; } void RemoteApp::get_actors_status(std::map& whereto) const @@ -168,10 +170,10 @@ void RemoteApp::get_actors_status(std::map& whereto) const // <----- send ACTORS_STATUS_REPLY // <----- send `N` `s_mc_message_actors_status_one_t` structs // <----- send `M` `s_mc_message_simcall_probe_one_t` structs - model_checker_->channel().send(MessageType::ACTORS_STATUS); + model_checker_->get_channel().send(MessageType::ACTORS_STATUS); s_mc_message_actors_status_answer_t answer; - ssize_t answer_size = model_checker_->channel().receive(answer); + ssize_t answer_size = model_checker_->get_channel().receive(answer); xbt_assert(answer_size != -1, "Could not receive message"); xbt_assert(answer_size == sizeof answer, "Broken message (size=%zd; expected %zu)", answer_size, sizeof answer); xbt_assert(answer.type == MessageType::ACTORS_STATUS_REPLY, @@ -189,7 +191,7 @@ void RemoteApp::get_actors_status(std::map& whereto) const std::vector status(answer.count); if (answer.count > 0) { size_t size = status.size() * sizeof(s_mc_message_actors_status_one_t); - ssize_t received = model_checker_->channel().receive(status.data(), size); + ssize_t received = model_checker_->get_channel().receive(status.data(), size); xbt_assert(static_cast(received) == size); } @@ -205,7 +207,7 @@ void RemoteApp::get_actors_status(std::map& whereto) const std::vector probes(answer.transition_count); if (answer.transition_count > 0) { for (auto& probe : probes) { - ssize_t received = model_checker_->channel().receive(probe); + ssize_t received = model_checker_->get_channel().receive(probe); xbt_assert(received >= 0, "Could not receive response to ACTORS_PROBE message (%s)", strerror(errno)); xbt_assert(static_cast(received) == sizeof probe, "Could not receive response to ACTORS_PROBE message (%zd bytes received != %zu bytes expected", @@ -236,9 +238,9 @@ void RemoteApp::get_actors_status(std::map& whereto) const void RemoteApp::check_deadlock() const { - xbt_assert(model_checker_->channel().send(MessageType::DEADLOCK_CHECK) == 0, "Could not check deadlock state"); + xbt_assert(model_checker_->get_channel().send(MessageType::DEADLOCK_CHECK) == 0, "Could not check deadlock state"); s_mc_message_int_t message; - ssize_t received = model_checker_->channel().receive(message); + ssize_t received = model_checker_->get_channel().receive(message); xbt_assert(received != -1, "Could not receive message"); xbt_assert(received == sizeof message, "Broken message (size=%zd; expected %zu)", received, sizeof message); xbt_assert(message.type == MessageType::DEADLOCK_CHECK_REPLY, @@ -256,4 +258,72 @@ void RemoteApp::check_deadlock() const throw DeadlockError(); } } + +void RemoteApp::wait_for_requests() +{ + /* Resume the application */ + if (model_checker_->get_channel().send(MessageType::CONTINUE) != 0) + throw xbt::errno_error(); + get_remote_process_memory().clear_cache(); + + if (this->get_remote_process_memory().running()) + model_checker_->channel_handle_events(); +} + +void RemoteApp::shutdown() +{ + XBT_DEBUG("Shutting down model-checker"); + + RemoteProcessMemory& process = get_remote_process_memory(); + if (process.running()) { + XBT_DEBUG("Killing process"); + finalize_app(true); + kill(process.pid(), SIGKILL); + process.terminate(); + } +} + +Transition* RemoteApp::handle_simcall(aid_t aid, int times_considered, bool new_transition) +{ + s_mc_message_simcall_execute_t m = {}; + m.type = MessageType::SIMCALL_EXECUTE; + m.aid_ = aid; + m.times_considered_ = times_considered; + model_checker_->get_channel().send(m); + + get_remote_process_memory().clear_cache(); + if (this->get_remote_process_memory().running()) + model_checker_->channel_handle_events(); // The app may send messages while processing the transition + + s_mc_message_simcall_execute_answer_t answer; + ssize_t s = model_checker_->get_channel().receive(answer); + xbt_assert(s != -1, "Could not receive message"); + xbt_assert(s == sizeof answer, "Broken message (size=%zd; expected %zu)", s, sizeof answer); + xbt_assert(answer.type == MessageType::SIMCALL_EXECUTE_ANSWER, + "Received unexpected message %s (%i); expected MessageType::SIMCALL_EXECUTE_ANSWER (%i)", + to_c_str(answer.type), (int)answer.type, (int)MessageType::SIMCALL_EXECUTE_ANSWER); + + if (new_transition) { + std::stringstream stream(answer.buffer.data()); + return deserialize_transition(aid, times_considered, stream); + } else + return nullptr; +} + +void RemoteApp::finalize_app(bool terminate_asap) +{ + s_mc_message_int_t m = {}; + m.type = MessageType::FINALIZE; + m.value = terminate_asap; + xbt_assert(model_checker_->get_channel().send(m) == 0, "Could not ask the app to finalize on need"); + + s_mc_message_t answer; + ssize_t s = model_checker_->get_channel().receive(answer); + xbt_assert(s != -1, "Could not receive answer to FINALIZE"); + xbt_assert(s == sizeof answer, "Broken message (size=%zd; expected %zu)", s, sizeof answer); + xbt_assert(answer.type == MessageType::FINALIZE_REPLY, + "Received unexpected message %s (%i); expected MessageType::FINALIZE_REPLY (%i)", to_c_str(answer.type), + (int)answer.type, (int)MessageType::FINALIZE_REPLY); +} + } // namespace simgrid::mc