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/SimcallInspector.hpp"
7 #include "src/mc/mc_comm_pattern.hpp"
8 #include "src/mc/mc_pattern.hpp"
9 #include "src/mc/mc_private.hpp"
10 #include "src/mc/mc_smx.hpp"
11 #include "src/mc/remote/RemoteSimulation.hpp"
12 #include <xbt/asserts.h>
14 // #include <xbt/dynar.h>
17 #include "src/smpi/include/smpi_request.hpp"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Fasade APIs ");
22 using Simcall = simgrid::simix::Simcall;
27 static inline const char* get_color(int id)
29 static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
30 "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
32 return colors[id % colors.size()];
35 static char* pointer_to_string(void* pointer)
37 if (XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose))
38 return bprintf("%p", pointer);
40 return xbt_strdup("(verbose only)");
43 static char* buff_size_to_string(size_t buff_size)
45 if (XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose))
46 return bprintf("%zu", buff_size);
48 return xbt_strdup("(verbose only)");
51 /* Search an enabled transition for the given process.
53 * This can be seen as an iterator returning the next transition of the process.
55 * We only consider the processes that are both
56 * - marked "to be interleaved" in their ActorState (controlled by the checker algorithm).
57 * - which simcall can currently be executed (like a comm where the other partner is already known)
58 * Once we returned the last enabled transition of a process, it is marked done.
60 * Things can get muddled with the WAITANY and TESTANY simcalls, that are rewritten on the fly to a bunch of WAIT
61 * (resp TEST) transitions using the transition.argument field to remember what was the last returned sub-transition.
63 static inline smx_simcall_t MC_state_choose_request_for_process(simgrid::mc::State* state, smx_actor_t actor)
65 /* reset the outgoing transition */
66 simgrid::mc::ActorState* procstate = &state->actor_states_[actor->get_pid()];
67 state->transition_.pid_ = -1;
68 state->transition_.argument_ = -1;
69 state->executed_req_.call_ = Simcall::NONE;
71 if (not simgrid::mc::actor_is_enabled(actor))
72 return nullptr; // Not executable in the application
74 smx_simcall_t req = nullptr;
75 switch (actor->simcall_.call_) {
76 case Simcall::COMM_WAITANY:
77 state->transition_.argument_ = -1;
78 while (procstate->times_considered < simcall_comm_waitany__get__count(&actor->simcall_)) {
79 if (simgrid::mc::request_is_enabled_by_idx(&actor->simcall_, procstate->times_considered)) {
80 state->transition_.argument_ = procstate->times_considered;
81 ++procstate->times_considered;
84 ++procstate->times_considered;
87 if (procstate->times_considered >= simcall_comm_waitany__get__count(&actor->simcall_))
88 procstate->set_done();
89 if (state->transition_.argument_ != -1)
90 req = &actor->simcall_;
93 case Simcall::COMM_TESTANY: {
94 unsigned start_count = procstate->times_considered;
95 state->transition_.argument_ = -1;
96 while (procstate->times_considered < simcall_comm_testany__get__count(&actor->simcall_)) {
97 if (simgrid::mc::request_is_enabled_by_idx(&actor->simcall_, procstate->times_considered)) {
98 state->transition_.argument_ = procstate->times_considered;
99 ++procstate->times_considered;
102 ++procstate->times_considered;
105 if (procstate->times_considered >= simcall_comm_testany__get__count(&actor->simcall_))
106 procstate->set_done();
108 if (state->transition_.argument_ != -1 || start_count == 0)
109 req = &actor->simcall_;
114 case Simcall::COMM_WAIT: {
115 simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> remote_act =
116 remote(simcall_comm_wait__getraw__comm(&actor->simcall_));
117 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_act;
118 mc_model_checker->get_remote_simulation().read(temp_act, remote_act);
119 const simgrid::kernel::activity::CommImpl* act = temp_act.get_buffer();
120 if (act->src_actor_.get() && act->dst_actor_.get())
121 state->transition_.argument_ = 0; // OK
122 else if (act->src_actor_.get() == nullptr && act->type_ == simgrid::kernel::activity::CommImpl::Type::READY &&
124 state->transition_.argument_ = 0; // OK
126 state->transition_.argument_ = -1; // timeout
127 procstate->set_done();
128 req = &actor->simcall_;
132 case Simcall::MC_RANDOM: {
133 int min_value = simcall_mc_random__get__min(&actor->simcall_);
134 state->transition_.argument_ = procstate->times_considered + min_value;
135 procstate->times_considered++;
136 if (state->transition_.argument_ == simcall_mc_random__get__max(&actor->simcall_))
137 procstate->set_done();
138 req = &actor->simcall_;
143 procstate->set_done();
144 state->transition_.argument_ = 0;
145 req = &actor->simcall_;
151 state->transition_.pid_ = actor->get_pid();
152 state->executed_req_ = *req;
153 // Fetch the data of the request and translate it:
154 state->internal_req_ = *req;
156 /* The waitany and testany request are transformed into a wait or test request over the corresponding communication
157 * action so it can be treated later by the dependence function. */
158 switch (req->call_) {
159 case Simcall::COMM_WAITANY: {
160 state->internal_req_.call_ = Simcall::COMM_WAIT;
161 simgrid::kernel::activity::CommImpl* remote_comm;
162 remote_comm = mc_model_checker->get_remote_simulation().read(
163 remote(simcall_comm_waitany__get__comms(req) + state->transition_.argument_));
164 mc_model_checker->get_remote_simulation().read(state->internal_comm_, remote(remote_comm));
165 simcall_comm_wait__set__comm(&state->internal_req_, state->internal_comm_.get_buffer());
166 simcall_comm_wait__set__timeout(&state->internal_req_, 0);
170 case Simcall::COMM_TESTANY:
171 state->internal_req_.call_ = Simcall::COMM_TEST;
173 if (state->transition_.argument_ > 0) {
174 simgrid::kernel::activity::CommImpl* remote_comm = mc_model_checker->get_remote_simulation().read(
175 remote(simcall_comm_testany__get__comms(req) + state->transition_.argument_));
176 mc_model_checker->get_remote_simulation().read(state->internal_comm_, remote(remote_comm));
179 simcall_comm_test__set__comm(&state->internal_req_, state->internal_comm_.get_buffer());
180 simcall_comm_test__set__result(&state->internal_req_, state->transition_.argument_);
183 case Simcall::COMM_WAIT:
184 mc_model_checker->get_remote_simulation().read_bytes(&state->internal_comm_, sizeof(state->internal_comm_),
185 remote(simcall_comm_wait__getraw__comm(req)));
186 simcall_comm_wait__set__comm(&state->executed_req_, state->internal_comm_.get_buffer());
187 simcall_comm_wait__set__comm(&state->internal_req_, state->internal_comm_.get_buffer());
190 case Simcall::COMM_TEST:
191 mc_model_checker->get_remote_simulation().read_bytes(&state->internal_comm_, sizeof(state->internal_comm_),
192 remote(simcall_comm_test__getraw__comm(req)));
193 simcall_comm_test__set__comm(&state->executed_req_, state->internal_comm_.get_buffer());
194 simcall_comm_test__set__comm(&state->internal_req_, state->internal_comm_.get_buffer());
198 /* No translation needed */
205 smx_mailbox_t Api::get_mbox(smx_simcall_t const r) const
208 case Simcall::COMM_ISEND:
209 return simcall_comm_isend__get__mbox(r);
210 case Simcall::COMM_IRECV:
211 return simcall_comm_irecv__get__mbox(r);
217 simgrid::kernel::activity::CommImpl* Api::get_comm(smx_simcall_t const r) const
220 case Simcall::COMM_WAIT:
221 return simcall_comm_wait__getraw__comm(r);
222 case Simcall::COMM_TEST:
223 return simcall_comm_test__getraw__comm(r);
230 bool Api::request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const
232 if (r1->call_ == Simcall::COMM_ISEND && r2->call_ == Simcall::COMM_IRECV)
235 if (r1->call_ == Simcall::COMM_IRECV && r2->call_ == Simcall::COMM_ISEND)
238 // Those are internal requests, we do not need indirection because those objects are copies:
239 const kernel::activity::CommImpl* synchro1 = get_comm(r1);
240 const kernel::activity::CommImpl* synchro2 = get_comm(r2);
242 if ((r1->call_ == Simcall::COMM_ISEND || r1->call_ == Simcall::COMM_IRECV) && r2->call_ == Simcall::COMM_WAIT) {
243 const kernel::activity::MailboxImpl* mbox = get_mbox(r1); // r1->get_mboxx')
245 if (mbox != synchro2->mbox_cpy
246 && simcall_comm_wait__get__timeout(r2) <= 0)
249 if ((r1->issuer_ != synchro2->src_actor_.get()) && (r1->issuer_ != synchro2->dst_actor_.get()) &&
250 simcall_comm_wait__get__timeout(r2) <= 0)
253 if ((r1->call_ == Simcall::COMM_ISEND) && (synchro2->type_ == kernel::activity::CommImpl::Type::SEND) &&
254 (synchro2->src_buff_ != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
257 if ((r1->call_ == Simcall::COMM_IRECV) && (synchro2->type_ == kernel::activity::CommImpl::Type::RECEIVE) &&
258 (synchro2->dst_buff_ != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
262 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
265 if((r1->call == Simcall::COMM_ISEND || r1->call == Simcall::COMM_IRECV)
266 && r2->call == Simcall::COMM_TEST)
270 if (r1->call_ == Simcall::COMM_WAIT && (r2->call_ == Simcall::COMM_WAIT || r2->call_ == Simcall::COMM_TEST) &&
271 (synchro1->src_actor_.get() == nullptr || synchro1->dst_actor_.get() == nullptr))
274 if (r1->call_ == Simcall::COMM_TEST &&
275 (simcall_comm_test__get__comm(r1) == nullptr || synchro1->src_buff_ == nullptr || synchro1->dst_buff_ == nullptr))
278 if (r1->call_ == Simcall::COMM_TEST && r2->call_ == Simcall::COMM_WAIT &&
279 synchro1->src_buff_ == synchro2->src_buff_ && synchro1->dst_buff_ == synchro2->dst_buff_)
282 if (r1->call_ == Simcall::COMM_WAIT && r2->call_ == Simcall::COMM_TEST && synchro1->src_buff_ != nullptr &&
283 synchro1->dst_buff_ != nullptr && synchro2->src_buff_ != nullptr && synchro2->dst_buff_ != nullptr &&
284 synchro1->dst_buff_ != synchro2->src_buff_ && synchro1->dst_buff_ != synchro2->dst_buff_ &&
285 synchro2->dst_buff_ != synchro1->src_buff_)
291 void Api::initialize(char** argv) const
293 simgrid::mc::session = new simgrid::mc::Session([argv] {
295 while (argv[i] != nullptr && argv[i][0] == '-')
297 xbt_assert(argv[i] != nullptr,
298 "Unable to find a binary to exec on the command line. Did you only pass config flags?");
299 execvp(argv[i], argv + i);
300 xbt_die("The model-checked process failed to exec(): %s", strerror(errno));
304 std::vector<simgrid::mc::ActorInformation>& Api::get_actors() const
306 return mc_model_checker->get_remote_simulation().actors();
309 bool Api::actor_is_enabled(aid_t pid) const
311 return session->actor_is_enabled(pid);
314 unsigned long Api::get_maxpid() const
316 return MC_smx_get_maxpid();
319 int Api::get_actors_size() const
321 return mc_model_checker->get_remote_simulation().actors().size();
324 RemotePtr<kernel::activity::CommImpl> Api::get_comm_isend_raw_addr(smx_simcall_t request) const
326 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(request->result_);
327 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
330 RemotePtr<kernel::activity::CommImpl> Api::get_comm_irecv_raw_addr(smx_simcall_t request) const
332 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(request->result_);
333 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
336 RemotePtr<kernel::activity::CommImpl> Api::get_comm_wait_raw_addr(smx_simcall_t request) const
338 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::CommImpl*>(request->args_[0]);
339 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
342 RemotePtr<kernel::activity::CommImpl> Api::get_comm_waitany_raw_addr(smx_simcall_t request, int value) const
344 auto addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::CommImpl**>(request->args_[0]) + value;
345 auto comm_addr = mc_model_checker->get_remote_simulation().read(remote(addr));
346 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
349 std::string Api::get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const
351 Remote<kernel::activity::CommImpl> temp_synchro;
352 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
353 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
355 char* remote_name = mc_model_checker->get_remote_simulation().read<char*>(RemotePtr<char*>(
356 (uint64_t)(synchro->get_mailbox() ? &synchro->get_mailbox()->get_name() : &synchro->mbox_cpy->get_name())));
357 auto rdv = mc_model_checker->get_remote_simulation().read_string(RemotePtr<char>(remote_name));
361 unsigned long Api::get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
363 Remote<kernel::activity::CommImpl> temp_synchro;
364 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
365 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
367 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(synchro->src_actor_.get()))->get_pid();
371 unsigned long Api::get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
373 Remote<kernel::activity::CommImpl> temp_synchro;
374 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
375 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
377 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(synchro->dst_actor_.get()))->get_pid();
381 std::vector<char> Api::get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const
383 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
384 mc_model_checker->get_remote_simulation().read(temp_comm, addr);
385 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
387 std::vector<char> buffer{};
388 if (comm->src_buff_ != nullptr) {
389 buffer.resize(comm->src_buff_size_);
390 mc_model_checker->get_remote_simulation().read_bytes(buffer.data(), buffer.size(), remote(comm->src_buff_));
395 const char* Api::get_actor_host_name(smx_actor_t actor) const
397 const char* host_name = MC_smx_actor_get_host_name(actor);
402 bool Api::check_send_request_detached(smx_simcall_t const& simcall) const
404 simgrid::smpi::Request mpi_request;
405 mc_model_checker->get_remote_simulation().read(
406 &mpi_request, remote(static_cast<smpi::Request*>(simcall_comm_isend__get__data(simcall))));
407 return mpi_request.detached();
411 smx_actor_t Api::get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
413 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
414 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
415 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
417 auto src_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->src_actor_.get()));
421 smx_actor_t Api::get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
423 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
424 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
425 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
427 auto dst_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->dst_actor_.get()));
431 std::size_t Api::get_remote_heap_bytes() const
433 RemoteSimulation& process = mc_model_checker->get_remote_simulation();
434 auto heap_bytes_used = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
435 return heap_bytes_used;
438 void Api::session_initialize() const
440 session->initialize();
443 void Api::mc_inc_visited_states() const
445 mc_model_checker->visited_states++;
448 void Api::mc_inc_executed_trans() const
450 mc_model_checker->executed_transitions++;
453 unsigned long Api::mc_get_visited_states() const
455 return mc_model_checker->visited_states;
458 unsigned long Api::mc_get_executed_trans() const
460 return mc_model_checker->executed_transitions;
463 bool Api::mc_check_deadlock() const
465 return mc_model_checker->checkDeadlock();
468 void Api::mc_show_deadlock() const
473 /** Get the issuer of a simcall (`req->issuer`)
475 * In split-process mode, it does the black magic necessary to get an address
476 * of a (shallow) copy of the data structure the issuer SIMIX actor in the local
479 * @param process the MCed process
480 * @param req the simcall (copied in the local process)
482 smx_actor_t Api::simcall_get_issuer(s_smx_simcall const* req) const
484 xbt_assert(mc_model_checker != nullptr);
486 // This is the address of the smx_actor in the MCed process:
487 auto address = simgrid::mc::remote(req->issuer_);
489 // Lookup by address:
490 for (auto& actor : mc_model_checker->get_remote_simulation().actors())
491 if (actor.address == address)
492 return actor.copy.get_buffer();
493 for (auto& actor : mc_model_checker->get_remote_simulation().dead_actors())
494 if (actor.address == address)
495 return actor.copy.get_buffer();
497 xbt_die("Issuer not found");
500 long Api::simcall_get_actor_id(s_smx_simcall const* req) const
502 return simcall_get_issuer(req)->get_pid();
505 smx_mailbox_t Api::simcall_get_mbox(smx_simcall_t const req) const
507 return get_mbox(req);
510 bool Api::mc_is_null() const
512 auto is_null = (mc_model_checker == nullptr) ? true : false;
516 Checker* Api::mc_get_checker() const
518 return mc_model_checker->getChecker();
521 void Api::set_checker(Checker* const checker) const
523 xbt_assert(mc_model_checker);
524 xbt_assert(mc_model_checker->getChecker() == nullptr);
525 mc_model_checker->setChecker(checker);
528 void Api::handle_simcall(Transition const& transition) const
530 mc_model_checker->handle_simcall(transition);
533 void Api::mc_wait_for_requests() const
535 mc_model_checker->wait_for_requests();
538 void Api::mc_exit(int status) const
540 mc_model_checker->exit(status);
543 std::string const& Api::mc_get_host_name(std::string const& hostname) const
545 return mc_model_checker->get_host_name(hostname);
548 void Api::dump_record_path() const
550 simgrid::mc::dumpRecordPath();
553 smx_simcall_t Api::mc_state_choose_request(simgrid::mc::State* state) const
555 for (auto& actor : mc_model_checker->get_remote_simulation().actors()) {
556 /* Only consider the actors that were marked as interleaving by the checker algorithm */
557 if (not state->actor_states_[actor.copy.get_buffer()->get_pid()].is_todo())
560 smx_simcall_t res = MC_state_choose_request_for_process(state, actor.copy.get_buffer());
567 bool Api::simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const
569 if (req1->issuer_ == req2->issuer_)
572 /* Wait with timeout transitions are not considered by the independence theorem, thus we consider them as dependent with all other transitions */
573 if ((req1->call_ == Simcall::COMM_WAIT && simcall_comm_wait__get__timeout(req1) > 0) ||
574 (req2->call_ == Simcall::COMM_WAIT && simcall_comm_wait__get__timeout(req2) > 0))
577 if (req1->call_ != req2->call_)
578 return request_depend_asymmetric(req1, req2) && request_depend_asymmetric(req2, req1);
580 // Those are internal requests, we do not need indirection because those objects are copies:
581 const kernel::activity::CommImpl* synchro1 = get_comm(req1);
582 const kernel::activity::CommImpl* synchro2 = get_comm(req2);
584 switch (req1->call_) {
585 case Simcall::COMM_ISEND:
586 return simcall_comm_isend__get__mbox(req1) == simcall_comm_isend__get__mbox(req2);
587 case Simcall::COMM_IRECV:
588 return simcall_comm_irecv__get__mbox(req1) == simcall_comm_irecv__get__mbox(req2);
589 case Simcall::COMM_WAIT:
590 if (synchro1->src_buff_ == synchro2->src_buff_ && synchro1->dst_buff_ == synchro2->dst_buff_)
592 if (synchro1->src_buff_ != nullptr && synchro1->dst_buff_ != nullptr && synchro2->src_buff_ != nullptr &&
593 synchro2->dst_buff_ != nullptr && synchro1->dst_buff_ != synchro2->src_buff_ &&
594 synchro1->dst_buff_ != synchro2->dst_buff_ && synchro2->dst_buff_ != synchro1->src_buff_)
602 std::string Api::request_to_string(smx_simcall_t req, int value, RequestType request_type) const
604 xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
606 if (req->inspector_ != nullptr)
607 return req->inspector_->to_string();
609 bool use_remote_comm = true;
610 switch (request_type) {
611 case simgrid::mc::RequestType::simix:
612 use_remote_comm = true;
614 case simgrid::mc::RequestType::executed:
615 case simgrid::mc::RequestType::internal:
616 use_remote_comm = false;
622 const char* type = nullptr;
623 char* args = nullptr;
625 smx_actor_t issuer = simcall_get_issuer(req);
627 switch (req->call_) {
628 case Simcall::COMM_ISEND: {
630 char* p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
631 char* bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
632 if (issuer->get_host())
633 args = bprintf("src=(%ld)%s (%s), buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
634 MC_smx_actor_get_name(issuer), p, bs);
636 args = bprintf("src=(%ld)%s, buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_name(issuer), p, bs);
642 case Simcall::COMM_IRECV: {
643 size_t* remote_size = simcall_comm_irecv__get__dst_buff_size(req);
646 mc_model_checker->get_remote_simulation().read_bytes(&size, sizeof(size), remote(remote_size));
649 char* p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
650 char* bs = buff_size_to_string(size);
651 if (issuer->get_host())
652 args = bprintf("dst=(%ld)%s (%s), buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
653 MC_smx_actor_get_name(issuer), p, bs);
655 args = bprintf("dst=(%ld)%s, buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_name(issuer), p, bs);
661 case Simcall::COMM_WAIT: {
662 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_wait__getraw__comm(req);
665 type = "WaitTimeout";
666 p = pointer_to_string(remote_act);
667 args = bprintf("comm=%s", p);
670 p = pointer_to_string(remote_act);
672 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
673 const simgrid::kernel::activity::CommImpl* act;
674 if (use_remote_comm) {
675 mc_model_checker->get_remote_simulation().read(temp_synchro, remote(remote_act));
676 act = temp_synchro.get_buffer();
680 smx_actor_t src_proc =
681 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
682 smx_actor_t dst_proc =
683 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
684 args = bprintf("comm=%s [(%ld)%s (%s)-> (%ld)%s (%s)]", p, src_proc ? src_proc->get_pid() : 0,
685 src_proc ? MC_smx_actor_get_host_name(src_proc) : "",
686 src_proc ? MC_smx_actor_get_name(src_proc) : "", dst_proc ? dst_proc->get_pid() : 0,
687 dst_proc ? MC_smx_actor_get_host_name(dst_proc) : "",
688 dst_proc ? MC_smx_actor_get_name(dst_proc) : "");
694 case Simcall::COMM_TEST: {
695 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_test__getraw__comm(req);
696 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
697 const simgrid::kernel::activity::CommImpl* act;
698 if (use_remote_comm) {
699 mc_model_checker->get_remote_simulation().read(temp_synchro, remote(remote_act));
700 act = temp_synchro.get_buffer();
705 if (act->src_actor_.get() == nullptr || act->dst_actor_.get() == nullptr) {
707 p = pointer_to_string(remote_act);
708 args = bprintf("comm=%s", p);
711 p = pointer_to_string(remote_act);
713 smx_actor_t src_proc =
714 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
715 smx_actor_t dst_proc =
716 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
717 args = bprintf("comm=%s [(%ld)%s (%s) -> (%ld)%s (%s)]", p, src_proc->get_pid(),
718 MC_smx_actor_get_name(src_proc), MC_smx_actor_get_host_name(src_proc), dst_proc->get_pid(),
719 MC_smx_actor_get_name(dst_proc), MC_smx_actor_get_host_name(dst_proc));
725 case Simcall::COMM_WAITANY: {
727 size_t count = simcall_comm_waitany__get__count(req);
729 simgrid::kernel::activity::CommImpl* remote_sync;
731 mc_model_checker->get_remote_simulation().read(remote(simcall_comm_waitany__get__comms(req) + value));
732 char* p = pointer_to_string(remote_sync);
733 args = bprintf("comm=%s (%d of %zu)", p, value + 1, count);
736 args = bprintf("comm at idx %d", value);
740 case Simcall::COMM_TESTANY:
742 type = "TestAny FALSE";
743 args = xbt_strdup("-");
746 args = bprintf("(%d of %zu)", value + 1, simcall_comm_testany__get__count(req));
750 case Simcall::MUTEX_TRYLOCK:
751 case Simcall::MUTEX_LOCK: {
752 if (req->call_ == Simcall::MUTEX_LOCK)
755 type = "Mutex TRYLOCK";
757 simgrid::mc::Remote<simgrid::kernel::activity::MutexImpl> mutex;
758 mc_model_checker->get_remote_simulation().read_bytes(mutex.get_buffer(), sizeof(mutex),
759 remote(req->call_ == Simcall::MUTEX_LOCK
760 ? simcall_mutex_lock__get__mutex(req)
761 : simcall_mutex_trylock__get__mutex(req)));
762 args = bprintf("locked = %d, owner = %d, sleeping = n/a", mutex.get_buffer()->is_locked(),
763 mutex.get_buffer()->get_owner() != nullptr
764 ? (int)mc_model_checker->get_remote_simulation()
765 .resolve_actor(simgrid::mc::remote(mutex.get_buffer()->get_owner()))
771 case Simcall::MC_RANDOM:
773 args = bprintf("%d", value);
777 type = SIMIX_simcall_name(req->call_);
778 args = bprintf("??");
784 str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s(%s)", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
785 MC_smx_actor_get_name(issuer), type, args);
787 str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s ", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
788 MC_smx_actor_get_name(issuer), type);
793 std::string Api::request_get_dot_output(smx_simcall_t req, int value) const
795 const smx_actor_t issuer = simcall_get_issuer(req);
796 const char* color = get_color(issuer->get_pid() - 1);
798 if (req->inspector_ != nullptr)
799 return simgrid::xbt::string_printf("label = \"%s\", color = %s, fontcolor = %s",
800 req->inspector_->dot_label().c_str(), color, color);
804 switch (req->call_) {
805 case Simcall::COMM_ISEND:
806 if (issuer->get_host())
807 label = xbt::string_printf("[(%ld)%s] iSend", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
809 label = bprintf("[(%ld)] iSend", issuer->get_pid());
812 case Simcall::COMM_IRECV:
813 if (issuer->get_host())
814 label = xbt::string_printf("[(%ld)%s] iRecv", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
816 label = xbt::string_printf("[(%ld)] iRecv", issuer->get_pid());
819 case Simcall::COMM_WAIT:
821 if (issuer->get_host())
822 label = xbt::string_printf("[(%ld)%s] WaitTimeout", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
824 label = xbt::string_printf("[(%ld)] WaitTimeout", issuer->get_pid());
826 kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req);
827 Remote<kernel::activity::CommImpl> temp_comm;
828 mc_model_checker->get_remote_simulation().read(temp_comm,
829 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
830 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
832 const kernel::actor::ActorImpl* src_proc =
833 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->src_actor_.get()));
834 const kernel::actor::ActorImpl* dst_proc =
835 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->dst_actor_.get()));
836 if (issuer->get_host())
838 xbt::string_printf("[(%ld)%s] Wait [(%ld)->(%ld)]", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
839 src_proc ? src_proc->get_pid() : 0, dst_proc ? dst_proc->get_pid() : 0);
841 label = xbt::string_printf("[(%ld)] Wait [(%ld)->(%ld)]", issuer->get_pid(),
842 src_proc ? src_proc->get_pid() : 0, dst_proc ? dst_proc->get_pid() : 0);
846 case Simcall::COMM_TEST: {
847 kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req);
848 Remote<simgrid::kernel::activity::CommImpl> temp_comm;
849 mc_model_checker->get_remote_simulation().read(temp_comm,
850 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
851 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
852 if (comm->src_actor_.get() == nullptr || comm->dst_actor_.get() == nullptr) {
853 if (issuer->get_host())
854 label = xbt::string_printf("[(%ld)%s] Test FALSE", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
856 label = bprintf("[(%ld)] Test FALSE", issuer->get_pid());
858 if (issuer->get_host())
859 label = xbt::string_printf("[(%ld)%s] Test TRUE", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
861 label = xbt::string_printf("[(%ld)] Test TRUE", issuer->get_pid());
866 case Simcall::COMM_WAITANY: {
867 size_t comms_size = simcall_comm_waitany__get__count(req);
868 if (issuer->get_host())
869 label = xbt::string_printf("[(%ld)%s] WaitAny [%d of %zu]", issuer->get_pid(),
870 MC_smx_actor_get_host_name(issuer), value + 1, comms_size);
872 label = xbt::string_printf("[(%ld)] WaitAny [%d of %zu]", issuer->get_pid(), value + 1, comms_size);
876 case Simcall::COMM_TESTANY:
878 if (issuer->get_host())
879 label = xbt::string_printf("[(%ld)%s] TestAny FALSE", issuer->get_pid(), MC_smx_actor_get_host_name(issuer));
881 label = xbt::string_printf("[(%ld)] TestAny FALSE", issuer->get_pid());
883 if (issuer->get_host())
885 xbt::string_printf("[(%ld)%s] TestAny TRUE [%d of %lu]", issuer->get_pid(),
886 MC_smx_actor_get_host_name(issuer), value + 1, simcall_comm_testany__get__count(req));
888 label = xbt::string_printf("[(%ld)] TestAny TRUE [%d of %lu]", issuer->get_pid(), value + 1,
889 simcall_comm_testany__get__count(req));
893 case Simcall::MUTEX_TRYLOCK:
894 label = xbt::string_printf("[(%ld)] Mutex TRYLOCK", issuer->get_pid());
897 case Simcall::MUTEX_LOCK:
898 label = xbt::string_printf("[(%ld)] Mutex LOCK", issuer->get_pid());
901 case Simcall::MC_RANDOM:
902 if (issuer->get_host())
903 label = xbt::string_printf("[(%ld)%s] MC_RANDOM (%d)", issuer->get_pid(), MC_smx_actor_get_host_name(issuer),
906 label = xbt::string_printf("[(%ld)] MC_RANDOM (%d)", issuer->get_pid(), value);
913 return xbt::string_printf("label = \"%s\", color = %s, fontcolor = %s", label.c_str(), color, color);
916 const char* Api::simcall_get_name(simgrid::simix::Simcall kind) const
918 return SIMIX_simcall_name(kind);
922 int Api::get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const
924 simgrid::smpi::Request mpi_request;
925 void* simcall_data = nullptr;
926 if (type == Simcall::COMM_ISEND)
927 simcall_data = simcall_comm_isend__get__data(simcall);
928 else if (type == Simcall::COMM_IRECV)
929 simcall_data = simcall_comm_irecv__get__data(simcall);
930 mc_model_checker->get_remote_simulation().read(&mpi_request, remote(static_cast<smpi::Request*>(simcall_data)));
931 return mpi_request.tag();
935 void Api::restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const
937 system_state->restore(&mc_model_checker->get_remote_simulation());
940 void Api::log_state() const
942 session->log_state();
945 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
947 return simgrid::mc::snapshot_equal(s1, s2);
950 simgrid::mc::Snapshot* Api::take_snapshot(int num_state) const
952 auto snapshot = new simgrid::mc::Snapshot(num_state);
956 void Api::s_close() const
961 void Api::restore_initial_state() const
963 session->restore_initial_state();
966 void Api::execute(Transition const& transition) const
968 session->execute(transition);
972 void Api::automaton_load(const char* file) const
974 MC_automaton_load(file);
978 std::vector<int> Api::automaton_propositional_symbol_evaluate() const
980 unsigned int cursor = 0;
981 std::vector<int> values;
982 xbt_automaton_propositional_symbol_t ps = nullptr;
983 xbt_dynar_foreach (mc::property_automaton->propositional_symbols, cursor, ps)
984 values.push_back(xbt_automaton_propositional_symbol_evaluate(ps));
988 std::vector<xbt_automaton_state_t> Api::get_automaton_state() const
990 std::vector<xbt_automaton_state_t> automaton_stack;
991 unsigned int cursor = 0;
992 xbt_automaton_state_t automaton_state;
993 xbt_dynar_foreach (mc::property_automaton->states, cursor, automaton_state)
994 if (automaton_state->type == -1)
995 automaton_stack.push_back(automaton_state);
996 return automaton_stack;
999 int Api::compare_automaton_exp_label(const xbt_automaton_exp_label* l) const
1001 unsigned int cursor = 0;
1002 xbt_automaton_propositional_symbol_t p = nullptr;
1003 xbt_dynar_foreach (simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
1004 if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
1010 void Api::set_property_automaton(xbt_automaton_state_t const& automaton_state) const
1012 mc::property_automaton->current_state = automaton_state;
1015 xbt_automaton_exp_label_t Api::get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const
1017 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
1018 return transition->label;
1021 xbt_automaton_state_t Api::get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const
1023 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
1024 return transition->dst;
1028 } // namespace simgrid