Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
94c72013d6e1c787ec4bc79ea0484c43dbf4a671
[simgrid.git] / src / mc / mc_state.h
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMGRID_MC_STATE_H
8 #define SIMGRID_MC_STATE_H
9
10 #include <list>
11 #include <memory>
12
13 #include <xbt/base.h>
14 #include <xbt/dynar.h>
15
16 #include <simgrid_config.h>
17 #include "src/simix/smx_private.h"
18 #include "src/mc/mc_snapshot.h"
19
20 /* Possible exploration status of a process in a state */
21 typedef enum {
22   MC_NOT_INTERLEAVE=0,      /* Do not interleave (do not execute) */
23   MC_INTERLEAVE,            /* Interleave the process (one or more request) */
24   MC_MORE_INTERLEAVE,       /* Interleave twice the process (for mc_random simcall) */
25   MC_DONE                   /* Already interleaved */
26 } e_mc_process_state_t;
27
28 /* On every state, each process has an entry of the following type */
29 typedef struct mc_procstate{
30   e_mc_process_state_t state;       /* Exploration control information */
31   unsigned int interleave_count;    /* Number of times that the process was
32                                        interleaved */
33 } s_mc_procstate_t, *mc_procstate_t;
34
35 namespace simgrid {
36 namespace mc {
37
38 extern XBT_PRIVATE std::unique_ptr<s_mc_global_t> initial_global_state;
39
40 /* An exploration state.
41  *
42  *  The `executed_state` is sometimes transformed into another `internal_req`.
43  *  For example WAITANY is transformes into a WAIT and TESTANY into TEST.
44  *  See `MC_state_set_executed_request()`.
45  */
46 struct XBT_PRIVATE State {
47   unsigned long max_pid = 0;            /* Maximum pid at state's creation time */
48   mc_procstate_t proc_status = 0;       /* State's exploration status by process */
49   s_smx_synchro_t internal_comm;     /* To be referenced by the internal_req */
50   s_smx_simcall_t internal_req;         /* Internal translation of request */
51   s_smx_simcall_t executed_req;         /* The executed request of the state */
52   int req_num = 0;                      /* The request number (in the case of a
53                                        multi-request like waitany ) */
54   std::shared_ptr<simgrid::mc::Snapshot> system_state = nullptr;      /* Snapshot of system state */
55   int num = 0;
56   int in_visited_states = 0;
57   // comm determinism verification (xbt_dynar_t<xbt_dynar_t<mc_comm_pattern_t>):
58   xbt_dynar_t incomplete_comm_pattern = nullptr;
59   xbt_dynar_t index_comm = nullptr; // comm determinism verification
60
61   State();
62   ~State();
63 };
64
65 XBT_PRIVATE void replay(std::list<std::unique_ptr<simgrid::mc::State>> const& stack);
66
67 }
68 }
69
70 XBT_PRIVATE simgrid::mc::State* MC_state_new(void);
71 XBT_PRIVATE void MC_state_delete(simgrid::mc::State* state, int free_snapshot);
72 XBT_PRIVATE void MC_state_interleave_process(simgrid::mc::State* state, smx_process_t process);
73 XBT_PRIVATE unsigned int MC_state_interleave_size(simgrid::mc::State* state);
74 XBT_PRIVATE int MC_state_process_is_done(simgrid::mc::State* state, smx_process_t process);
75 XBT_PRIVATE void MC_state_set_executed_request(simgrid::mc::State* state, smx_simcall_t req, int value);
76 XBT_PRIVATE smx_simcall_t MC_state_get_executed_request(simgrid::mc::State* state, int *value);
77 XBT_PRIVATE smx_simcall_t MC_state_get_internal_request(simgrid::mc::State* state);
78 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state, int *value);
79 XBT_PRIVATE void MC_state_remove_interleave_process(simgrid::mc::State* state, smx_process_t process);
80
81 #endif