Logo AND Algorithmique Numérique Distribuée

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