Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify
[simgrid.git] / src / mc / api.hpp
1 /* Copyright (c) 2020-2021. 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_API_HPP
7 #define SIMGRID_MC_API_HPP
8
9 #include <memory>
10 #include <vector>
11
12 #include "simgrid/forward.h"
13 #include "src/mc/mc_forward.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/mc_state.hpp"
16 #include "xbt/automaton.hpp"
17 #include "xbt/base.h"
18
19 namespace simgrid {
20 namespace mc {
21
22 XBT_DECLARE_ENUM_CLASS(CheckerAlgorithm, Safety, UDPOR, Liveness, CommDeterminism);
23
24 /**
25  * @brief Maintains the transition's information.
26  */
27 struct s_transition_detail {
28   simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE;
29   long issuer_id                = -1;
30   RemotePtr<kernel::activity::MailboxImpl> mbox_remote_addr {}; // used to represent mailbox remote address for isend and ireceive transitions
31   RemotePtr<kernel::activity::ActivityImpl> comm_remote_addr {}; // the communication this transition concerns (to be used only for isend, ireceive, wait and test)
32 };
33
34 using transition_detail_t = std::unique_ptr<s_transition_detail>;
35
36 /*
37 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
38 ** (Unfolding_Checker, DPOR, ...) layer and the
39 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
40 ** detailes in a way that the CheckerSide eventually
41 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
42 */
43
44 class Api {
45 private:
46   Api() = default;
47
48   struct DerefAndCompareByActorsCountAndUsedHeap {
49     template <class X, class Y> bool operator()(X const& a, Y const& b) const
50     {
51       return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used);
52     }
53   };
54
55   simgrid::kernel::activity::CommImpl* get_comm_or_nullptr(smx_simcall_t const r) const;
56   bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const;
57   simgrid::mc::ActorInformation* actor_info_cast(smx_actor_t actor) const;
58   std::string get_actor_string(smx_actor_t actor) const;
59   std::string get_actor_dot_label(smx_actor_t actor) const;
60
61 public:
62   // No copy:
63   Api(Api const&) = delete;
64   void operator=(Api const&) = delete;
65
66   static Api& get()
67   {
68     static Api api;
69     return api;
70   }
71
72   simgrid::mc::Checker* initialize(char** argv, simgrid::mc::CheckerAlgorithm algo) const;
73
74   // ACTOR APIs
75   std::vector<simgrid::mc::ActorInformation>& get_actors() const;
76   unsigned long get_maxpid() const;
77   int get_actors_size() const;
78
79   // COMMUNICATION APIs
80   RemotePtr<kernel::activity::CommImpl> get_comm_isend_raw_addr(smx_simcall_t request) const;
81   RemotePtr<kernel::activity::CommImpl> get_comm_waitany_raw_addr(smx_simcall_t request, int value) const;
82   std::string get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const;
83   unsigned long get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
84   unsigned long get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
85   std::vector<char> get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const;
86   xbt::string const& get_actor_name(smx_actor_t actor) const;
87   xbt::string const& get_actor_host_name(smx_actor_t actor) const;
88 #if HAVE_SMPI
89   bool check_send_request_detached(smx_simcall_t const& simcall) const;
90 #endif
91   smx_actor_t get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
92   smx_actor_t get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
93
94   // REMOTE APIs
95   std::size_t get_remote_heap_bytes() const;
96
97   // MODEL CHECKER APIs
98   void mc_inc_visited_states() const;
99   void mc_inc_executed_trans() const;
100   unsigned long mc_get_visited_states() const;
101   unsigned long mc_get_executed_trans() const;
102   void mc_check_deadlock() const;
103   bool mc_is_null() const;
104   Checker* mc_get_checker() const;
105   void handle_simcall(Transition const& transition) const;
106   void mc_wait_for_requests() const;
107   XBT_ATTRIB_NORETURN void mc_exit(int status) const;
108   void dump_record_path() const;
109   smx_simcall_t mc_state_choose_request(simgrid::mc::State* state) const;
110
111   // UDPOR APIs
112   std::list<transition_detail_t> get_enabled_transitions(simgrid::mc::State* state) const;
113
114   // SIMCALL APIs
115   std::string request_to_string(smx_simcall_t req, int value) const;
116   std::string request_get_dot_output(smx_simcall_t req, int value) const;
117   smx_actor_t simcall_get_issuer(s_smx_simcall const* req) const;
118   long simcall_get_actor_id(s_smx_simcall const* req) const;
119   RemotePtr<kernel::activity::MailboxImpl> get_mbox_remote_addr(smx_simcall_t const req) const;
120   RemotePtr<kernel::activity::ActivityImpl> get_comm_remote_addr(smx_simcall_t const req) const;
121   bool simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const;
122
123 #if HAVE_SMPI
124   int get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const;
125 #endif
126
127   // STATE APIs
128   void restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const;
129   void log_state() const;
130
131   // SNAPSHOT APIs
132   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
133   simgrid::mc::Snapshot* take_snapshot(int num_state) const;
134
135   // SESSION APIs
136   void s_close() const;
137   void execute(Transition& transition, smx_simcall_t simcall) const;
138
139 // AUTOMATION APIs
140 #if SIMGRID_HAVE_MC
141   void automaton_load(const char* file) const;
142 #endif
143   std::vector<int> automaton_propositional_symbol_evaluate() const;
144   std::vector<xbt_automaton_state_t> get_automaton_state() const;
145   int compare_automaton_exp_label(const xbt_automaton_exp_label* l) const;
146   void set_property_automaton(xbt_automaton_state_t const& automaton_state) const;
147   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const
148   {
149     return DerefAndCompareByActorsCountAndUsedHeap();
150   }
151   inline int automaton_state_compare(const_xbt_automaton_state_t const& s1, const_xbt_automaton_state_t const& s2) const
152   {
153     return xbt_automaton_state_compare(s1, s2);
154   }
155   xbt_automaton_exp_label_t get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const;
156   xbt_automaton_state_t get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const;
157
158   // DYNAR APIs
159   inline unsigned long get_dynar_length(const_xbt_dynar_t const& dynar) const { return xbt_dynar_length(dynar); }
160 };
161
162 } // namespace mc
163 } // namespace simgrid
164
165 #endif