1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/TransitionComm.hpp"
7 #include "src/mc/Transition.hpp"
8 #include "xbt/asserts.h"
9 #include <simgrid/config.h>
11 #include "src/mc/ModelChecker.hpp"
12 #include "src/mc/Session.hpp"
13 #include "src/mc/mc_state.hpp"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
19 "Logging specific to MC transitions about communications");
24 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, char* buffer)
25 : Transition(issuer, times_considered)
27 std::stringstream stream(buffer);
28 stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
29 XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu",
30 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_);
32 std::string CommWaitTransition::to_string(bool verbose)
34 textual_ = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_,
35 (timeout_ ? "timeout" : "no timeout"));
37 textual_ += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
38 textual_ += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
43 bool CommWaitTransition::depends(const Transition* other) const
45 if (aid_ == other->aid_)
48 if (auto* send = dynamic_cast<const CommSendTransition*>(other))
49 return send->depends(this);
51 if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
52 return recv->depends(this);
54 /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */
55 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
56 if (timeout_ || wait->timeout_)
59 if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
61 if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
62 dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
69 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
70 : Transition(issuer, times_considered)
72 std::stringstream stream(buffer);
73 stream >> mbox_ >> dst_buff_;
75 std::string CommRecvTransition::to_string(bool verbose)
77 textual_ = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
79 textual_ += ", buff=" + xbt::string_printf("%p", dst_buff_);
83 bool CommRecvTransition::depends(const Transition* other) const
85 if (aid_ == other->aid_)
88 if (const auto* other_irecv = dynamic_cast<const CommRecvTransition*>(other))
89 return mbox_ == other_irecv->mbox_;
91 if (auto* isend = dynamic_cast<const CommSendTransition*>(other))
92 return isend->depends(this);
94 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
98 if (mbox_ != wait->mbox_)
101 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
104 if (wait->dst_buff_ != dst_buff_)
108 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
111 if (dynamic_cast<ActivityTestSimcall*>(other))
118 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
119 : Transition(issuer, times_considered)
121 std::stringstream stream(buffer);
122 stream >> mbox_ >> src_buff_ >> size_;
123 XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_);
125 std::string CommSendTransition::to_string(bool verbose = false)
127 textual_ = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
129 textual_ += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
133 bool CommSendTransition::depends(const Transition* other) const
135 if (aid_ == other->aid_)
138 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
139 return mbox_ == other_isend->mbox_;
141 // FIXME: Not in the former dependency check because of the ordering but seems logical to add it
142 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
145 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
149 if (mbox_ != wait->mbox_)
152 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
155 if (wait->src_buff_ != src_buff_)
159 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
162 if (dynamic_cast<ActivityTestSimcall*>(other))
169 Transition* recv_transition(aid_t issuer, int times_considered, kernel::actor::SimcallObserver::Simcall simcall,
173 case kernel::actor::SimcallObserver::Simcall::COMM_WAIT:
174 return new CommWaitTransition(issuer, times_considered, buffer);
175 case kernel::actor::SimcallObserver::Simcall::IRECV:
176 return new CommRecvTransition(issuer, times_considered, buffer);
177 case kernel::actor::SimcallObserver::Simcall::ISEND:
178 return new CommSendTransition(issuer, times_considered, buffer);
179 case kernel::actor::SimcallObserver::Simcall::UNKNOWN:
180 return new Transition(issuer, times_considered);
182 xbt_die("recv_transition of type %s unimplemented", kernel::actor::SimcallObserver::to_c_str(simcall));
187 } // namespace simgrid