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 /* An exploration state.
108 * The `executed_state` is sometimes transformed into another `internal_req`.
109 * For example WAITANY is transformes into a WAIT and TESTANY into TEST.
110 * See `MC_state_get_request_for_process()`.
112 struct XBT_PRIVATE State {
114 /** Sequential state number (used for debugging) */
117 /* Next transition to explore for this communication
119 * Some transitions are not deterministic such as:
121 * * waitany which can receive different messages;
123 * * random which can produce different values.
125 * This variable is used to keep track of which transition
126 * should be explored next for a given simcall.
130 /** State's exploration status by process */
131 std::vector<ProcessState> processStates;
134 s_smx_simcall_t executed_req;
136 /* Internal translation of the simcall
138 * IMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
139 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
141 s_smx_simcall_t internal_req;
143 /* Can be used as a copy of the remote synchro object */
144 s_smx_synchro_t internal_comm;
146 /** Snapshot of system state (if needed) */
147 std::shared_ptr<simgrid::mc::Snapshot> system_state;
149 // For CommunicationDeterminismChecker
150 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
151 std::vector<unsigned> communicationIndices;
155 std::size_t interleaveSize() const;
156 void interleave(smx_process_t process)
158 this->processStates[process->pid].interleave();
160 RecordTraceElement getRecordElement() const;
163 XBT_PRIVATE void replay(std::list<std::unique_ptr<simgrid::mc::State>> const& stack);
168 XBT_PRIVATE simgrid::mc::State* MC_state_new(void);
169 XBT_PRIVATE smx_simcall_t MC_state_get_executed_request(simgrid::mc::State* state, int *value);
170 XBT_PRIVATE smx_simcall_t MC_state_get_internal_request(simgrid::mc::State* state);
171 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state, int *value);