3 #include "src/kernel/activity/MailboxImpl.hpp"
4 #include "src/kernel/activity/MutexImpl.hpp"
5 #include "src/mc/Session.hpp"
6 #include "src/mc/checker/SimcallObserver.hpp"
7 #include "src/mc/mc_comm_pattern.hpp"
8 #include "src/mc/mc_exit.hpp"
9 #include "src/mc/mc_pattern.hpp"
10 #include "src/mc/mc_private.hpp"
11 #include "src/mc/remote/RemoteSimulation.hpp"
13 #include <xbt/asserts.h>
15 #include "simgrid/s4u/Host.hpp"
16 #include "xbt/string.hpp"
18 #include "src/smpi/include/smpi_request.hpp"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Facade APIs ");
23 using Simcall = simgrid::simix::Simcall;
28 static inline const char* get_color(int id)
30 static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
31 "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
33 return colors[id % colors.size()];
36 static std::string pointer_to_string(void* pointer)
38 return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? xbt::string_printf("%p", pointer) : "(verbose only)";
41 static std::string buff_size_to_string(size_t buff_size)
43 return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? std::to_string(buff_size) : "(verbose only)";
46 static void simcall_translate(smx_simcall_t req,
47 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl>& buffered_comm);
49 /* Search an enabled transition for the given process.
51 * This can be seen as an iterator returning the next transition of the process.
53 * We only consider the processes that are both
54 * - marked "to be interleaved" in their ActorState (controlled by the checker algorithm).
55 * - which simcall can currently be executed (like a comm where the other partner is already known)
56 * Once we returned the last enabled transition of a process, it is marked done.
58 * Things can get muddled with the WAITANY and TESTANY simcalls, that are rewritten on the fly to a bunch of WAIT
59 * (resp TEST) transitions using the transition.argument field to remember what was the last returned sub-transition.
61 static inline smx_simcall_t MC_state_choose_request_for_process(simgrid::mc::State* state, smx_actor_t actor)
63 /* reset the outgoing transition */
64 simgrid::mc::ActorState* procstate = &state->actor_states_[actor->get_pid()];
65 state->transition_.pid_ = -1;
66 state->transition_.times_considered_ = -1;
67 state->transition_.textual[0] = '\0';
68 state->executed_req_.call_ = Simcall::NONE;
70 if (not simgrid::mc::actor_is_enabled(actor))
71 return nullptr; // Not executable in the application
73 smx_simcall_t req = nullptr;
74 if (actor->simcall_.observer_ != nullptr) {
75 state->transition_.times_considered_ = procstate->times_considered;
76 procstate->times_considered++;
77 if (actor->simcall_.mc_max_consider_ <= procstate->times_considered)
78 procstate->set_done();
79 req = &actor->simcall_;
81 switch (actor->simcall_.call_) {
82 case Simcall::COMM_WAITANY:
83 state->transition_.times_considered_ = -1;
84 while (procstate->times_considered < simcall_comm_waitany__get__count(&actor->simcall_)) {
85 if (simgrid::mc::request_is_enabled_by_idx(&actor->simcall_, procstate->times_considered)) {
86 state->transition_.times_considered_ = procstate->times_considered;
87 ++procstate->times_considered;
90 ++procstate->times_considered;
93 if (procstate->times_considered >= simcall_comm_waitany__get__count(&actor->simcall_))
94 procstate->set_done();
95 if (state->transition_.times_considered_ != -1)
96 req = &actor->simcall_;
99 case Simcall::COMM_TESTANY:
100 state->transition_.times_considered_ = -1;
101 while (procstate->times_considered < simcall_comm_testany__get__count(&actor->simcall_)) {
102 if (simgrid::mc::request_is_enabled_by_idx(&actor->simcall_, procstate->times_considered)) {
103 state->transition_.times_considered_ = procstate->times_considered;
104 ++procstate->times_considered;
107 ++procstate->times_considered;
110 if (procstate->times_considered >= simcall_comm_testany__get__count(&actor->simcall_))
111 procstate->set_done();
112 if (state->transition_.times_considered_ != -1)
113 req = &actor->simcall_;
116 case Simcall::COMM_WAIT: {
117 simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> remote_act =
118 remote(simcall_comm_wait__getraw__comm(&actor->simcall_));
119 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_act;
120 mc_model_checker->get_remote_simulation().read(temp_act, remote_act);
121 const simgrid::kernel::activity::CommImpl* act = temp_act.get_buffer();
122 if (act->src_actor_.get() && act->dst_actor_.get())
123 state->transition_.times_considered_ = 0; // OK
124 else if (act->src_actor_.get() == nullptr && act->state_ == simgrid::kernel::activity::State::READY &&
126 state->transition_.times_considered_ = 0; // OK
128 state->transition_.times_considered_ = -1; // timeout
129 procstate->set_done();
130 req = &actor->simcall_;
135 procstate->set_done();
136 state->transition_.times_considered_ = 0;
137 req = &actor->simcall_;
143 state->transition_.pid_ = actor->get_pid();
144 state->executed_req_ = *req;
146 // Fetch the data of the request and translate it:
147 state->internal_req_ = *req;
148 state->internal_req_.mc_value_ = state->transition_.times_considered_;
149 simcall_translate(&state->internal_req_, state->internal_comm_);
154 static void simcall_translate(smx_simcall_t req,
155 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl>& buffered_comm)
157 simgrid::kernel::activity::CommImpl* chosen_comm;
159 /* The waitany and testany request are transformed into a wait or test request over the corresponding communication
160 * action so it can be treated later by the dependence function. */
161 switch (req->call_) {
162 case Simcall::COMM_WAITANY:
163 req->call_ = Simcall::COMM_WAIT;
164 chosen_comm = mc_model_checker->get_remote_simulation().read(
165 remote(simcall_comm_waitany__get__comms(req) + req->mc_value_));
167 mc_model_checker->get_remote_simulation().read(buffered_comm, remote(chosen_comm));
168 simcall_comm_wait__set__comm(req, buffered_comm.get_buffer());
169 simcall_comm_wait__set__timeout(req, 0);
172 case Simcall::COMM_TESTANY:
173 req->call_ = Simcall::COMM_TEST;
174 chosen_comm = mc_model_checker->get_remote_simulation().read(
175 remote(simcall_comm_testany__get__comms(req) + req->mc_value_));
177 mc_model_checker->get_remote_simulation().read(buffered_comm, remote(chosen_comm));
178 simcall_comm_test__set__comm(req, buffered_comm.get_buffer());
179 simcall_comm_test__set__result(req, req->mc_value_);
182 case Simcall::COMM_WAIT:
183 chosen_comm = simcall_comm_wait__getraw__comm(req);
184 mc_model_checker->get_remote_simulation().read(buffered_comm, remote(chosen_comm));
185 simcall_comm_wait__set__comm(req, buffered_comm.get_buffer());
188 case Simcall::COMM_TEST:
189 chosen_comm = simcall_comm_test__getraw__comm(req);
190 mc_model_checker->get_remote_simulation().read(buffered_comm, remote(chosen_comm));
191 simcall_comm_test__set__comm(req, buffered_comm.get_buffer());
195 /* No translation needed */
200 simgrid::kernel::activity::CommImpl* Api::get_comm_or_nullptr(smx_simcall_t const r) const
202 if (r->call_ == Simcall::COMM_WAIT)
203 return simcall_comm_wait__getraw__comm(r);
204 if (r->call_ == Simcall::COMM_TEST)
205 return simcall_comm_test__getraw__comm(r);
209 /** Statically "upcast" a s_smx_actor_t into an ActorInformation
211 * This gets 'actorInfo' from '&actorInfo->copy'. It upcasts in the
212 * sense that we could achieve the same thing by having ActorInformation
213 * inherit from s_smx_actor_t but we don't really want to do that.
215 simgrid::mc::ActorInformation* Api::actor_info_cast(smx_actor_t actor) const
217 simgrid::mc::ActorInformation temp;
218 std::size_t offset = (char*)temp.copy.get_buffer() - (char*)&temp;
220 auto* process_info = reinterpret_cast<simgrid::mc::ActorInformation*>((char*)actor - offset);
225 bool Api::request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const
227 if (r1->call_ == Simcall::COMM_ISEND && r2->call_ == Simcall::COMM_IRECV)
230 if (r1->call_ == Simcall::COMM_IRECV && r2->call_ == Simcall::COMM_ISEND)
233 // Those are internal requests, we do not need indirection because those objects are copies:
234 auto comm1 = get_comm_or_nullptr(r1);
235 auto comm2 = get_comm_or_nullptr(r2);
237 if ((r1->call_ == Simcall::COMM_ISEND || r1->call_ == Simcall::COMM_IRECV) && r2->call_ == Simcall::COMM_WAIT) {
238 auto mbox1 = get_mbox_remote_addr(r1);
239 auto mbox2 = remote(comm2->mbox_cpy);
241 if (mbox1 != mbox2 && simcall_comm_wait__get__timeout(r2) <= 0)
244 if ((r1->issuer_ != comm2->src_actor_.get()) && (r1->issuer_ != comm2->dst_actor_.get()) &&
245 simcall_comm_wait__get__timeout(r2) <= 0)
248 if ((r1->call_ == Simcall::COMM_ISEND) && (comm2->type_ == kernel::activity::CommImpl::Type::SEND) &&
249 (comm2->src_buff_ != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
252 if ((r1->call_ == Simcall::COMM_IRECV) && (comm2->type_ == kernel::activity::CommImpl::Type::RECEIVE) &&
253 (comm2->dst_buff_ != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
257 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
260 if((r1->call == Simcall::COMM_ISEND || r1->call == Simcall::COMM_IRECV)
261 && r2->call == Simcall::COMM_TEST)
265 if (r1->call_ == Simcall::COMM_WAIT && (r2->call_ == Simcall::COMM_WAIT || r2->call_ == Simcall::COMM_TEST) &&
266 (comm1->src_actor_.get() == nullptr || comm1->dst_actor_.get() == nullptr))
269 if (r1->call_ == Simcall::COMM_TEST &&
270 (simcall_comm_test__get__comm(r1) == nullptr || comm1->src_buff_ == nullptr || comm1->dst_buff_ == nullptr))
273 if (r1->call_ == Simcall::COMM_TEST && r2->call_ == Simcall::COMM_WAIT && comm1->src_buff_ == comm2->src_buff_ &&
274 comm1->dst_buff_ == comm2->dst_buff_)
277 if (r1->call_ == Simcall::COMM_WAIT && r2->call_ == Simcall::COMM_TEST && comm1->src_buff_ != nullptr &&
278 comm1->dst_buff_ != nullptr && comm2->src_buff_ != nullptr && comm2->dst_buff_ != nullptr &&
279 comm1->dst_buff_ != comm2->src_buff_ && comm1->dst_buff_ != comm2->dst_buff_ &&
280 comm2->dst_buff_ != comm1->src_buff_)
286 bool Api::simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const
288 const auto ISEND = Simcall::COMM_ISEND;
289 const auto IRECV = Simcall::COMM_IRECV;
290 const auto TEST = Simcall::COMM_TEST;
291 const auto WAIT = Simcall::COMM_WAIT;
293 if (req1->issuer_ == req2->issuer_)
296 /* The independence theorem only consider 4 simcalls. All others are dependent with anything. */
297 if (req1->call_ != ISEND && req1->call_ != IRECV && req1->call_ != TEST && req1->call_ != WAIT)
299 if (req2->call_ != ISEND && req2->call_ != IRECV && req2->call_ != TEST && req2->call_ != WAIT)
302 /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */
303 if ((req1->call_ == WAIT && simcall_comm_wait__get__timeout(req1) > 0) ||
304 (req2->call_ == WAIT && simcall_comm_wait__get__timeout(req2) > 0))
307 if (req1->call_ != req2->call_)
308 return request_depend_asymmetric(req1, req2) && request_depend_asymmetric(req2, req1);
310 // Those are internal requests, we do not need indirection because those objects are copies:
311 const auto comm1 = get_comm_or_nullptr(req1);
312 const auto comm2 = get_comm_or_nullptr(req2);
314 switch (req1->call_) {
315 case Simcall::COMM_ISEND:
316 return simcall_comm_isend__get__mbox(req1) == simcall_comm_isend__get__mbox(req2);
317 case Simcall::COMM_IRECV:
318 return simcall_comm_irecv__get__mbox(req1) == simcall_comm_irecv__get__mbox(req2);
319 case Simcall::COMM_WAIT:
320 if (comm1->src_buff_ == comm2->src_buff_ && comm1->dst_buff_ == comm2->dst_buff_)
322 if (comm1->src_buff_ != nullptr && comm1->dst_buff_ != nullptr && comm2->src_buff_ != nullptr &&
323 comm2->dst_buff_ != nullptr && comm1->dst_buff_ != comm2->src_buff_ && comm1->dst_buff_ != comm2->dst_buff_ &&
324 comm2->dst_buff_ != comm1->src_buff_)
332 xbt::string const& Api::get_actor_host_name(smx_actor_t actor) const
334 if (mc_model_checker == nullptr)
335 return actor->get_host()->get_name();
337 const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
339 // Read the simgrid::xbt::string in the MCed process:
340 simgrid::mc::ActorInformation* info = actor_info_cast(actor);
341 auto remote_string_address =
342 remote(reinterpret_cast<const simgrid::xbt::string_data*>(&actor->get_host()->get_name()));
343 simgrid::xbt::string_data remote_string = process->read(remote_string_address);
344 std::vector<char> hostname(remote_string.len + 1);
345 // no need to read the terminating null byte, and thus hostname[remote_string.len] is guaranteed to be '\0'
346 process->read_bytes(hostname.data(), remote_string.len, remote(remote_string.data));
347 info->hostname = &mc_model_checker->get_host_name(hostname.data());
348 return *info->hostname;
351 std::string Api::get_actor_name(smx_actor_t actor) const
353 if (mc_model_checker == nullptr)
354 return actor->get_cname();
356 simgrid::mc::ActorInformation* info = actor_info_cast(actor);
357 if (info->name.empty()) {
358 const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
360 simgrid::xbt::string_data string_data = simgrid::xbt::string::to_string_data(actor->name_);
361 info->name = process->read_string(remote(string_data.data), string_data.len);
366 std::string Api::get_actor_string(smx_actor_t actor) const
370 res = "(" + std::to_string(actor->get_pid()) + ")";
371 if (actor->get_host())
372 res += std::string(get_actor_host_name(actor)) + " (" + get_actor_name(actor) + ")";
374 res += get_actor_name(actor);
380 std::string Api::get_actor_dot_label(smx_actor_t actor) const
382 std::string res = "(" + std::to_string(actor->get_pid()) + ")";
383 if (actor->get_host())
384 res += get_actor_host_name(actor);
388 void Api::initialize(char** argv) const
390 simgrid::mc::session = new simgrid::mc::Session([argv] {
392 while (argv[i] != nullptr && argv[i][0] == '-')
394 xbt_assert(argv[i] != nullptr,
395 "Unable to find a binary to exec on the command line. Did you only pass config flags?");
396 execvp(argv[i], argv + i);
397 xbt_die("The model-checked process failed to exec(): %s", strerror(errno));
401 std::vector<simgrid::mc::ActorInformation>& Api::get_actors() const
403 return mc_model_checker->get_remote_simulation().actors();
406 bool Api::actor_is_enabled(aid_t pid) const
408 return session->actor_is_enabled(pid);
411 unsigned long Api::get_maxpid() const
413 static const char* name = nullptr;
415 name = "simgrid::kernel::actor::maxpid";
416 if (mc_model_checker->get_remote_simulation().find_variable(name) == nullptr)
417 name = "maxpid"; // We seem to miss the namespaces when compiling with GCC
419 unsigned long maxpid;
420 mc_model_checker->get_remote_simulation().read_variable(name, &maxpid, sizeof(maxpid));
424 int Api::get_actors_size() const
426 return mc_model_checker->get_remote_simulation().actors().size();
429 RemotePtr<kernel::activity::CommImpl> Api::get_comm_isend_raw_addr(smx_simcall_t request) const
431 return remote(static_cast<kernel::activity::CommImpl*>(simcall_comm_isend__getraw__result(request)));
434 RemotePtr<kernel::activity::CommImpl> Api::get_comm_wait_raw_addr(smx_simcall_t request) const
436 return remote(simcall_comm_wait__getraw__comm(request));
439 RemotePtr<kernel::activity::CommImpl> Api::get_comm_waitany_raw_addr(smx_simcall_t request, int value) const
441 auto addr = simcall_comm_waitany__getraw__comms(request) + value;
442 auto comm_addr = mc_model_checker->get_remote_simulation().read(remote(addr));
443 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
446 std::string Api::get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const
448 Remote<kernel::activity::CommImpl> temp_activity;
449 mc_model_checker->get_remote_simulation().read(temp_activity, addr);
450 const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
452 char* remote_name = mc_model_checker->get_remote_simulation().read<char*>(RemotePtr<char*>(
453 (uint64_t)(activity->get_mailbox() ? &activity->get_mailbox()->get_name() : &activity->mbox_cpy->get_name())));
454 auto rdv = mc_model_checker->get_remote_simulation().read_string(RemotePtr<char>(remote_name));
458 unsigned long Api::get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
460 Remote<kernel::activity::CommImpl> temp_activity;
461 mc_model_checker->get_remote_simulation().read(temp_activity, addr);
462 const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
464 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(activity->src_actor_.get()))->get_pid();
468 unsigned long Api::get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
470 Remote<kernel::activity::CommImpl> temp_activity;
471 mc_model_checker->get_remote_simulation().read(temp_activity, addr);
472 const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
474 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(activity->dst_actor_.get()))->get_pid();
478 std::vector<char> Api::get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const
480 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
481 mc_model_checker->get_remote_simulation().read(temp_comm, addr);
482 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
484 std::vector<char> buffer{};
485 if (comm->src_buff_ != nullptr) {
486 buffer.resize(comm->src_buff_size_);
487 mc_model_checker->get_remote_simulation().read_bytes(buffer.data(), buffer.size(), remote(comm->src_buff_));
493 bool Api::check_send_request_detached(smx_simcall_t const& simcall) const
495 simgrid::smpi::Request mpi_request;
496 mc_model_checker->get_remote_simulation().read(
497 &mpi_request, remote(static_cast<smpi::Request*>(simcall_comm_isend__get__data(simcall))));
498 return mpi_request.detached();
502 smx_actor_t Api::get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
504 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
505 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
506 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
508 auto src_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->src_actor_.get()));
512 smx_actor_t Api::get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
514 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
515 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
516 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
518 auto dst_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->dst_actor_.get()));
522 std::size_t Api::get_remote_heap_bytes() const
524 RemoteSimulation& process = mc_model_checker->get_remote_simulation();
525 auto heap_bytes_used = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
526 return heap_bytes_used;
529 void Api::session_initialize() const
531 session->initialize();
534 void Api::mc_inc_visited_states() const
536 mc_model_checker->visited_states++;
539 void Api::mc_inc_executed_trans() const
541 mc_model_checker->executed_transitions++;
544 unsigned long Api::mc_get_visited_states() const
546 return mc_model_checker->visited_states;
549 unsigned long Api::mc_get_executed_trans() const
551 return mc_model_checker->executed_transitions;
554 void Api::mc_check_deadlock() const
556 if (mc_model_checker->checkDeadlock()) {
558 throw DeadlockError();
562 /** Get the issuer of a simcall (`req->issuer`)
564 * In split-process mode, it does the black magic necessary to get an address
565 * of a (shallow) copy of the data structure the issuer SIMIX actor in the local
568 * @param process the MCed process
569 * @param req the simcall (copied in the local process)
571 smx_actor_t Api::simcall_get_issuer(s_smx_simcall const* req) const
573 xbt_assert(mc_model_checker != nullptr);
575 // This is the address of the smx_actor in the MCed process:
576 auto address = simgrid::mc::remote(req->issuer_);
578 // Lookup by address:
579 for (auto& actor : mc_model_checker->get_remote_simulation().actors())
580 if (actor.address == address)
581 return actor.copy.get_buffer();
582 for (auto& actor : mc_model_checker->get_remote_simulation().dead_actors())
583 if (actor.address == address)
584 return actor.copy.get_buffer();
586 xbt_die("Issuer not found");
589 long Api::simcall_get_actor_id(s_smx_simcall const* req) const
591 return simcall_get_issuer(req)->get_pid();
594 RemotePtr<kernel::activity::MailboxImpl> Api::get_mbox_remote_addr(smx_simcall_t const req) const
596 if (req->call_ == Simcall::COMM_ISEND)
597 return remote(simcall_comm_isend__get__mbox(req));
598 if (req->call_ == Simcall::COMM_IRECV)
599 return remote(simcall_comm_irecv__get__mbox(req));
603 RemotePtr<kernel::activity::ActivityImpl> Api::get_comm_remote_addr(smx_simcall_t const req) const
605 if (req->call_ == Simcall::COMM_ISEND)
606 return remote(simcall_comm_isend__getraw__result(req));
607 if (req->call_ == Simcall::COMM_IRECV)
608 return remote(simcall_comm_irecv__getraw__result(req));
612 bool Api::mc_is_null() const
614 auto is_null = (mc_model_checker == nullptr) ? true : false;
618 Checker* Api::mc_get_checker() const
620 return mc_model_checker->getChecker();
623 void Api::set_checker(Checker* const checker) const
625 xbt_assert(mc_model_checker);
626 xbt_assert(mc_model_checker->getChecker() == nullptr);
627 mc_model_checker->setChecker(checker);
630 void Api::handle_simcall(Transition const& transition) const
632 mc_model_checker->handle_simcall(transition);
635 void Api::mc_wait_for_requests() const
637 mc_model_checker->wait_for_requests();
640 void Api::mc_exit(int status) const
642 mc_model_checker->exit(status);
645 void Api::dump_record_path() const
647 simgrid::mc::dumpRecordPath();
650 smx_simcall_t Api::mc_state_choose_request(simgrid::mc::State* state) const
652 for (auto& actor : mc_model_checker->get_remote_simulation().actors()) {
653 /* Only consider the actors that were marked as interleaving by the checker algorithm */
654 if (not state->actor_states_[actor.copy.get_buffer()->get_pid()].is_todo())
657 smx_simcall_t res = MC_state_choose_request_for_process(state, actor.copy.get_buffer());
664 std::list<transition_detail_t> Api::get_enabled_transitions(simgrid::mc::State* state) const
666 std::list<transition_detail_t> tr_list{};
668 for (auto& actor : mc_model_checker->get_remote_simulation().actors()) {
669 auto actor_pid = actor.copy.get_buffer()->get_pid();
670 auto actor_impl = actor.copy.get_buffer();
672 // Only consider the actors that were marked as interleaving by the checker algorithm
673 if (not state->actor_states_[actor_pid].is_todo())
675 // Not executable in the application
676 if (not simgrid::mc::actor_is_enabled(actor_impl))
679 auto transition = std::make_unique<s_transition_detail>();
680 Simcall simcall_call = actor_impl->simcall_.call_;
681 smx_simcall_t simcall = &actor_impl->simcall_;
682 transition->call_ = simcall_call;
683 switch (simcall_call) {
684 case Simcall::COMM_ISEND:
685 case Simcall::COMM_IRECV:
686 transition->mbox_remote_addr = get_mbox_remote_addr(simcall);
687 transition->comm_remote_addr = get_comm_remote_addr(simcall);
693 tr_list.emplace_back(std::move(transition));
699 std::string Api::request_to_string(smx_simcall_t req, int value) const
701 xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
706 smx_actor_t issuer = simcall_get_issuer(req);
708 if (issuer->simcall_.observer_ != nullptr)
709 return mc_model_checker->simcall_to_string(issuer->get_pid(), value);
711 switch (req->call_) {
712 case Simcall::COMM_ISEND:
714 args = "src=" + get_actor_string(issuer);
715 args += ", buff=" + pointer_to_string(simcall_comm_isend__get__src_buff(req));
716 args += ", size=" + buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
719 case Simcall::COMM_IRECV: {
720 size_t* remote_size = simcall_comm_irecv__get__dst_buff_size(req);
723 mc_model_checker->get_remote_simulation().read_bytes(&size, sizeof(size), remote(remote_size));
726 args = "dst=" + get_actor_string(issuer);
727 args += ", buff=" + pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
728 args += ", size=" + buff_size_to_string(size);
732 case Simcall::COMM_WAIT: {
733 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_wait__getraw__comm(req);
735 type = "WaitTimeout";
736 args = "comm=" + pointer_to_string(remote_act);
740 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_activity;
741 const simgrid::kernel::activity::CommImpl* act;
742 mc_model_checker->get_remote_simulation().read(temp_activity, remote(remote_act));
743 act = temp_activity.get_buffer();
745 smx_actor_t src_proc =
746 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
747 smx_actor_t dst_proc =
748 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
749 args = "comm=" + pointer_to_string(remote_act);
750 args += " [" + get_actor_string(src_proc) + "-> " + get_actor_string(dst_proc) + "]";
755 case Simcall::COMM_TEST: {
756 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_test__getraw__comm(req);
757 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_activity;
758 const simgrid::kernel::activity::CommImpl* act;
759 mc_model_checker->get_remote_simulation().read(temp_activity, remote(remote_act));
760 act = temp_activity.get_buffer();
762 if (act->src_actor_.get() == nullptr || act->dst_actor_.get() == nullptr) {
764 args = "comm=" + pointer_to_string(remote_act);
768 smx_actor_t src_proc =
769 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
770 smx_actor_t dst_proc =
771 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
772 args = "comm=" + pointer_to_string(remote_act);
773 args += " [" + get_actor_string(src_proc) + " -> " + get_actor_string(dst_proc) + "]";
778 case Simcall::COMM_WAITANY: {
780 size_t count = simcall_comm_waitany__get__count(req);
782 simgrid::kernel::activity::CommImpl* remote_sync;
784 mc_model_checker->get_remote_simulation().read(remote(simcall_comm_waitany__get__comms(req) + value));
785 args = "comm=" + pointer_to_string(remote_sync) + xbt::string_printf("(%d of %zu)", value + 1, count);
787 args = "comm at idx " + std::to_string(value);
791 case Simcall::COMM_TESTANY:
793 type = "TestAny FALSE";
797 args = xbt::string_printf("(%d of %zu)", value + 1, simcall_comm_testany__get__count(req));
802 type = SIMIX_simcall_name(req->call_);
807 return "[" + get_actor_string(issuer) + "] " + type + "(" + args + ")";
810 std::string Api::request_get_dot_output(smx_simcall_t req, int value) const
812 const smx_actor_t issuer = simcall_get_issuer(req);
813 const char* color = get_color(issuer->get_pid() - 1);
817 if (req->observer_ != nullptr) {
818 label = mc_model_checker->simcall_dot_label(issuer->get_pid(), value);
820 switch (req->call_) {
821 case Simcall::COMM_ISEND:
822 label = "[" + get_actor_dot_label(issuer) + "] iSend";
825 case Simcall::COMM_IRECV:
826 label = "[" + get_actor_dot_label(issuer) + "] iRecv";
829 case Simcall::COMM_WAIT:
831 label = "[" + get_actor_dot_label(issuer) + "] WaitTimeout";
833 kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req);
834 Remote<kernel::activity::CommImpl> temp_comm;
835 mc_model_checker->get_remote_simulation().read(temp_comm,
836 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
837 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
839 const kernel::actor::ActorImpl* src_proc =
840 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->src_actor_.get()));
841 const kernel::actor::ActorImpl* dst_proc =
842 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->dst_actor_.get()));
843 label = "[" + get_actor_dot_label(issuer) + "] Wait";
844 label += " [(" + std::to_string(src_proc ? src_proc->get_pid() : 0) + ")";
845 label += "->(" + std::to_string(dst_proc ? dst_proc->get_pid() : 0) + ")]";
849 case Simcall::COMM_TEST: {
850 kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req);
851 Remote<simgrid::kernel::activity::CommImpl> temp_comm;
852 mc_model_checker->get_remote_simulation().read(temp_comm,
853 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
854 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
855 if (comm->src_actor_.get() == nullptr || comm->dst_actor_.get() == nullptr) {
856 label = "[" + get_actor_dot_label(issuer) + "] Test FALSE";
858 label = "[" + get_actor_dot_label(issuer) + "] Test TRUE";
863 case Simcall::COMM_WAITANY:
864 label = "[" + get_actor_dot_label(issuer) + "] WaitAny";
865 label += xbt::string_printf(" [%d of %zu]", value + 1, simcall_comm_waitany__get__count(req));
868 case Simcall::COMM_TESTANY:
870 label = "[" + get_actor_dot_label(issuer) + "] TestAny FALSE";
872 label = "[" + get_actor_dot_label(issuer) + "] TestAny TRUE";
873 label += xbt::string_printf(" [%d of %zu]", value + 1, simcall_comm_testany__get__count(req));
881 return "label = \"" + label + "\", color = " + color + ", fontcolor = " + color;
885 int Api::get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const
887 simgrid::smpi::Request mpi_request;
888 void* simcall_data = nullptr;
889 if (type == Simcall::COMM_ISEND)
890 simcall_data = simcall_comm_isend__get__data(simcall);
891 else if (type == Simcall::COMM_IRECV)
892 simcall_data = simcall_comm_irecv__get__data(simcall);
893 mc_model_checker->get_remote_simulation().read(&mpi_request, remote(static_cast<smpi::Request*>(simcall_data)));
894 return mpi_request.tag();
898 void Api::restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const
900 system_state->restore(&mc_model_checker->get_remote_simulation());
903 void Api::log_state() const
905 session->log_state();
908 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
910 return simgrid::mc::snapshot_equal(s1, s2);
913 simgrid::mc::Snapshot* Api::take_snapshot(int num_state) const
915 auto snapshot = new simgrid::mc::Snapshot(num_state);
919 void Api::s_close() const
924 void Api::restore_initial_state() const
926 session->restore_initial_state();
929 void Api::execute(Transition& transition, smx_simcall_t simcall) const
931 /* FIXME: once all simcalls have observers, kill the simcall parameter and use mc_model_checker->simcall_to_string() */
932 transition.textual = request_to_string(simcall, transition.times_considered_);
933 session->execute(transition);
937 void Api::automaton_load(const char* file) const
939 MC_automaton_load(file);
943 std::vector<int> Api::automaton_propositional_symbol_evaluate() const
945 unsigned int cursor = 0;
946 std::vector<int> values;
947 xbt_automaton_propositional_symbol_t ps = nullptr;
948 xbt_dynar_foreach (mc::property_automaton->propositional_symbols, cursor, ps)
949 values.push_back(xbt_automaton_propositional_symbol_evaluate(ps));
953 std::vector<xbt_automaton_state_t> Api::get_automaton_state() const
955 std::vector<xbt_automaton_state_t> automaton_stack;
956 unsigned int cursor = 0;
957 xbt_automaton_state_t automaton_state;
958 xbt_dynar_foreach (mc::property_automaton->states, cursor, automaton_state)
959 if (automaton_state->type == -1)
960 automaton_stack.push_back(automaton_state);
961 return automaton_stack;
964 int Api::compare_automaton_exp_label(const xbt_automaton_exp_label* l) const
966 unsigned int cursor = 0;
967 xbt_automaton_propositional_symbol_t p = nullptr;
968 xbt_dynar_foreach (simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
969 if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
975 void Api::set_property_automaton(xbt_automaton_state_t const& automaton_state) const
977 mc::property_automaton->current_state = automaton_state;
980 xbt_automaton_exp_label_t Api::get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const
982 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
983 return transition->label;
986 xbt_automaton_state_t Api::get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const
988 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
989 return transition->dst;
993 } // namespace simgrid