Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Welcome to modernity
[simgrid.git] / src / mc / mc_smx.cpp
1 /* Copyright (c) 2015-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 #include "simgrid/s4u/Host.hpp"
7
8 #include "src/mc/ModelChecker.hpp"
9 #include "src/mc/mc_smx.hpp"
10
11 using simgrid::mc::remote;
12
13 /** Load the remote list of processes into a vector
14  *
15  *  @param process      MCed process
16  *  @param target       Local vector (to be filled with copies of `s_smx_actor_t`)
17  *  @param remote_dynar Address of the process dynar in the remote list
18  */
19 static void MC_process_refresh_simix_actor_dynar(const simgrid::mc::RemoteSimulation* process,
20                                                  std::vector<simgrid::mc::ActorInformation>& target,
21                                                  simgrid::mc::RemotePtr<s_xbt_dynar_t> remote_dynar)
22 {
23   target.clear();
24
25   s_xbt_dynar_t dynar;
26   process->read_bytes(&dynar, sizeof(dynar), remote_dynar);
27
28   auto* data = static_cast<smx_actor_t*>(::operator new(dynar.elmsize * dynar.used));
29   process->read_bytes(data, dynar.elmsize * dynar.used, simgrid::mc::RemotePtr<void>(dynar.data));
30
31   // Load each element of the vector from the MCed process:
32   for (unsigned int i = 0; i < dynar.used; ++i) {
33     simgrid::mc::ActorInformation info;
34
35     info.address  = simgrid::mc::RemotePtr<simgrid::kernel::actor::ActorImpl>(data[i]);
36     info.hostname = nullptr;
37     process->read_bytes(&info.copy, sizeof(info.copy), remote(data[i]));
38     target.push_back(std::move(info));
39   }
40   ::operator delete(data);
41 }
42 namespace simgrid {
43 namespace mc {
44
45 void RemoteSimulation::refresh_simix()
46 {
47   if (this->cache_flags_ & RemoteSimulation::cache_simix_processes)
48     return;
49
50   // TODO, avoid to reload `&simix_global`, `simix_global`, `*simix_global`
51
52   static_assert(std::is_same<
53       std::unique_ptr<simgrid::simix::Global>,
54       decltype(simix_global)
55     >::value, "Unexpected type for simix_global");
56   static_assert(sizeof(simix_global) == sizeof(simgrid::simix::Global*),
57     "Bad size for simix_global");
58
59   RemotePtr<simgrid::simix::Global> simix_global_p{this->read_variable<simgrid::simix::Global*>("simix_global")};
60
61   // simix_global = REMOTE(*simix_global)
62   Remote<simgrid::simix::Global> simix_global =
63     this->read<simgrid::simix::Global>(simix_global_p);
64
65   MC_process_refresh_simix_actor_dynar(this, this->smx_actors_infos, remote(simix_global.get_buffer()->actors_vector));
66   MC_process_refresh_simix_actor_dynar(this, this->smx_dead_actors_infos,
67                                        remote(simix_global.get_buffer()->dead_actors_vector));
68
69   this->cache_flags_ |= RemoteSimulation::cache_simix_processes;
70 }
71
72 }
73 }
74
75 unsigned long MC_smx_get_maxpid()
76 {
77   unsigned long maxpid;
78   const char* name = "simgrid::kernel::actor::maxpid";
79   if (mc_model_checker->get_remote_simulation().find_variable(name) == nullptr)
80     name = "maxpid"; // We seem to miss the namespaces when compiling with GCC
81   mc_model_checker->get_remote_simulation().read_variable(name, &maxpid, sizeof(maxpid));
82   return maxpid;
83 }