1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/mc_base.hpp"
7 #include "src/kernel/EngineImpl.hpp"
8 #include "src/kernel/activity/CommImpl.hpp"
9 #include "src/kernel/activity/MutexImpl.hpp"
10 #include "src/kernel/actor/SimcallObserver.hpp"
12 #include "src/mc/mc.h"
13 #include "src/mc/mc_config.hpp"
14 #include "src/mc/mc_replay.hpp"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(mc, "All MC categories");
17 bool simgrid_mc_replay_show_backtraces = false;
19 namespace simgrid::mc {
23 auto* engine = kernel::EngineImpl::get_instance();
25 XBT_DEBUG("execute_actors: %lu of %zu to run (%s)", engine->get_actor_to_run_count(), engine->get_actor_count(),
26 (MC_record_replay_is_active() ? "replay active" : "no replay"));
27 while (engine->has_actors_to_run()) {
28 engine->run_all_actors();
29 for (auto const& actor : engine->get_actors_that_ran()) {
30 const kernel::actor::Simcall* req = &actor->simcall_;
31 if (req->call_ != kernel::actor::Simcall::Type::NONE && not simgrid::mc::request_is_visible(req))
32 actor->simcall_handle(0);
37 /** @brief returns if there this transition can proceed in a finite amount of time
39 * It is used in the model-checker to not get into self-deadlock where it would execute a never ending transition.
41 * Only WAIT operations (on comm, on mutex, etc) can ever return false because they could lock the MC exploration.
42 * Wait operations are OK and return true in only two situations:
43 * - if the wait will succeed immediately (if both peer of the comm are there already or if the mutex is available)
44 * - if a timeout is provided, because we can fire the timeout if the transition is not ready without blocking in this
45 * transition for ever.
46 * This is controlled in the is_enabled() method of the corresponding observers.
48 bool actor_is_enabled(kernel::actor::ActorImpl* actor)
50 xbt_assert(get_model_checking_mode() != ModelCheckingMode::CHECKER_SIDE,
51 "This should be called from the client side");
53 // Now, we are in the client app, no need for remote memory reading.
54 kernel::actor::Simcall* req = &actor->simcall_;
56 if (req->observer_ != nullptr)
57 return req->observer_->is_enabled();
59 if (req->call_ == kernel::actor::Simcall::Type::NONE)
62 /* The rest of the requests are always enabled */
66 /* This is the list of requests that are visible from the checker algorithm.
67 * Any other requests are handled right away on the application side.
69 bool request_is_visible(const kernel::actor::Simcall* req)
71 xbt_assert(get_model_checking_mode() != ModelCheckingMode::CHECKER_SIDE,
72 "This should be called from the client side");
74 if (req->observer_ == nullptr)
76 return req->observer_->is_visible();
79 } // namespace simgrid::mc