1 /* Copyright (c) 2015-2021. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u/Host.hpp"
8 #include "src/mc/ModelChecker.hpp"
9 #include "src/mc/mc_smx.hpp"
11 using simgrid::mc::remote;
13 /** Load the remote list of processes into a vector
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
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)
26 process->read_bytes(&dynar, sizeof(dynar), remote_dynar);
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));
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;
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));
40 ::operator delete(data);
45 void RemoteSimulation::refresh_simix()
47 if (this->cache_flags_ & RemoteSimulation::cache_simix_processes)
50 // TODO, avoid to reload `&simix_global`, `simix_global`, `*simix_global`
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");
59 RemotePtr<simgrid::simix::Global> simix_global_p{this->read_variable<simgrid::simix::Global*>("simix_global")};
61 // simix_global = REMOTE(*simix_global)
62 Remote<simgrid::simix::Global> simix_global =
63 this->read<simgrid::simix::Global>(simix_global_p);
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));
69 this->cache_flags_ |= RemoteSimulation::cache_simix_processes;
75 unsigned long MC_smx_get_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));