Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Align the behavior of MC and MC_replay in SMPI, so that replay actually works
[simgrid.git] / src / mc / mc_base.cpp
1 /* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/mc/mc_base.hpp"
7 #include "mc/mc.h"
8 #include "src/kernel/EngineImpl.hpp"
9 #include "src/kernel/activity/CommImpl.hpp"
10 #include "src/kernel/activity/MutexImpl.hpp"
11 #include "src/kernel/actor/SimcallObserver.hpp"
12 #include "src/mc/mc_replay.hpp"
13
14 #if SIMGRID_HAVE_MC
15 #include "src/mc/ModelChecker.hpp"
16 #include "src/mc/api/RemoteApp.hpp"
17 #include "src/mc/remote/AppSide.hpp"
18 #include "src/mc/remote/RemoteProcess.hpp"
19 #endif
20
21 XBT_LOG_NEW_DEFAULT_CATEGORY(mc, "All MC categories");
22
23 namespace simgrid::mc {
24
25 void execute_actors()
26 {
27   auto* engine = kernel::EngineImpl::get_instance();
28
29   XBT_DEBUG("execute_actors: %lu of %zu to run (%s)", engine->get_actor_to_run_count(), engine->get_actor_count(),
30             (MC_record_replay_is_active() ? "replay active" : "no replay"));
31   while (engine->has_actors_to_run()) {
32     engine->run_all_actors();
33     for (auto const& actor : engine->get_actors_that_ran()) {
34       const kernel::actor::Simcall* req = &actor->simcall_;
35       if (req->call_ != kernel::actor::Simcall::Type::NONE && not simgrid::mc::request_is_visible(req))
36         actor->simcall_handle(0);
37     }
38   }
39 }
40
41 /** @brief returns if there this transition can proceed in a finite amount of time
42  *
43  * It is used in the model-checker to not get into self-deadlock where it would execute a never ending transition.
44  *
45  * Only WAIT operations (on comm, on mutex, etc) can ever return false because they could lock the MC exploration.
46  * Wait operations are OK and return true in only two situations:
47  *  - if the wait will succeed immediately (if both peer of the comm are there already or if the mutex is available)
48  *  - if a timeout is provided, because we can fire the timeout if the transition is not ready without blocking in this
49  * transition for ever.
50  * This is controlled in the is_enabled() method of the corresponding observers.
51  */
52 bool actor_is_enabled(kernel::actor::ActorImpl* actor)
53 {
54 #if SIMGRID_HAVE_MC
55   xbt_assert(mc_model_checker == nullptr, "This should be called from the client side");
56 #endif
57
58   // Now, we are in the client app, no need for remote memory reading.
59   kernel::actor::Simcall* req = &actor->simcall_;
60
61   if (req->observer_ != nullptr)
62     return req->observer_->is_enabled();
63
64   if (req->call_ == kernel::actor::Simcall::Type::NONE)
65     return false;
66   else
67     /* The rest of the requests are always enabled */
68     return true;
69 }
70
71 /* This is the list of requests that are visible from the checker algorithm.
72  * Any other requests are handled right away on the application side.
73  */
74 bool request_is_visible(const kernel::actor::Simcall* req)
75 {
76 #if SIMGRID_HAVE_MC
77   xbt_assert(mc_model_checker == nullptr, "This should be called from the client side");
78 #endif
79   if (req->observer_ == nullptr)
80     return false;
81   return req->observer_->is_visible();
82 }
83
84 } // namespace simgrid::mc