1 /* Copyright (c) 2007-2017. 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_H
7 #define SIMGRID_MC_STATE_H
13 #include <xbt/dynar.h>
15 #include <simgrid_config.h>
16 #include "src/simix/smx_private.h"
17 #include "src/kernel/activity/SynchroIo.hpp"
18 #include "src/kernel/activity/SynchroComm.hpp"
19 #include "src/kernel/activity/SynchroRaw.hpp"
20 #include "src/kernel/activity/SynchroSleep.hpp"
21 #include "src/kernel/activity/SynchroExec.hpp"
22 #include "src/mc/mc_snapshot.h"
23 #include "src/mc/mc_record.h"
24 #include "src/mc/Transition.hpp"
29 enum class PatternCommunicationType {
35 struct PatternCommunication {
37 smx_activity_t comm_addr;
38 PatternCommunicationType type = PatternCommunicationType::send;
39 unsigned long src_proc = 0;
40 unsigned long dst_proc = 0;
41 const char *src_host = nullptr;
42 const char *dst_host = nullptr;
44 std::vector<char> data;
48 PatternCommunication()
50 std::memset(&comm_addr, 0, sizeof(comm_addr));
53 PatternCommunication dup() const
55 simgrid::mc::PatternCommunication res;
57 res.comm_addr = this->comm_addr;
58 res.type = this->type;
61 res.dst_proc = this->dst_proc;
62 res.dst_host = this->dst_host;
64 res.data = this->data;
66 res.index = this->index;
72 /* On every state, each process has an entry of the following type.
73 * This represents both the process and its transition because
74 * a process cannot have more than one enabled transition at a given time.
77 /* Possible exploration status of a process transition in a state.
78 * Either the checker did not consider the transition, or it was considered and to do, or considered and done.
80 enum class InterleavingType {
81 /** This process transition is not considered by the checker (yet?) */
83 /** The checker algorithm decided that this process transitions should be done at some point */
85 /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
89 /** Exploration control information */
90 InterleavingType state = InterleavingType::disabled;
92 /** Number of times that the process was considered to be executed */
93 // TODO, make this private
94 unsigned int times_considered = 0;
96 bool isDisabled() const {
97 return this->state == InterleavingType::disabled;
100 return this->state == InterleavingType::done;
102 bool isTodo() const {
103 return this->state == InterleavingType::todo;
105 /** Mark that we should try executing this process at some point in the future of the checker algorithm */
107 this->state = InterleavingType::todo;
108 this->times_considered = 0;
111 this->state = InterleavingType::done;
115 /* A node in the exploration graph (kind-of)
117 struct XBT_PRIVATE State {
119 /** Sequential state number (used for debugging) */
122 /** State's exploration status by process */
123 std::vector<ProcessState> actorStates;
125 Transition transition;
127 /** The simcall which was executed, going out of that state */
128 s_smx_simcall_t executed_req;
130 /* Internal translation of the executed_req simcall
132 * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
133 * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
135 s_smx_simcall_t internal_req;
137 /* Can be used as a copy of the remote synchro object */
138 simgrid::mc::Remote<simgrid::kernel::activity::Comm> internal_comm;
140 /** Snapshot of system state (if needed) */
141 std::shared_ptr<simgrid::mc::Snapshot> system_state;
143 // For CommunicationDeterminismChecker
144 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
145 std::vector<unsigned> communicationIndices;
147 State(unsigned long state_number);
149 std::size_t interleaveSize() const;
150 void interleave(smx_actor_t actor) {
151 this->actorStates[actor->pid].consider();
153 Transition getTransition() const;
159 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);