1 /* Copyright (c) 2007-2019. 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 process has an entry of the following type.
57 * This represents both the process and its transition because
58 * a process cannot have more than one enabled transition at a given time.
61 /* Possible exploration status of a process transition in a state.
62 * Either the checker did not consider the transition, or it was considered and to do, or considered and done.
64 enum class InterleavingType {
65 /** This process transition is not considered by the checker (yet?) */
67 /** The checker algorithm decided that this process 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 isDisabled() const { return this->state == InterleavingType::disabled; }
82 bool isDone() const { return this->state == InterleavingType::done; }
83 bool isTodo() 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 setDone() { this->state = InterleavingType::done; }
93 /* A node in the exploration graph (kind-of)
95 class XBT_PRIVATE State {
97 /** Sequential state number (used for debugging) */
100 /** State's exploration status by process */
101 std::vector<ProcessState> actorStates;
103 Transition transition;
105 /** The simcall which was executed, going out of that state */
106 s_smx_simcall executed_req;
108 /* Internal translation of the executed_req simcall
110 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
111 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
113 s_smx_simcall internal_req;
115 /* Can be used as a copy of the remote synchro object */
116 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> internal_comm;
118 /** Snapshot of system state (if needed) */
119 std::shared_ptr<simgrid::mc::Snapshot> system_state;
121 // For CommunicationDeterminismChecker
122 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
123 std::vector<unsigned> communicationIndices;
125 explicit State(unsigned long state_number);
127 std::size_t interleaveSize() const;
128 void addInterleavingSet(smx_actor_t actor) { this->actorStates[actor->get_pid()].consider(); }
129 Transition getTransition() const;
134 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);