Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #181 from bcamus/master
[simgrid.git] / src / mc / mc_state.h
1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_STATE_H
7 #define SIMGRID_MC_STATE_H
8
9 #include <list>
10 #include <memory>
11
12 #include "src/mc/mc_snapshot.h"
13 #include "src/mc/mc_record.h"
14 #include "src/mc/Transition.hpp"
15
16 namespace simgrid {
17 namespace mc {
18
19 enum class PatternCommunicationType {
20   none = 0,
21   send = 1,
22   receive = 2,
23 };
24
25 struct PatternCommunication {
26   int num = 0;
27   simgrid::kernel::activity::CommImpl* comm_addr;
28   PatternCommunicationType type = PatternCommunicationType::send;
29   unsigned long src_proc = 0;
30   unsigned long dst_proc = 0;
31   const char *src_host = nullptr;
32   const char *dst_host = nullptr;
33   std::string rdv;
34   std::vector<char> data;
35   int tag = 0;
36   int index = 0;
37
38   PatternCommunication()
39   {
40     std::memset(&comm_addr, 0, sizeof(comm_addr));
41   }
42
43   PatternCommunication dup() const
44   {
45     simgrid::mc::PatternCommunication res;
46     // num?
47     res.comm_addr = this->comm_addr;
48     res.type = this->type;
49     // src_proc?
50     // dst_proc?
51     res.dst_proc = this->dst_proc;
52     res.dst_host = this->dst_host;
53     res.rdv = this->rdv;
54     res.data = this->data;
55     // tag?
56     res.index = this->index;
57     return res;
58   }
59
60 };
61
62 /* On every state, each process has an entry of the following type.
63  * This represents both the process and its transition because
64  *   a process cannot have more than one enabled transition at a given time.
65  */
66 class ProcessState {
67   /* Possible exploration status of a process transition in a state.
68    * Either the checker did not consider the transition, or it was considered and to do, or considered and done.
69    */
70   enum class InterleavingType {
71     /** This process transition is not considered by the checker (yet?) */
72     disabled = 0,
73     /** The checker algorithm decided that this process transitions should be done at some point */
74     todo,
75     /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
76     done,
77   };
78
79   /** Exploration control information */
80   InterleavingType state = InterleavingType::disabled;
81 public:
82   /** Number of times that the process was considered to be executed */
83   // TODO, make this private
84   unsigned int times_considered = 0;
85
86   bool isDisabled() const {
87     return this->state == InterleavingType::disabled;
88   }
89   bool isDone() const {
90     return this->state == InterleavingType::done;
91   }
92   bool isTodo() const {
93     return this->state == InterleavingType::todo;
94   }
95   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
96   void consider() {
97     this->state            = InterleavingType::todo;
98     this->times_considered = 0;
99   }
100   void setDone() {
101     this->state = InterleavingType::done;
102   }
103 };
104
105 /* A node in the exploration graph (kind-of)
106  */
107 struct XBT_PRIVATE State {
108
109   /** Sequential state number (used for debugging) */
110   int num = 0;
111
112   /** State's exploration status by process */
113   std::vector<ProcessState> actorStates;
114
115   Transition transition;
116
117   /** The simcall which was executed, going out of that state */
118   s_smx_simcall_t executed_req;
119
120   /* Internal translation of the executed_req simcall
121    *
122    * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
123    * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
124    */
125   s_smx_simcall_t internal_req;
126
127   /* Can be used as a copy of the remote synchro object */
128   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> internal_comm;
129
130   /** Snapshot of system state (if needed) */
131   std::shared_ptr<simgrid::mc::Snapshot> system_state;
132
133   // For CommunicationDeterminismChecker
134   std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
135   std::vector<unsigned> communicationIndices;
136
137   State(unsigned long state_number);
138
139   std::size_t interleaveSize() const;
140   void addInterleavingSet(smx_actor_t actor) { this->actorStates[actor->pid].consider(); }
141   Transition getTransition() const;
142 };
143
144 }
145 }
146
147 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);
148
149 #endif