1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_STATE_H
8 #define SIMGRID_MC_STATE_H
14 #include <xbt/dynar.h>
16 #include <simgrid_config.h>
17 #include "src/simix/smx_private.h"
18 #include "src/mc/mc_snapshot.h"
19 #include "src/mc/mc_record.h"
24 extern XBT_PRIVATE std::unique_ptr<s_mc_global_t> initial_global_state;
26 struct PatternCommunication {
28 smx_synchro_t comm_addr;
29 e_smx_comm_type_t type = SIMIX_COMM_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()
41 std::memset(&comm_addr, 0, sizeof(comm_addr));
44 PatternCommunication dup() const
46 simgrid::mc::PatternCommunication res;
48 res.comm_addr = this->comm_addr;
49 res.type = this->type;
52 res.dst_proc = this->dst_proc;
53 res.dst_host = this->dst_host;
55 res.data = this->data;
57 res.index = this->index;
63 /* On every state, each process has an entry of the following type */
65 /* Possible exploration status of a process in a state */
66 enum class InterleavingType {
67 /** We do not have to execute this process transitions */
69 /** We still have to execute (some of) this process transitions */
71 /** We have already executed this process transitions */
75 /** Exploration control information */
76 InterleavingType state = InterleavingType::disabled;
79 /** Number of times that the process was interleaved */
80 // TODO, make this private
81 unsigned int interleave_count = 0;
83 bool isDisabled() const
85 return this->state == InterleavingType::disabled;
89 return this->state == InterleavingType::done;
91 bool isToInterleave() const
93 return this->state == InterleavingType::interleave;
97 this->state = InterleavingType::interleave;
98 this->interleave_count = 0;
102 this->state = InterleavingType::done;
106 /* A node in the exploration graph (kind-of)
108 struct XBT_PRIVATE State {
110 /** Sequential state number (used for debugging) */
113 /* Which transition was executed for this simcall
115 * Some simcalls can lead to different transitions:
117 * * waitany/testany can trigger on different messages;
119 * * random can produce different values.
123 /** State's exploration status by process */
124 std::vector<ProcessState> processStates;
126 /** The simcall which was executed */
127 s_smx_simcall_t executed_req;
129 /* Internal translation of the simcall
131 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
132 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
134 s_smx_simcall_t internal_req;
136 /* Can be used as a copy of the remote synchro object */
137 s_smx_synchro_t internal_comm;
139 /** Snapshot of system state (if needed) */
140 std::shared_ptr<simgrid::mc::Snapshot> system_state;
142 // For CommunicationDeterminismChecker
143 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
144 std::vector<unsigned> communicationIndices;
148 std::size_t interleaveSize() const;
149 void interleave(smx_process_t process)
151 this->processStates[process->pid].interleave();
153 RecordTraceElement getRecordElement() const;
156 XBT_PRIVATE void replay(std::list<std::unique_ptr<simgrid::mc::State>> const& stack);
161 XBT_PRIVATE simgrid::mc::State* MC_state_new(void);
162 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);