1 /* Copyright (c) 2007-2020. 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 #ifndef SIMGRID_MC_STATE_HPP
7 #define SIMGRID_MC_STATE_HPP
9 #include "src/kernel/activity/CommImpl.hpp"
10 #include "src/mc/Transition.hpp"
11 #include "src/mc/sosp/Snapshot.hpp"
16 enum class PatternCommunicationType {
22 class PatternCommunication {
25 simgrid::kernel::activity::CommImpl* comm_addr;
26 PatternCommunicationType type = PatternCommunicationType::send;
27 unsigned long src_proc = 0;
28 unsigned long dst_proc = 0;
29 const char* src_host = nullptr;
30 const char* dst_host = nullptr;
32 std::vector<char> data;
36 PatternCommunication() { std::memset(&comm_addr, 0, sizeof(comm_addr)); }
38 PatternCommunication dup() const
40 simgrid::mc::PatternCommunication res;
42 res.comm_addr = this->comm_addr;
43 res.type = this->type;
46 res.dst_proc = this->dst_proc;
47 res.dst_host = this->dst_host;
49 res.data = this->data;
51 res.index = this->index;
56 /* On every state, each actor has an entry of the following type.
57 * This represents both the actor and its transition because
58 * an actor cannot have more than one enabled transition at a given time.
61 /* Possible exploration status of a actor transition in a state.
62 * Either the checker did not consider the transition, or it was considered and still to do, or considered and done.
64 enum class InterleavingType {
65 /** This actor transition is not considered by the checker (yet?) */
67 /** The checker algorithm decided that this actor transitions should be done at some point */
69 /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
73 /** Exploration control information */
74 InterleavingType state = InterleavingType::disabled;
77 /** Number of times that the process was considered to be executed */
78 // TODO, make this private
79 unsigned int times_considered = 0;
81 bool is_disabled() const { return this->state == InterleavingType::disabled; }
82 bool is_done() const { return this->state == InterleavingType::done; }
83 bool is_todo() const { return this->state == InterleavingType::todo; }
84 /** Mark that we should try executing this process at some point in the future of the checker algorithm */
87 this->state = InterleavingType::todo;
88 this->times_considered = 0;
90 void set_done() { this->state = InterleavingType::done; }
93 /* A node in the exploration graph (kind-of) */
94 class XBT_PRIVATE State {
96 /** Sequential state number (used for debugging) */
99 /** State's exploration status by process */
100 std::vector<ActorState> actor_states_;
102 Transition transition_;
104 /** The simcall which was executed, going out of that state */
105 s_smx_simcall executed_req_;
107 /* Internal translation of the executed_req simcall
109 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
110 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
112 s_smx_simcall internal_req_;
114 /* Can be used as a copy of the remote synchro object */
115 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> internal_comm_;
117 /** Snapshot of system state (if needed) */
118 std::shared_ptr<simgrid::mc::Snapshot> system_state_;
120 // For CommunicationDeterminismChecker
121 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern_;
122 std::vector<unsigned> communication_indices_;
124 explicit State(unsigned long state_number);
126 std::size_t interleave_size() const;
127 void add_interleaving_set(const simgrid::kernel::actor::ActorImpl* actor)
129 this->actor_states_[actor->get_pid()].consider();
131 Transition get_transition() const;
136 XBT_PRIVATE smx_simcall_t MC_state_choose_request(simgrid::mc::State* state);