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>& internal_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;
145 // Fetch the data of the request and translate it:
146 state->internal_req_ = *req;
147 state->internal_req_.mc_value_ = state->transition_.times_considered_;
148 simcall_translate(&state->internal_req_, state->internal_comm_);
153 static void simcall_translate(smx_simcall_t req,
154 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl>& internal_comm)
156 simgrid::kernel::activity::CommImpl* chosen_comm;
158 /* The waitany and testany request are transformed into a wait or test request over the corresponding communication
159 * action so it can be treated later by the dependence function. */
160 switch (req->call_) {
161 case Simcall::COMM_WAITANY:
162 req->call_ = Simcall::COMM_WAIT;
163 chosen_comm = mc_model_checker->get_remote_simulation().read(
164 remote(simcall_comm_waitany__get__comms(req) + req->mc_value_));
166 mc_model_checker->get_remote_simulation().read(internal_comm, remote(chosen_comm));
167 simcall_comm_wait__set__comm(req, internal_comm.get_buffer());
168 simcall_comm_wait__set__timeout(req, 0);
171 case Simcall::COMM_TESTANY:
172 req->call_ = Simcall::COMM_TEST;
173 chosen_comm = mc_model_checker->get_remote_simulation().read(
174 remote(simcall_comm_testany__get__comms(req) + req->mc_value_));
176 mc_model_checker->get_remote_simulation().read(internal_comm, remote(chosen_comm));
177 simcall_comm_test__set__comm(req, internal_comm.get_buffer());
178 simcall_comm_test__set__result(req, req->mc_value_);
181 case Simcall::COMM_WAIT:
182 chosen_comm = simcall_comm_wait__getraw__comm(req);
183 mc_model_checker->get_remote_simulation().read(internal_comm, remote(chosen_comm));
184 simcall_comm_wait__set__comm(req, internal_comm.get_buffer());
187 case Simcall::COMM_TEST:
188 chosen_comm = simcall_comm_test__getraw__comm(req);
189 mc_model_checker->get_remote_simulation().read(internal_comm, remote(chosen_comm));
190 simcall_comm_test__set__comm(req, internal_comm.get_buffer());
194 /* No translation needed */
199 simgrid::kernel::activity::CommImpl* Api::get_comm(smx_simcall_t const r) const
202 case Simcall::COMM_WAIT:
203 return simcall_comm_wait__getraw__comm(r);
204 case Simcall::COMM_TEST:
205 return simcall_comm_test__getraw__comm(r);
211 /** Statically "upcast" a s_smx_actor_t into an ActorInformation
213 * This gets 'actorInfo' from '&actorInfo->copy'. It upcasts in the
214 * sense that we could achieve the same thing by having ActorInformation
215 * inherit from s_smx_actor_t but we don't really want to do that.
217 simgrid::mc::ActorInformation* Api::actor_info_cast(smx_actor_t actor) const
219 simgrid::mc::ActorInformation temp;
220 std::size_t offset = (char*)temp.copy.get_buffer() - (char*)&temp;
222 auto* process_info = reinterpret_cast<simgrid::mc::ActorInformation*>((char*)actor - offset);
227 bool Api::request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const
229 if (r1->call_ == Simcall::COMM_ISEND && r2->call_ == Simcall::COMM_IRECV)
232 if (r1->call_ == Simcall::COMM_IRECV && r2->call_ == Simcall::COMM_ISEND)
235 // Those are internal requests, we do not need indirection because those objects are copies:
236 const kernel::activity::CommImpl* synchro1 = get_comm(r1);
237 const kernel::activity::CommImpl* synchro2 = get_comm(r2);
239 if ((r1->call_ == Simcall::COMM_ISEND || r1->call_ == Simcall::COMM_IRECV) && r2->call_ == Simcall::COMM_WAIT) {
240 auto mbox = get_mbox_remote_addr(r1);
241 RemotePtr<kernel::activity::MailboxImpl> synchro2_mbox_cpy = remote(synchro2->mbox_cpy);
243 if (mbox != synchro2_mbox_cpy && simcall_comm_wait__get__timeout(r2) <= 0)
246 if ((r1->issuer_ != synchro2->src_actor_.get()) && (r1->issuer_ != synchro2->dst_actor_.get()) &&
247 simcall_comm_wait__get__timeout(r2) <= 0)
250 if ((r1->call_ == Simcall::COMM_ISEND) && (synchro2->type_ == kernel::activity::CommImpl::Type::SEND) &&
251 (synchro2->src_buff_ != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
254 if ((r1->call_ == Simcall::COMM_IRECV) && (synchro2->type_ == kernel::activity::CommImpl::Type::RECEIVE) &&
255 (synchro2->dst_buff_ != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
259 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
262 if((r1->call == Simcall::COMM_ISEND || r1->call == Simcall::COMM_IRECV)
263 && r2->call == Simcall::COMM_TEST)
267 if (r1->call_ == Simcall::COMM_WAIT && (r2->call_ == Simcall::COMM_WAIT || r2->call_ == Simcall::COMM_TEST) &&
268 (synchro1->src_actor_.get() == nullptr || synchro1->dst_actor_.get() == nullptr))
271 if (r1->call_ == Simcall::COMM_TEST &&
272 (simcall_comm_test__get__comm(r1) == nullptr || synchro1->src_buff_ == nullptr || synchro1->dst_buff_ == nullptr))
275 if (r1->call_ == Simcall::COMM_TEST && r2->call_ == Simcall::COMM_WAIT &&
276 synchro1->src_buff_ == synchro2->src_buff_ && synchro1->dst_buff_ == synchro2->dst_buff_)
279 if (r1->call_ == Simcall::COMM_WAIT && r2->call_ == Simcall::COMM_TEST && synchro1->src_buff_ != nullptr &&
280 synchro1->dst_buff_ != nullptr && synchro2->src_buff_ != nullptr && synchro2->dst_buff_ != nullptr &&
281 synchro1->dst_buff_ != synchro2->src_buff_ && synchro1->dst_buff_ != synchro2->dst_buff_ &&
282 synchro2->dst_buff_ != synchro1->src_buff_)
288 xbt::string const& Api::get_actor_host_name(smx_actor_t actor) const
290 if (mc_model_checker == nullptr)
291 return actor->get_host()->get_name();
293 const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
295 // Read the simgrid::xbt::string in the MCed process:
296 simgrid::mc::ActorInformation* info = actor_info_cast(actor);
297 auto remote_string_address =
298 remote(reinterpret_cast<const simgrid::xbt::string_data*>(&actor->get_host()->get_name()));
299 simgrid::xbt::string_data remote_string = process->read(remote_string_address);
300 std::vector<char> hostname(remote_string.len + 1);
301 // no need to read the terminating null byte, and thus hostname[remote_string.len] is guaranteed to be '\0'
302 process->read_bytes(hostname.data(), remote_string.len, remote(remote_string.data));
303 info->hostname = &mc_model_checker->get_host_name(hostname.data());
304 return *info->hostname;
307 std::string Api::get_actor_name(smx_actor_t actor) const
309 if (mc_model_checker == nullptr)
310 return actor->get_cname();
312 const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
314 simgrid::mc::ActorInformation* info = actor_info_cast(actor);
315 if (info->name.empty()) {
316 simgrid::xbt::string_data string_data = simgrid::xbt::string::to_string_data(actor->name_);
317 info->name = process->read_string(remote(string_data.data), string_data.len);
322 std::string Api::get_actor_string(smx_actor_t actor) const
326 res = "(" + std::to_string(actor->get_pid()) + ")";
327 if (actor->get_host())
328 res += std::string(get_actor_host_name(actor)) + " (" + get_actor_name(actor) + ")";
330 res += get_actor_name(actor);
336 std::string Api::get_actor_dot_label(smx_actor_t actor) const
338 std::string res = "(" + std::to_string(actor->get_pid()) + ")";
339 if (actor->get_host())
340 res += get_actor_host_name(actor);
344 void Api::initialize(char** argv) const
346 simgrid::mc::session = new simgrid::mc::Session([argv] {
348 while (argv[i] != nullptr && argv[i][0] == '-')
350 xbt_assert(argv[i] != nullptr,
351 "Unable to find a binary to exec on the command line. Did you only pass config flags?");
352 execvp(argv[i], argv + i);
353 xbt_die("The model-checked process failed to exec(): %s", strerror(errno));
357 std::vector<simgrid::mc::ActorInformation>& Api::get_actors() const
359 return mc_model_checker->get_remote_simulation().actors();
362 bool Api::actor_is_enabled(aid_t pid) const
364 return session->actor_is_enabled(pid);
367 unsigned long Api::get_maxpid() const
369 static const char* name = nullptr;
371 name = "simgrid::kernel::actor::maxpid";
372 if (mc_model_checker->get_remote_simulation().find_variable(name) == nullptr)
373 name = "maxpid"; // We seem to miss the namespaces when compiling with GCC
375 unsigned long maxpid;
376 mc_model_checker->get_remote_simulation().read_variable(name, &maxpid, sizeof(maxpid));
380 int Api::get_actors_size() const
382 return mc_model_checker->get_remote_simulation().actors().size();
385 RemotePtr<kernel::activity::CommImpl> Api::get_comm_isend_raw_addr(smx_simcall_t request) const
387 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(request->result_);
388 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
391 RemotePtr<kernel::activity::CommImpl> Api::get_comm_irecv_raw_addr(smx_simcall_t request) const
393 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(request->result_);
394 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
397 RemotePtr<kernel::activity::CommImpl> Api::get_comm_wait_raw_addr(smx_simcall_t request) const
399 auto comm_addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::CommImpl*>(request->args_[0]);
400 return RemotePtr<kernel::activity::CommImpl>(comm_addr);
403 RemotePtr<kernel::activity::CommImpl> Api::get_comm_waitany_raw_addr(smx_simcall_t request, int value) const
405 auto addr = simgrid::simix::unmarshal_raw<simgrid::kernel::activity::CommImpl**>(request->args_[0]) + value;
406 auto comm_addr = mc_model_checker->get_remote_simulation().read(remote(addr));
407 return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
410 std::string Api::get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const
412 Remote<kernel::activity::CommImpl> temp_synchro;
413 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
414 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
416 char* remote_name = mc_model_checker->get_remote_simulation().read<char*>(RemotePtr<char*>(
417 (uint64_t)(synchro->get_mailbox() ? &synchro->get_mailbox()->get_name() : &synchro->mbox_cpy->get_name())));
418 auto rdv = mc_model_checker->get_remote_simulation().read_string(RemotePtr<char>(remote_name));
422 unsigned long Api::get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
424 Remote<kernel::activity::CommImpl> temp_synchro;
425 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
426 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
428 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(synchro->src_actor_.get()))->get_pid();
432 unsigned long Api::get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
434 Remote<kernel::activity::CommImpl> temp_synchro;
435 mc_model_checker->get_remote_simulation().read(temp_synchro, addr);
436 const kernel::activity::CommImpl* synchro = temp_synchro.get_buffer();
438 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(synchro->dst_actor_.get()))->get_pid();
442 std::vector<char> Api::get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const
444 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
445 mc_model_checker->get_remote_simulation().read(temp_comm, addr);
446 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
448 std::vector<char> buffer{};
449 if (comm->src_buff_ != nullptr) {
450 buffer.resize(comm->src_buff_size_);
451 mc_model_checker->get_remote_simulation().read_bytes(buffer.data(), buffer.size(), remote(comm->src_buff_));
457 bool Api::check_send_request_detached(smx_simcall_t const& simcall) const
459 simgrid::smpi::Request mpi_request;
460 mc_model_checker->get_remote_simulation().read(
461 &mpi_request, remote(static_cast<smpi::Request*>(simcall_comm_isend__get__data(simcall))));
462 return mpi_request.detached();
466 smx_actor_t Api::get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
468 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
469 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
470 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
472 auto src_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->src_actor_.get()));
476 smx_actor_t Api::get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
478 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
479 mc_model_checker->get_remote_simulation().read(temp_comm, comm_addr);
480 const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
482 auto dst_proc = mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(comm->dst_actor_.get()));
486 std::size_t Api::get_remote_heap_bytes() const
488 RemoteSimulation& process = mc_model_checker->get_remote_simulation();
489 auto heap_bytes_used = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
490 return heap_bytes_used;
493 void Api::session_initialize() const
495 session->initialize();
498 void Api::mc_inc_visited_states() const
500 mc_model_checker->visited_states++;
503 void Api::mc_inc_executed_trans() const
505 mc_model_checker->executed_transitions++;
508 unsigned long Api::mc_get_visited_states() const
510 return mc_model_checker->visited_states;
513 unsigned long Api::mc_get_executed_trans() const
515 return mc_model_checker->executed_transitions;
518 void Api::mc_check_deadlock() const
520 if (mc_model_checker->checkDeadlock()) {
522 throw DeadlockError();
526 /** Get the issuer of a simcall (`req->issuer`)
528 * In split-process mode, it does the black magic necessary to get an address
529 * of a (shallow) copy of the data structure the issuer SIMIX actor in the local
532 * @param process the MCed process
533 * @param req the simcall (copied in the local process)
535 smx_actor_t Api::simcall_get_issuer(s_smx_simcall const* req) const
537 xbt_assert(mc_model_checker != nullptr);
539 // This is the address of the smx_actor in the MCed process:
540 auto address = simgrid::mc::remote(req->issuer_);
542 // Lookup by address:
543 for (auto& actor : mc_model_checker->get_remote_simulation().actors())
544 if (actor.address == address)
545 return actor.copy.get_buffer();
546 for (auto& actor : mc_model_checker->get_remote_simulation().dead_actors())
547 if (actor.address == address)
548 return actor.copy.get_buffer();
550 xbt_die("Issuer not found");
553 long Api::simcall_get_actor_id(s_smx_simcall const* req) const
555 return simcall_get_issuer(req)->get_pid();
558 RemotePtr<kernel::activity::MailboxImpl> Api::get_mbox_remote_addr(smx_simcall_t const req) const
560 RemotePtr<kernel::activity::MailboxImpl> mbox_addr;
561 switch (req->call_) {
562 case Simcall::COMM_ISEND:
563 case Simcall::COMM_IRECV:
564 mbox_addr = remote(simix::unmarshal<smx_mailbox_t>(req->args_[1]));
567 mbox_addr = RemotePtr<kernel::activity::MailboxImpl>();
573 RemotePtr<kernel::activity::ActivityImpl> Api::get_comm_remote_addr(smx_simcall_t const req) const
575 RemotePtr<kernel::activity::ActivityImpl> comm_addr;
576 switch (req->call_) {
577 case Simcall::COMM_ISEND:
578 case Simcall::COMM_IRECV:
579 comm_addr = remote(simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(req->result_));
582 comm_addr = RemotePtr<kernel::activity::ActivityImpl>();
588 bool Api::mc_is_null() const
590 auto is_null = (mc_model_checker == nullptr) ? true : false;
594 Checker* Api::mc_get_checker() const
596 return mc_model_checker->getChecker();
599 void Api::set_checker(Checker* const checker) const
601 xbt_assert(mc_model_checker);
602 xbt_assert(mc_model_checker->getChecker() == nullptr);
603 mc_model_checker->setChecker(checker);
606 void Api::handle_simcall(Transition const& transition) const
608 mc_model_checker->handle_simcall(transition);
611 void Api::mc_wait_for_requests() const
613 mc_model_checker->wait_for_requests();
616 void Api::mc_exit(int status) const
618 mc_model_checker->exit(status);
621 void Api::dump_record_path() const
623 simgrid::mc::dumpRecordPath();
626 smx_simcall_t Api::mc_state_choose_request(simgrid::mc::State* state) const
628 for (auto& actor : mc_model_checker->get_remote_simulation().actors()) {
629 /* Only consider the actors that were marked as interleaving by the checker algorithm */
630 if (not state->actor_states_[actor.copy.get_buffer()->get_pid()].is_todo())
633 smx_simcall_t res = MC_state_choose_request_for_process(state, actor.copy.get_buffer());
640 std::list<transition_detail_t> Api::get_enabled_transitions(simgrid::mc::State* state) const
642 std::list<transition_detail_t> tr_list{};
644 for (auto& actor : mc_model_checker->get_remote_simulation().actors()) {
645 auto actor_pid = actor.copy.get_buffer()->get_pid();
646 auto actor_impl = actor.copy.get_buffer();
648 // Only consider the actors that were marked as interleaving by the checker algorithm
649 if (not state->actor_states_[actor_pid].is_todo())
651 // Not executable in the application
652 if (not simgrid::mc::actor_is_enabled(actor_impl))
655 auto transition = std::make_unique<s_transition_detail>();
656 Simcall simcall_call = actor_impl->simcall_.call_;
657 smx_simcall_t simcall = &actor_impl->simcall_;
658 transition->call_ = simcall_call;
659 switch (simcall_call) {
660 case Simcall::COMM_ISEND:
661 case Simcall::COMM_IRECV:
662 transition->mbox_remote_addr = get_mbox_remote_addr(simcall);
663 transition->comm_remote_addr = get_comm_remote_addr(simcall);
669 tr_list.emplace_back(std::move(transition));
675 bool Api::simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const
677 if (req1->issuer_ == req2->issuer_)
680 /* Wait with timeout transitions are not considered by the independence theorem, thus we consider them as dependent
681 * with all other transitions */
682 if ((req1->call_ == Simcall::COMM_WAIT && simcall_comm_wait__get__timeout(req1) > 0) ||
683 (req2->call_ == Simcall::COMM_WAIT && simcall_comm_wait__get__timeout(req2) > 0))
686 if (req1->call_ != req2->call_)
687 return request_depend_asymmetric(req1, req2) && request_depend_asymmetric(req2, req1);
689 // Those are internal requests, we do not need indirection because those objects are copies:
690 const kernel::activity::CommImpl* synchro1 = get_comm(req1);
691 const kernel::activity::CommImpl* synchro2 = get_comm(req2);
693 switch (req1->call_) {
694 case Simcall::COMM_ISEND:
695 return simcall_comm_isend__get__mbox(req1) == simcall_comm_isend__get__mbox(req2);
696 case Simcall::COMM_IRECV:
697 return simcall_comm_irecv__get__mbox(req1) == simcall_comm_irecv__get__mbox(req2);
698 case Simcall::COMM_WAIT:
699 if (synchro1->src_buff_ == synchro2->src_buff_ && synchro1->dst_buff_ == synchro2->dst_buff_)
701 if (synchro1->src_buff_ != nullptr && synchro1->dst_buff_ != nullptr && synchro2->src_buff_ != nullptr &&
702 synchro2->dst_buff_ != nullptr && synchro1->dst_buff_ != synchro2->src_buff_ &&
703 synchro1->dst_buff_ != synchro2->dst_buff_ && synchro2->dst_buff_ != synchro1->src_buff_)
711 std::string Api::request_to_string(smx_simcall_t req, int value) const
713 xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
718 smx_actor_t issuer = simcall_get_issuer(req);
720 if (issuer->simcall_.observer_ != nullptr)
721 return mc_model_checker->simcall_to_string(issuer->get_pid(), value);
723 switch (req->call_) {
724 case Simcall::COMM_ISEND:
726 args = "src=" + get_actor_string(issuer);
727 args += ", buff=" + pointer_to_string(simcall_comm_isend__get__src_buff(req));
728 args += ", size=" + buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
731 case Simcall::COMM_IRECV: {
732 size_t* remote_size = simcall_comm_irecv__get__dst_buff_size(req);
735 mc_model_checker->get_remote_simulation().read_bytes(&size, sizeof(size), remote(remote_size));
738 args = "dst=" + get_actor_string(issuer);
739 args += ", buff=" + pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
740 args += ", size=" + buff_size_to_string(size);
744 case Simcall::COMM_WAIT: {
745 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_wait__getraw__comm(req);
747 type = "WaitTimeout";
748 args = "comm=" + pointer_to_string(remote_act);
752 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
753 const simgrid::kernel::activity::CommImpl* act;
754 mc_model_checker->get_remote_simulation().read(temp_synchro, remote(remote_act));
755 act = temp_synchro.get_buffer();
757 smx_actor_t src_proc =
758 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
759 smx_actor_t dst_proc =
760 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
761 args = "comm=" + pointer_to_string(remote_act);
762 args += " [" + get_actor_string(src_proc) + "-> " + get_actor_string(dst_proc) + "]";
767 case Simcall::COMM_TEST: {
768 simgrid::kernel::activity::CommImpl* remote_act = simcall_comm_test__getraw__comm(req);
769 simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
770 const simgrid::kernel::activity::CommImpl* act;
771 mc_model_checker->get_remote_simulation().read(temp_synchro, remote(remote_act));
772 act = temp_synchro.get_buffer();
774 if (act->src_actor_.get() == nullptr || act->dst_actor_.get() == nullptr) {
776 args = "comm=" + pointer_to_string(remote_act);
780 smx_actor_t src_proc =
781 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->src_actor_.get()));
782 smx_actor_t dst_proc =
783 mc_model_checker->get_remote_simulation().resolve_actor(simgrid::mc::remote(act->dst_actor_.get()));
784 args = "comm=" + pointer_to_string(remote_act);
785 args += " [" + get_actor_string(src_proc) + " -> " + get_actor_string(dst_proc) + "]";
790 case Simcall::COMM_WAITANY: {
792 size_t count = simcall_comm_waitany__get__count(req);
794 simgrid::kernel::activity::CommImpl* remote_sync;
796 mc_model_checker->get_remote_simulation().read(remote(simcall_comm_waitany__get__comms(req) + value));
797 args = "comm=" + pointer_to_string(remote_sync) + xbt::string_printf("(%d of %zu)", value + 1, count);
799 args = "comm at idx " + std::to_string(value);
803 case Simcall::COMM_TESTANY:
805 type = "TestAny FALSE";
809 args = xbt::string_printf("(%d of %zu)", value + 1, simcall_comm_testany__get__count(req));
814 type = SIMIX_simcall_name(req->call_);
819 return "[" + get_actor_string(issuer) + "] " + type + "(" + args + ")";
822 std::string Api::request_get_dot_output(smx_simcall_t req, int value) const
824 const smx_actor_t issuer = simcall_get_issuer(req);
825 const char* color = get_color(issuer->get_pid() - 1);
829 if (req->observer_ != nullptr) {
830 label = mc_model_checker->simcall_dot_label(issuer->get_pid(), value);
832 switch (req->call_) {
833 case Simcall::COMM_ISEND:
834 label = "[" + get_actor_dot_label(issuer) + "] iSend";
837 case Simcall::COMM_IRECV:
838 label = "[" + get_actor_dot_label(issuer) + "] iRecv";
841 case Simcall::COMM_WAIT:
843 label = "[" + get_actor_dot_label(issuer) + "] WaitTimeout";
845 kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req);
846 Remote<kernel::activity::CommImpl> temp_comm;
847 mc_model_checker->get_remote_simulation().read(temp_comm,
848 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
849 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
851 const kernel::actor::ActorImpl* src_proc =
852 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->src_actor_.get()));
853 const kernel::actor::ActorImpl* dst_proc =
854 mc_model_checker->get_remote_simulation().resolve_actor(mc::remote(comm->dst_actor_.get()));
855 label = "[" + get_actor_dot_label(issuer) + "] Wait";
856 label += " [(" + std::to_string(src_proc ? src_proc->get_pid() : 0) + ")";
857 label += "->(" + std::to_string(dst_proc ? dst_proc->get_pid() : 0) + ")]";
861 case Simcall::COMM_TEST: {
862 kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req);
863 Remote<simgrid::kernel::activity::CommImpl> temp_comm;
864 mc_model_checker->get_remote_simulation().read(temp_comm,
865 remote(static_cast<kernel::activity::CommImpl*>(remote_act)));
866 const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
867 if (comm->src_actor_.get() == nullptr || comm->dst_actor_.get() == nullptr) {
868 label = "[" + get_actor_dot_label(issuer) + "] Test FALSE";
870 label = "[" + get_actor_dot_label(issuer) + "] Test TRUE";
875 case Simcall::COMM_WAITANY:
876 label = "[" + get_actor_dot_label(issuer) + "] WaitAny";
877 label += xbt::string_printf(" [%d of %zu]", value + 1, simcall_comm_waitany__get__count(req));
880 case Simcall::COMM_TESTANY:
882 label = "[" + get_actor_dot_label(issuer) + "] TestAny FALSE";
884 label = "[" + get_actor_dot_label(issuer) + "] TestAny TRUE";
885 label += xbt::string_printf(" [%d of %zu]", value + 1, simcall_comm_testany__get__count(req));
893 return "label = \"" + label + "\", color = " + color + ", fontcolor = " + color;
897 int Api::get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const
899 simgrid::smpi::Request mpi_request;
900 void* simcall_data = nullptr;
901 if (type == Simcall::COMM_ISEND)
902 simcall_data = simcall_comm_isend__get__data(simcall);
903 else if (type == Simcall::COMM_IRECV)
904 simcall_data = simcall_comm_irecv__get__data(simcall);
905 mc_model_checker->get_remote_simulation().read(&mpi_request, remote(static_cast<smpi::Request*>(simcall_data)));
906 return mpi_request.tag();
910 void Api::restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const
912 system_state->restore(&mc_model_checker->get_remote_simulation());
915 void Api::log_state() const
917 session->log_state();
920 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
922 return simgrid::mc::snapshot_equal(s1, s2);
925 simgrid::mc::Snapshot* Api::take_snapshot(int num_state) const
927 auto snapshot = new simgrid::mc::Snapshot(num_state);
931 void Api::s_close() const
936 void Api::restore_initial_state() const
938 session->restore_initial_state();
941 void Api::execute(Transition& transition, smx_simcall_t simcall) const
943 /* FIXME: once all simcalls have observers, kill the simcall parameter and use mc_model_checker->simcall_to_string() */
944 transition.textual = request_to_string(simcall, transition.times_considered_);
945 session->execute(transition);
949 void Api::automaton_load(const char* file) const
951 MC_automaton_load(file);
955 std::vector<int> Api::automaton_propositional_symbol_evaluate() const
957 unsigned int cursor = 0;
958 std::vector<int> values;
959 xbt_automaton_propositional_symbol_t ps = nullptr;
960 xbt_dynar_foreach (mc::property_automaton->propositional_symbols, cursor, ps)
961 values.push_back(xbt_automaton_propositional_symbol_evaluate(ps));
965 std::vector<xbt_automaton_state_t> Api::get_automaton_state() const
967 std::vector<xbt_automaton_state_t> automaton_stack;
968 unsigned int cursor = 0;
969 xbt_automaton_state_t automaton_state;
970 xbt_dynar_foreach (mc::property_automaton->states, cursor, automaton_state)
971 if (automaton_state->type == -1)
972 automaton_stack.push_back(automaton_state);
973 return automaton_stack;
976 int Api::compare_automaton_exp_label(const xbt_automaton_exp_label* l) const
978 unsigned int cursor = 0;
979 xbt_automaton_propositional_symbol_t p = nullptr;
980 xbt_dynar_foreach (simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
981 if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
987 void Api::set_property_automaton(xbt_automaton_state_t const& automaton_state) const
989 mc::property_automaton->current_state = automaton_state;
992 xbt_automaton_exp_label_t Api::get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const
994 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
995 return transition->label;
998 xbt_automaton_state_t Api::get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const
1000 const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
1001 return transition->dst;
1005 } // namespace simgrid