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/Transition.hpp"
7 #include "src/mc/ModelChecker.hpp"
8 #include "src/mc/Session.hpp"
9 #include "src/mc/mc_state.hpp"
10 #include "src/mc/remote/RemoteProcess.hpp"
11 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
19 unsigned long Transition::executed_transitions_ = 0;
20 unsigned long Transition::replayed_transitions_ = 0;
22 std::string Transition::to_string(bool verbose)
24 xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
28 const char* Transition::to_cstring(bool verbose)
30 xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
33 return textual_.c_str();
35 void Transition::init(aid_t aid, int times_considered)
38 times_considered_ = times_considered;
40 void Transition::replay() const
42 replayed_transitions_++;
44 mc_model_checker->handle_simcall(*this, false);
45 mc_model_checker->wait_for_requests();
48 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, char* buffer)
49 : Transition(issuer, times_considered)
51 std::stringstream stream(buffer);
52 stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
53 XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu",
54 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_);
56 std::string CommWaitTransition::to_string(bool verbose)
58 textual_ = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_,
59 (timeout_ ? "timeout" : "no timeout"));
61 textual_ += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
62 textual_ += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
67 bool CommWaitTransition::depends(const Transition* other) const
69 if (aid_ == other->aid_)
72 if (auto* send = dynamic_cast<const CommSendTransition*>(other))
73 return send->depends(this);
75 if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
76 return recv->depends(this);
78 /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */
79 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
80 if (timeout_ || wait->timeout_)
83 if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
85 if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
86 dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
93 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
94 : Transition(issuer, times_considered)
96 std::stringstream stream(buffer);
97 stream >> mbox_ >> dst_buff_;
99 std::string CommRecvTransition::to_string(bool verbose)
101 textual_ = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
103 textual_ += ", buff=" + xbt::string_printf("%p", dst_buff_);
107 bool CommRecvTransition::depends(const Transition* other) const
109 if (aid_ == other->aid_)
112 if (const auto* other_irecv = dynamic_cast<const CommRecvTransition*>(other))
113 return mbox_ == other_irecv->mbox_;
115 if (auto* isend = dynamic_cast<const CommSendTransition*>(other))
116 return isend->depends(this);
118 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
122 if (mbox_ != wait->mbox_)
125 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
128 if (wait->dst_buff_ != dst_buff_)
132 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
135 if (dynamic_cast<ActivityTestSimcall*>(other))
142 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
143 : Transition(issuer, times_considered)
145 std::stringstream stream(buffer);
146 stream >> mbox_ >> src_buff_ >> size_;
147 XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_);
149 std::string CommSendTransition::to_string(bool verbose = false)
151 textual_ = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
153 textual_ += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
157 bool CommSendTransition::depends(const Transition* other) const
159 if (aid_ == other->aid_)
162 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
163 return mbox_ == other_isend->mbox_;
165 // FIXME: Not in the former dependency check because of the ordering but seems logical to add it
166 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
169 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
173 if (mbox_ != wait->mbox_)
176 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
179 if (wait->src_buff_ != src_buff_)
183 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
186 if (dynamic_cast<ActivityTestSimcall*>(other))
193 Transition* recv_transition(aid_t issuer, int times_considered, kernel::actor::SimcallObserver::Simcall simcall,
197 case kernel::actor::SimcallObserver::Simcall::COMM_WAIT:
198 return new CommWaitTransition(issuer, times_considered, buffer);
199 case kernel::actor::SimcallObserver::Simcall::IRECV:
200 return new CommRecvTransition(issuer, times_considered, buffer);
201 case kernel::actor::SimcallObserver::Simcall::ISEND:
202 return new CommSendTransition(issuer, times_considered, buffer);
203 case kernel::actor::SimcallObserver::Simcall::UNKNOWN:
204 return new Transition(issuer, times_considered);
206 xbt_die("recv_transition of type %s unimplemented", kernel::actor::SimcallObserver::to_c_str(simcall));
211 } // namespace simgrid