Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ok, I stop trying to please sonar.
[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 <xbt/base.h>
13 #include <xbt/dynar.h>
14
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"
25
26 namespace simgrid {
27 namespace mc {
28
29 enum class PatternCommunicationType {
30   none = 0,
31   send = 1,
32   receive = 2,
33 };
34
35 struct PatternCommunication {
36   int num = 0;
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;
43   std::string rdv;
44   std::vector<char> data;
45   int tag = 0;
46   int index = 0;
47
48   PatternCommunication()
49   {
50     std::memset(&comm_addr, 0, sizeof(comm_addr));
51   }
52
53   PatternCommunication dup() const
54   {
55     simgrid::mc::PatternCommunication res;
56     // num?
57     res.comm_addr = this->comm_addr;
58     res.type = this->type;
59     // src_proc?
60     // dst_proc?
61     res.dst_proc = this->dst_proc;
62     res.dst_host = this->dst_host;
63     res.rdv = this->rdv;
64     res.data = this->data;
65     // tag?
66     res.index = this->index;
67     return res;
68   }
69
70 };
71
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.
75  */
76 class ProcessState {
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.
79    */
80   enum class InterleavingType {
81     /** This process transition is not considered by the checker (yet?) */
82     disabled = 0,
83     /** The checker algorithm decided that this process transitions should be done at some point */
84     todo,
85     /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
86     done,
87   };
88
89   /** Exploration control information */
90   InterleavingType state = InterleavingType::disabled;
91 public:
92   /** Number of times that the process was considered to be executed */
93   // TODO, make this private
94   unsigned int times_considered = 0;
95
96   bool isDisabled() const {
97     return this->state == InterleavingType::disabled;
98   }
99   bool isDone() const {
100     return this->state == InterleavingType::done;
101   }
102   bool isTodo() const {
103     return this->state == InterleavingType::todo;
104   }
105   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
106   void consider() {
107     this->state            = InterleavingType::todo;
108     this->times_considered = 0;
109   }
110   void setDone() {
111     this->state = InterleavingType::done;
112   }
113 };
114
115 /* A node in the exploration graph (kind-of)
116  */
117 struct XBT_PRIVATE State {
118
119   /** Sequential state number (used for debugging) */
120   int num = 0;
121
122   /** State's exploration status by process */
123   std::vector<ProcessState> actorStates;
124
125   Transition transition;
126
127   /** The simcall which was executed, going out of that state */
128   s_smx_simcall_t executed_req;
129
130   /* Internal translation of the executed_req simcall
131    *
132    * SIMCALL_COMM_TESTANY is translated to a SIMCALL_COMM_TEST
133    * and SIMCALL_COMM_WAITANY to a SIMCALL_COMM_WAIT.
134    */
135   s_smx_simcall_t internal_req;
136
137   /* Can be used as a copy of the remote synchro object */
138   simgrid::mc::Remote<simgrid::kernel::activity::Comm> internal_comm;
139
140   /** Snapshot of system state (if needed) */
141   std::shared_ptr<simgrid::mc::Snapshot> system_state;
142
143   // For CommunicationDeterminismChecker
144   std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
145   std::vector<unsigned> communicationIndices;
146
147   State(unsigned long state_number);
148
149   std::size_t interleaveSize() const;
150   void interleave(smx_actor_t actor) {
151     this->actorStates[actor->pid].consider();
152   }
153   Transition getTransition() const;
154 };
155
156 }
157 }
158
159 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state);
160
161 #endif