Logo AND Algorithmique Numérique Distribuée

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