Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move the selection of the next transition to execute to mc::State
[simgrid.git] / src / mc / Transition.cpp
1 /* Copyright (c) 2015-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/Transition.hpp"
7 #include "src/mc/ModelChecker.hpp"
8 #include "src/mc/Session.hpp"
9 #include "src/mc/mc_state.hpp"
10 #include "src/mc/remote/RemoteProcess.hpp"
11 #include "xbt/asserts.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
14
15 namespace simgrid {
16 namespace mc {
17 unsigned long Transition::executed_transitions_ = 0;
18
19 std::string Transition::to_string()
20 {
21   xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
22
23   return textual_;
24 }
25 RemotePtr<simgrid::kernel::actor::SimcallObserver> Transition::execute(simgrid::mc::State* state, int next)
26 {
27   std::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
28
29   kernel::actor::ActorImpl* actor = actors[next].copy.get_buffer();
30   aid_t aid                       = actor->get_pid();
31
32   simgrid::mc::ActorState* actor_state = &state->actor_states_[aid];
33   /* This actor is ready to be executed. Prepare its execution when simcall_handle will be called on it */
34   if (actor->simcall_.observer_ != nullptr) {
35     state->transition_.times_considered_ = actor_state->get_times_considered_and_inc();
36     if (actor->simcall_.mc_max_consider_ <= actor_state->get_times_considered())
37       actor_state->set_done();
38   } else {
39     state->transition_.times_considered_ = 0;
40     actor_state->set_done();
41   }
42
43   aid_                 = aid;
44   state->executed_req_ = actor->simcall_;
45
46   textual_ = mc_model_checker->simcall_to_string(aid_, times_considered_);
47   XBT_DEBUG("Let's run actor %ld, going for transition %s", aid, textual_.c_str());
48
49   return replay();
50 }
51 RemotePtr<simgrid::kernel::actor::SimcallObserver> Transition::replay()
52 {
53   executed_transitions_++;
54
55   simgrid::mc::RemotePtr<simgrid::kernel::actor::SimcallObserver> res = mc_model_checker->handle_simcall(*this);
56   mc_model_checker->wait_for_requests();
57
58   return res;
59 }
60
61 } // namespace mc
62 } // namespace simgrid