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.
74 * This represents both the process and its transition because
75 * a process cannot have more than one enabled transition at a given time.
78 /* Possible exploration status of a process transition in a state.
79 * Either the checker did not consider the transition, or it was considered and to do, or considered and done.
81 enum class InterleavingType {
82 /** This process transition is not considered by the checker (yet?) */
84 /** The checker algorithm decided that this process transitions should be done at some point */
86 /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
90 /** Exploration control information */
91 InterleavingType state = InterleavingType::disabled;
93 /** Number of times that the process was considered to be executed */
94 // TODO, make this private
95 unsigned int times_considered = 0;
97 bool isDisabled() const {
98 return this->state == InterleavingType::disabled;
100 bool isDone() const {
101 return this->state == InterleavingType::done;
103 bool isTodo() const {
104 return this->state == InterleavingType::todo;
106 /** Mark that we should try executing this process at some point in the future of the checker algorithm */
108 this->state = InterleavingType::todo;
109 this->times_considered = 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> actorStates;
126 Transition transition;
128 /** The simcall which was executed, going out of that state */
129 s_smx_simcall_t executed_req;
131 /* Internal translation of the executed_req 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;
148 State(unsigned long state_number);
150 std::size_t interleaveSize() const;
151 void interleave(smx_actor_t actor) {
152 this->actorStates[actor->pid].consider();
154 Transition getTransition() const;
160 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);