X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d2f9b51fd9b5726667a0cbe288d8c99eb12229bc..d76599052f7eb659641d0b981c04f99d5f735a14:/src/mc/api/TransitionComm.cpp diff --git a/src/mc/api/TransitionComm.cpp b/src/mc/api/TransitionComm.cpp index 1e38480abe..28962dec09 100644 --- a/src/mc/api/TransitionComm.cpp +++ b/src/mc/api/TransitionComm.cpp @@ -20,24 +20,23 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition, namespace simgrid { namespace mc { -CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, char* buffer) - : Transition(issuer, times_considered) +CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::COMM_WAIT, issuer, times_considered) { - std::stringstream stream(buffer); stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_; XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_); } -std::string CommWaitTransition::to_string(bool verbose) +std::string CommWaitTransition::to_string(bool verbose) const { - textual_ = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_, + auto res = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_, (timeout_ ? "timeout" : "no timeout")); if (verbose) { - textual_ += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); - textual_ += ", dst_buff=" + xbt::string_printf("%p", dst_buff_); + res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); + res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_); } - textual_ += ")"; - return textual_; + res += ")"; + return res; } bool CommWaitTransition::depends(const Transition* other) const { @@ -47,16 +46,18 @@ bool CommWaitTransition::depends(const Transition* other) const if (dynamic_cast(other) != nullptr) return false; // Random is indep with any transition + if (auto* recv = dynamic_cast(other)) + return recv->depends(this); + if (auto* send = dynamic_cast(other)) return send->depends(this); - if (auto* recv = dynamic_cast(other)) - return recv->depends(this); + if (auto* test = dynamic_cast(other)) + return test->depends(this); - /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */ if (const auto* wait = dynamic_cast(other)) { if (timeout_ || wait->timeout_) - return true; + return true; // Timeouts are not considered by the independence theorem, thus assumed dependent if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_) return false; @@ -67,20 +68,63 @@ bool CommWaitTransition::depends(const Transition* other) const return true; } +CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::COMM_TEST, issuer, times_considered) +{ + stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_; + XBT_DEBUG("CommTestTransition comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", comm_, sender_, + receiver_, mbox_, src_buff_, dst_buff_, size_); +} +std::string CommTestTransition::to_string(bool verbose) const +{ + auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_); + if (verbose) { + res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); + res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_); + } + res += ")"; + return res; +} +bool CommTestTransition::depends(const Transition* other) const +{ + if (aid_ == other->aid_) + return false; + + if (dynamic_cast(other) != nullptr) + return false; // Test & Random are independent (Random is independent with anything) + + if (auto* recv = dynamic_cast(other)) + return recv->depends(this); // Recv < Test (alphabetical ordering) + + if (auto* send = dynamic_cast(other)) + return send->depends(this); // Send < Test (alphabetical ordering) + + if (dynamic_cast(other) != nullptr) + return false; // Test & Test are independent + + if (const auto* wait = dynamic_cast(other)) { + if (wait->timeout_) + return true; // Timeouts are not considered by the independence theorem, thus assumed dependent + + /* Wait & Test are independent */ + return false; + } + + return true; +} -CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer) - : Transition(issuer, times_considered) +CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::COMM_RECV, issuer, times_considered) { - std::stringstream stream(buffer); stream >> mbox_ >> dst_buff_; } -std::string CommRecvTransition::to_string(bool verbose) +std::string CommRecvTransition::to_string(bool verbose) const { - textual_ = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_); + auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_); if (verbose) - textual_ += ", buff=" + xbt::string_printf("%p", dst_buff_); - textual_ += ")"; - return textual_; + res += ", buff=" + xbt::string_printf("%p", dst_buff_); + res += ")"; + return res; } bool CommRecvTransition::depends(const Transition* other) const { @@ -90,11 +134,19 @@ bool CommRecvTransition::depends(const Transition* other) const if (dynamic_cast(other) != nullptr) return false; // Random is indep with any transition - if (const auto* other_irecv = dynamic_cast(other)) - return mbox_ == other_irecv->mbox_; + if (const auto* recv = dynamic_cast(other)) + return mbox_ == recv->mbox_; + + if (dynamic_cast(other) != nullptr) + return false; + + if (const auto* test = dynamic_cast(other)) { + if (mbox_ != test->mbox_) + return false; - if (auto* isend = dynamic_cast(other)) - return isend->depends(this); + if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->dst_buff_ != dst_buff_)) + return false; + } if (auto* wait = dynamic_cast(other)) { if (wait->timeout_) @@ -103,38 +155,51 @@ bool CommRecvTransition::depends(const Transition* other) const if (mbox_ != wait->mbox_) return false; - if ((aid_ != wait->sender_) && (aid_ != wait->receiver_)) - return false; - - if (wait->dst_buff_ != dst_buff_) + if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->dst_buff_ != dst_buff_)) return false; } - /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the - * test call. */ -#if 0 - if (dynamic_cast(other)) - return false; -#endif - return true; } -CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer) - : Transition(issuer, times_considered) +CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::COMM_SEND, issuer, times_considered) { - std::stringstream stream(buffer); stream >> mbox_ >> src_buff_ >> size_; XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_); } -std::string CommSendTransition::to_string(bool verbose = false) +std::string CommSendTransition::to_string(bool verbose = false) const { - textual_ = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_); + auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_); if (verbose) - textual_ += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); - textual_ += ")"; - return textual_; + res += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); + res += ")"; + return res; +} +TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::TESTANY, issuer, times_considered) +{ + int size; + stream >> size; + for (int i = 0; i < size; i++) { + + Transition* t = recv_transition(issuer, 0, stream); + transitions_.push_back(t); + } +} +std::string TestAnyTransition::to_string(bool verbose) const +{ + auto res = xbt::string_printf("%ld: TestAny{ ", aid_); + for (auto const* t : transitions_) + res += t->to_string(verbose); + res += "}"; + return res; } +bool TestAnyTransition::depends(const Transition* other) const +{ + return true; +} + bool CommSendTransition::depends(const Transition* other) const { if (aid_ == other->aid_) @@ -146,10 +211,17 @@ bool CommSendTransition::depends(const Transition* other) const if (const auto* other_isend = dynamic_cast(other)) return mbox_ == other_isend->mbox_; - // FIXME: Not in the former dependency check because of the ordering but seems logical to add it if (dynamic_cast(other) != nullptr) return false; + if (const auto* test = dynamic_cast(other)) { + if (mbox_ != test->mbox_) + return false; + + if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->src_buff_ != src_buff_)) + return false; + } + if (const auto* wait = dynamic_cast(other)) { if (wait->timeout_) return true; @@ -157,42 +229,42 @@ bool CommSendTransition::depends(const Transition* other) const if (mbox_ != wait->mbox_) return false; - if ((aid_ != wait->sender_) && (aid_ != wait->receiver_)) - return false; - - if (wait->src_buff_ != src_buff_) + if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->src_buff_ != src_buff_)) return false; } - /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the - * test call. */ -#if 0 - if (dynamic_cast(other)) - return false; -#endif - return true; } -Transition* recv_transition(aid_t issuer, int times_considered, kernel::actor::SimcallObserver::Simcall simcall, - char* buffer) +Transition* recv_transition(aid_t issuer, int times_considered, std::stringstream& stream) { + short type; + stream >> type; + xbt_assert(type >= 0 && type <= static_cast(Transition::Type::UNKNOWN), "Invalid transition type %d received", + type); + + auto simcall = static_cast(type); + switch (simcall) { - case kernel::actor::SimcallObserver::Simcall::COMM_WAIT: - return new CommWaitTransition(issuer, times_considered, buffer); - case kernel::actor::SimcallObserver::Simcall::IRECV: - return new CommRecvTransition(issuer, times_considered, buffer); - case kernel::actor::SimcallObserver::Simcall::ISEND: - return new CommSendTransition(issuer, times_considered, buffer); - - case kernel::actor::SimcallObserver::Simcall::RANDOM: - return new RandomTransition(issuer, times_considered, buffer); - - case kernel::actor::SimcallObserver::Simcall::UNKNOWN: - return new Transition(issuer, times_considered); - default: - xbt_die("recv_transition of type %s unimplemented", kernel::actor::SimcallObserver::to_c_str(simcall)); + case Transition::Type::COMM_RECV: + return new CommRecvTransition(issuer, times_considered, stream); + case Transition::Type::COMM_SEND: + return new CommSendTransition(issuer, times_considered, stream); + case Transition::Type::COMM_TEST: + return new CommTestTransition(issuer, times_considered, stream); + case Transition::Type::COMM_WAIT: + return new CommWaitTransition(issuer, times_considered, stream); + + case Transition::Type::TESTANY: + return new TestAnyTransition(issuer, times_considered, stream); + + case Transition::Type::RANDOM: + return new RandomTransition(issuer, times_considered, stream); + + case Transition::Type::UNKNOWN: + return new Transition(Transition::Type::UNKNOWN, issuer, times_considered); } + THROW_IMPOSSIBLE; // Some compilers don't detect that each branch of the above switch has a return } } // namespace mc