1 /* Copyright (c) 2007-2017. 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
12 #include "src/mc/Transition.hpp"
13 #include "src/mc/mc_record.hpp"
14 #include "src/mc/mc_snapshot.hpp"
19 enum class PatternCommunicationType {
25 class PatternCommunication {
28 simgrid::kernel::activity::CommImpl* comm_addr;
29 PatternCommunicationType type = PatternCommunicationType::send;
30 unsigned long src_proc = 0;
31 unsigned long dst_proc = 0;
32 const char* src_host = nullptr;
33 const char* dst_host = nullptr;
35 std::vector<char> data;
39 PatternCommunication() { std::memset(&comm_addr, 0, sizeof(comm_addr)); }
41 PatternCommunication dup() const
43 simgrid::mc::PatternCommunication res;
45 res.comm_addr = this->comm_addr;
46 res.type = this->type;
49 res.dst_proc = this->dst_proc;
50 res.dst_host = this->dst_host;
52 res.data = this->data;
54 res.index = this->index;
59 /* On every state, each process has an entry of the following type.
60 * This represents both the process and its transition because
61 * a process cannot have more than one enabled transition at a given time.
64 /* Possible exploration status of a process transition in a state.
65 * Either the checker did not consider the transition, or it was considered and to do, or considered and done.
67 enum class InterleavingType {
68 /** This process transition is not considered by the checker (yet?) */
70 /** The checker algorithm decided that this process transitions should be done at some point */
72 /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
76 /** Exploration control information */
77 InterleavingType state = InterleavingType::disabled;
80 /** Number of times that the process was considered to be executed */
81 // TODO, make this private
82 unsigned int times_considered = 0;
84 bool isDisabled() const { return this->state == InterleavingType::disabled; }
85 bool isDone() const { return this->state == InterleavingType::done; }
86 bool isTodo() const { return this->state == InterleavingType::todo; }
87 /** Mark that we should try executing this process at some point in the future of the checker algorithm */
90 this->state = InterleavingType::todo;
91 this->times_considered = 0;
93 void setDone() { this->state = InterleavingType::done; }
96 /* A node in the exploration graph (kind-of)
98 class XBT_PRIVATE State {
100 /** Sequential state number (used for debugging) */
103 /** State's exploration status by process */
104 std::vector<ProcessState> actorStates;
106 Transition transition;
108 /** The simcall which was executed, going out of that state */
109 s_smx_simcall_t executed_req;
111 /* Internal translation of the executed_req simcall
113 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
114 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
116 s_smx_simcall_t internal_req;
118 /* Can be used as a copy of the remote synchro object */
119 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> internal_comm;
121 /** Snapshot of system state (if needed) */
122 std::shared_ptr<simgrid::mc::Snapshot> system_state;
124 // For CommunicationDeterminismChecker
125 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
126 std::vector<unsigned> communicationIndices;
128 explicit State(unsigned long state_number);
130 std::size_t interleaveSize() const;
131 void addInterleavingSet(smx_actor_t actor) { this->actorStates[actor->pid].consider(); }
132 Transition getTransition() const;
137 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);