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/kernel/activity/SynchroIo.hpp"
19 #include "src/kernel/activity/SynchroComm.hpp"
20 #include "src/kernel/activity/SynchroRaw.hpp"
21 #include "src/kernel/activity/SynchroSleep.hpp"
22 #include "src/kernel/activity/SynchroExec.hpp"
23 #include "src/mc/mc_snapshot.h"
24 #include "src/mc/mc_record.h"
25 #include "src/mc/Transition.hpp"
30 enum class PatternCommunicationType {
36 struct PatternCommunication {
38 smx_activity_t comm_addr;
39 PatternCommunicationType type = PatternCommunicationType::send;
40 unsigned long src_proc = 0;
41 unsigned long dst_proc = 0;
42 const char *src_host = nullptr;
43 const char *dst_host = nullptr;
45 std::vector<char> data;
49 PatternCommunication()
51 std::memset(&comm_addr, 0, sizeof(comm_addr));
54 PatternCommunication dup() const
56 simgrid::mc::PatternCommunication res;
58 res.comm_addr = this->comm_addr;
59 res.type = this->type;
62 res.dst_proc = this->dst_proc;
63 res.dst_host = this->dst_host;
65 res.data = this->data;
67 res.index = this->index;
73 /* On every state, each process has an entry of the following type */
75 /* Possible exploration status of a process in a state */
76 enum class InterleavingType {
77 /** We do not have to execute this process transitions */
79 /** We still have to execute (some of) this process transitions */
81 /** We have already executed this process transitions */
85 /** Exploration control information */
86 InterleavingType state = InterleavingType::disabled;
89 /** Number of times that the process was interleaved */
90 // TODO, make this private
91 unsigned int interleave_count = 0;
93 bool isDisabled() const
95 return this->state == InterleavingType::disabled;
99 return this->state == InterleavingType::done;
101 bool isToInterleave() const
103 return this->state == InterleavingType::interleave;
107 this->state = InterleavingType::interleave;
108 this->interleave_count = 0;
112 this->state = InterleavingType::done;
116 /* A node in the exploration graph (kind-of)
118 struct XBT_PRIVATE State {
120 /** Sequential state number (used for debugging) */
123 /** State's exploration status by process */
124 std::vector<ProcessState> processStates;
126 Transition transition;
128 /** The simcall which was executed */
129 s_smx_simcall_t executed_req;
131 /* Internal translation of the simcall
133 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
134 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
136 s_smx_simcall_t internal_req;
138 /* Can be used as a copy of the remote synchro object */
139 simgrid::mc::Remote<simgrid::kernel::activity::Comm> internal_comm;
141 /** Snapshot of system state (if needed) */
142 std::shared_ptr<simgrid::mc::Snapshot> system_state;
144 // For CommunicationDeterminismChecker
145 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
146 std::vector<unsigned> communicationIndices;
150 std::size_t interleaveSize() const;
151 void interleave(smx_process_t process)
153 this->processStates[process->pid].interleave();
155 Transition getTransition() const;
161 XBT_PRIVATE simgrid::mc::State* MC_state_new(unsigned long state_number);
162 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);