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/mc/mc_snapshot.h"
23 extern XBT_PRIVATE std::unique_ptr<s_mc_global_t> initial_global_state;
25 struct PatternCommunication {
27 smx_synchro_t comm_addr;
28 e_smx_comm_type_t type = SIMIX_COMM_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;
34 std::vector<char> data;
38 PatternCommunication()
40 std::memset(&comm_addr, 0, sizeof(comm_addr));
43 PatternCommunication dup() const
45 simgrid::mc::PatternCommunication res;
47 res.comm_addr = this->comm_addr;
48 res.type = this->type;
51 res.dst_proc = this->dst_proc;
52 res.dst_host = this->dst_host;
54 res.data = this->data;
56 res.index = this->index;
62 /* Possible exploration status of a process in a state */
63 enum class ProcessInterleaveState {
64 no_interleave=0, /* Do not interleave (do not execute) */
65 interleave, /* Interleave the process (one or more request) */
66 more_interleave, /* Interleave twice the process (for mc_random simcall) */
67 done /* Already interleaved */
70 /* On every state, each process has an entry of the following type */
72 /** Exploration control information */
73 ProcessInterleaveState state = ProcessInterleaveState::no_interleave;
74 /** Number of times that the process was interleaved */
75 unsigned int interleave_count;
79 return this->state == ProcessInterleaveState::done;
81 bool interleave() const {
82 return this->state == ProcessInterleaveState::interleave
83 || this->state == ProcessInterleaveState::more_interleave;
87 /* An exploration state.
89 * The `executed_state` is sometimes transformed into another `internal_req`.
90 * For example WAITANY is transformes into a WAIT and TESTANY into TEST.
91 * See `MC_state_set_executed_request()`.
93 struct XBT_PRIVATE State {
94 /** State's exploration status by process */
95 std::vector<ProcessState> processStates;
96 s_smx_synchro_t internal_comm; /* To be referenced by the internal_req */
97 s_smx_simcall_t internal_req; /* Internal translation of request */
98 s_smx_simcall_t executed_req; /* The executed request of the state */
99 int req_num = 0; /* The request number (in the case of a
100 multi-request like waitany ) */
101 std::shared_ptr<simgrid::mc::Snapshot> system_state = nullptr; /* Snapshot of system state */
103 int in_visited_states = 0;
105 // comm determinism verification (xbt_dynar_t<xbt_dynar_t<simgrid::mc::PatternCommunication*>):
106 std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern;
108 // For communication determinism verification:
109 std::vector<unsigned> communicationIndices;
113 std::size_t interleaveSize() const;
116 XBT_PRIVATE void replay(std::list<std::unique_ptr<simgrid::mc::State>> const& stack);
121 XBT_PRIVATE simgrid::mc::State* MC_state_new(void);
122 XBT_PRIVATE void MC_state_interleave_process(simgrid::mc::State* state, smx_process_t process);
123 XBT_PRIVATE void MC_state_set_executed_request(simgrid::mc::State* state, smx_simcall_t req, int value);
124 XBT_PRIVATE smx_simcall_t MC_state_get_executed_request(simgrid::mc::State* state, int *value);
125 XBT_PRIVATE smx_simcall_t MC_state_get_internal_request(simgrid::mc::State* state);
126 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state, int *value);
127 XBT_PRIVATE void MC_state_remove_interleave_process(simgrid::mc::State* state, smx_process_t process);