From d2cc5a5e537a7b2915f781dd75ad8f4d02f6fcf7 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 12 Aug 2019 12:21:51 +0200 Subject: [PATCH] start to make generic simcalls observable from the MC WIP, done in the easy parts for now. Not finished in MC_state_get_request_for_process() yet. That's too bad because this function is the core of the use of simcalls by the MC, where the next simcall is picked. Not done in the independence computing part either. --- include/simgrid/simix.hpp | 30 ++++++-- include/simgrid/simix/blocking_simcall.hpp | 87 +++++++++++----------- src/mc/mc_base.cpp | 11 ++- src/mc/mc_request.cpp | 12 ++- src/simix/libsmx.cpp | 6 +- src/simix/popping_private.hpp | 1 + 6 files changed, 90 insertions(+), 57 deletions(-) diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index f28dbb294e..08bb97b713 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -16,8 +16,26 @@ #include #include -XBT_PUBLIC void simcall_run_kernel(std::function const& code); -XBT_PUBLIC void simcall_run_blocking(std::function const& code); +namespace simgrid { +namespace kernel { +namespace actor { + +class Transition { +public: + virtual bool fireable() + { + return true; + } // whether this transition can currently be taken (if not, it could block the process) + virtual bool visible() { return true; } // whether the model-checker should pay any attention to this simcall + virtual std::string to_string() = 0; + virtual std::string dot_label() = 0; +}; +} // namespace actor +} // namespace kernel +} // namespace simgrid + +XBT_PUBLIC void simcall_run_kernel(std::function const& code, simgrid::kernel::actor::Transition* t); +XBT_PUBLIC void simcall_run_blocking(std::function const& code, simgrid::kernel::actor::Transition* t); namespace simgrid { namespace kernel { @@ -42,7 +60,7 @@ namespace actor { * you may need to wait for that mutex to be unlocked by its current owner. * Potentially blocking simcall must be issued using simcall_blocking(), right below in this file. */ -template typename std::result_of::type simcall(F&& code) +template typename std::result_of::type simcall(F&& code, Transition* t = nullptr) { // If we are in the maestro, we take the fast path and execute the // code directly without simcall mashalling/unmarshalling/dispatch: @@ -54,7 +72,7 @@ template typename std::result_of::type simcall(F&& code) // conveniently handles the success/failure value for us. typedef typename std::result_of::type R; simgrid::xbt::Result result; - simcall_run_kernel([&result, &code] { simgrid::xbt::fulfill_promise(result, std::forward(code)); }); + simcall_run_kernel([&result, &code] { simgrid::xbt::fulfill_promise(result, std::forward(code)); }, t); return result.get(); } @@ -72,7 +90,7 @@ template typename std::result_of::type simcall(F&& code) * * If your code never calls actor->simcall_answer() itself, the actor will never return from its simcall. */ -template typename std::result_of::type simcall_blocking(F&& code) +template typename std::result_of::type simcall_blocking(F&& code, Transition* t = nullptr) { // If we are in the maestro, we take the fast path and execute the // code directly without simcall mashalling/unmarshalling/dispatch: @@ -84,7 +102,7 @@ template typename std::result_of::type simcall_blocking(F&& code) // conveniently handles the success/failure value for us. typedef typename std::result_of::type R; simgrid::xbt::Result result; - simcall_run_blocking([&result, &code] { simgrid::xbt::fulfill_promise(result, std::forward(code)); }); + simcall_run_blocking([&result, &code] { simgrid::xbt::fulfill_promise(result, std::forward(code)); }, t); return result.get(); } } // namespace actor diff --git a/include/simgrid/simix/blocking_simcall.hpp b/include/simgrid/simix/blocking_simcall.hpp index c8ba0f746a..017b7f2248 100644 --- a/include/simgrid/simix/blocking_simcall.hpp +++ b/include/simgrid/simix/blocking_simcall.hpp @@ -18,8 +18,6 @@ #include #include -XBT_PUBLIC void simcall_run_blocking(std::function const& code); - namespace simgrid { namespace simix { @@ -54,19 +52,20 @@ template auto kernel_sync(F code) -> decltype(code().get()) smx_actor_t self = SIMIX_process_self(); simgrid::xbt::Result result; - simcall_run_blocking([&result, self, &code]{ - try { - auto future = code(); - future.then_([&result, self](std::shared_ptr>&& value) { - simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); - simgrid::simix::unblock(self); - }); - } - catch (...) { - result.set_exception(std::current_exception()); - simgrid::simix::unblock(self); - } - }); + simcall_run_blocking( + [&result, self, &code] { + try { + auto future = code(); + future.then_([&result, self](std::shared_ptr>&& value) { + simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); + simgrid::simix::unblock(self); + }); + } catch (...) { + result.set_exception(std::current_exception()); + simgrid::simix::unblock(self); + } + }, + nullptr); return result.get(); } @@ -89,20 +88,21 @@ public: throw std::future_error(std::future_errc::no_state); smx_actor_t self = SIMIX_process_self(); simgrid::xbt::Result result; - simcall_run_blocking([this, &result, self]{ - try { - // When the kernel future is ready... - this->future_.then_([&result, self](std::shared_ptr>&& value) { - // ... wake up the process with the result of the kernel future. - simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); - simgrid::simix::unblock(self); - }); - } - catch (...) { - result.set_exception(std::current_exception()); - simgrid::simix::unblock(self); - } - }); + simcall_run_blocking( + [this, &result, self] { + try { + // When the kernel future is ready... + this->future_.then_([&result, self](std::shared_ptr>&& value) { + // ... wake up the process with the result of the kernel future. + simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); + simgrid::simix::unblock(self); + }); + } catch (...) { + result.set_exception(std::current_exception()); + simgrid::simix::unblock(self); + } + }, + nullptr); return result.get(); } bool is_ready() const @@ -119,20 +119,21 @@ public: // The future is not ready. We have to delegate to the SimGrid kernel: std::exception_ptr exception; smx_actor_t self = SIMIX_process_self(); - simcall_run_blocking([this, &exception, self]{ - try { - // When the kernel future is ready... - this->future_.then_([this, self](std::shared_ptr>&& value) { - // ...store it the simix kernel and wake up. - this->future_ = std::move(simgrid::kernel::Future(value)); - simgrid::simix::unblock(self); - }); - } - catch (...) { - exception = std::current_exception(); - simgrid::simix::unblock(self); - } - }); + simcall_run_blocking( + [this, &exception, self] { + try { + // When the kernel future is ready... + this->future_.then_([this, self](std::shared_ptr>&& value) { + // ...store it the simix kernel and wake up. + this->future_ = std::move(simgrid::kernel::Future(value)); + simgrid::simix::unblock(self); + }); + } catch (...) { + exception = std::current_exception(); + simgrid::simix::unblock(self); + } + }, + nullptr); } private: // We wrap an event-based kernel future: diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 413e9a7d9b..2a6b270e5e 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -78,6 +78,9 @@ bool actor_is_enabled(smx_actor_t actor) // Now, we are in the client app, no need for remote memory reading. smx_simcall_t req = &actor->simcall; + if (req->transition != nullptr) + return req->transition->fireable(); + switch (req->call) { case SIMCALL_NONE: return false; @@ -150,10 +153,10 @@ bool request_is_visible(smx_simcall_t req) xbt_assert(mc_model_checker == nullptr, "This should be called from the client side"); #endif - return req->call == SIMCALL_COMM_ISEND || req->call == SIMCALL_COMM_IRECV || req->call == SIMCALL_COMM_WAIT || - req->call == SIMCALL_COMM_WAITANY || req->call == SIMCALL_COMM_TEST || req->call == SIMCALL_COMM_TESTANY || - req->call == SIMCALL_MC_RANDOM || req->call == SIMCALL_MUTEX_LOCK || req->call == SIMCALL_MUTEX_TRYLOCK || - req->call == SIMCALL_MUTEX_UNLOCK; + return (req->transition != nullptr && req->transition->visible()) || req->call == SIMCALL_COMM_ISEND || + req->call == SIMCALL_COMM_IRECV || req->call == SIMCALL_COMM_WAIT || req->call == SIMCALL_COMM_WAITANY || + req->call == SIMCALL_COMM_TEST || req->call == SIMCALL_COMM_TESTANY || req->call == SIMCALL_MC_RANDOM || + req->call == SIMCALL_MUTEX_LOCK || req->call == SIMCALL_MUTEX_TRYLOCK || req->call == SIMCALL_MUTEX_UNLOCK; } } diff --git a/src/mc/mc_request.cpp b/src/mc/mc_request.cpp index b46fc559d0..900a115e2f 100644 --- a/src/mc/mc_request.cpp +++ b/src/mc/mc_request.cpp @@ -176,6 +176,9 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid { xbt_assert(mc_model_checker != nullptr, "Must be called from MCer"); + if (req->transition != nullptr) + return req->transition->to_string(); + bool use_remote_comm = true; switch(request_type) { case simgrid::mc::RequestType::simix: @@ -417,9 +420,15 @@ static inline const char* get_color(int id) std::string request_get_dot_output(smx_simcall_t req, int value) { + const smx_actor_t issuer = MC_smx_simcall_get_issuer(req); + const char* color = get_color(issuer->get_pid() - 1); + + if (req->transition != nullptr) + return simgrid::xbt::string_printf("label = \"%s\", color = %s, fontcolor = %s", + req->transition->dot_label().c_str(), color, color); + std::string label; - const smx_actor_t issuer = MC_smx_simcall_get_issuer(req); switch (req->call) { case SIMCALL_COMM_ISEND: @@ -531,7 +540,6 @@ std::string request_get_dot_output(smx_simcall_t req, int value) THROW_UNIMPLEMENTED; } - const char* color = get_color(issuer->get_pid() - 1); return simgrid::xbt::string_printf( "label = \"%s\", color = %s, fontcolor = %s", label.c_str(), color, color); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 4a0aa0ef46..c8470a43b8 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -307,13 +307,15 @@ e_smx_state_t simcall_io_wait(const smx_activity_t& io) return (e_smx_state_t)simcall_BODY_io_wait(static_cast(io.get())); } -void simcall_run_kernel(std::function const& code) +void simcall_run_kernel(std::function const& code, simgrid::kernel::actor::Transition* t) { + SIMIX_process_self()->simcall.transition = t; simcall_BODY_run_kernel(&code); } -void simcall_run_blocking(std::function const& code) +void simcall_run_blocking(std::function const& code, simgrid::kernel::actor::Transition* t = nullptr) { + SIMIX_process_self()->simcall.transition = t; simcall_BODY_run_blocking(&code); } diff --git a/src/simix/popping_private.hpp b/src/simix/popping_private.hpp index 83f7e2d84b..f0c6cce8b1 100644 --- a/src/simix/popping_private.hpp +++ b/src/simix/popping_private.hpp @@ -46,6 +46,7 @@ struct s_smx_simcall { e_smx_simcall_t call; smx_actor_t issuer; smx_timer_t timeout_cb; // Callback to timeouts + simgrid::kernel::actor::Transition* transition = nullptr; int mc_value; u_smx_scalar args[11]; u_smx_scalar result; -- 2.20.1