#include "src/mc/remote/RemoteProcess.hpp"
#include "xbt/asserts.h"
+#include <sstream>
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
namespace simgrid {
namespace mc {
unsigned long Transition::executed_transitions_ = 0;
+unsigned long Transition::replayed_transitions_ = 0;
-std::string Transition::to_string() const
+std::string Transition::to_string(bool verbose)
{
xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
return textual_;
}
-RemotePtr<simgrid::kernel::actor::SimcallObserver> Transition::execute(simgrid::mc::State* state, int next)
+const char* Transition::to_cstring(bool verbose)
+{
+ xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
+
+ to_string();
+ return textual_.c_str();
+}
+void Transition::init(aid_t aid, int times_considered)
+{
+ aid_ = aid;
+ times_considered_ = times_considered;
+}
+void Transition::replay() const
+{
+ replayed_transitions_++;
+
+ mc_model_checker->handle_simcall(*this, false);
+ mc_model_checker->wait_for_requests();
+}
+
+CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, char* buffer)
+ : Transition(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::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
-
- kernel::actor::ActorImpl* actor = actors[next].copy.get_buffer();
- aid_t aid = actor->get_pid();
- int times_considered;
-
- simgrid::mc::ActorState* actor_state = &state->actor_states_[aid];
- /* This actor is ready to be executed. Prepare its execution when simcall_handle will be called on it */
- if (actor->simcall_.observer_ != nullptr) {
- times_considered = actor_state->get_times_considered_and_inc();
- if (actor->simcall_.mc_max_consider_ <= actor_state->get_times_considered())
- actor_state->set_done();
- } else {
- times_considered = 0;
- actor_state->set_done();
+ textual_ = 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_);
}
+ textual_ += ")";
+ return textual_;
+}
+bool CommWaitTransition::depends(const Transition* other) const
+{
+ if (aid_ == other->aid_)
+ return false;
+
+ if (auto* send = dynamic_cast<const CommSendTransition*>(other))
+ return send->depends(this);
- times_considered_ = times_considered;
- aid_ = aid;
- state->executed_req_ = actor->simcall_;
+ if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
+ return recv->depends(this);
+
+ /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */
+ if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
+ if (timeout_ || wait->timeout_)
+ return true;
+
+ if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
+ return false;
+ if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
+ dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
+ return false;
+ }
- textual_ = mc_model_checker->simcall_to_string(aid_, times_considered_);
- XBT_DEBUG("Let's run actor %ld, going for transition %s", aid, textual_.c_str());
+ return true;
+}
- return replay();
+CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
+ : Transition(issuer, times_considered)
+{
+ std::stringstream stream(buffer);
+ stream >> mbox_ >> dst_buff_;
}
-RemotePtr<simgrid::kernel::actor::SimcallObserver> Transition::replay() const
+std::string CommRecvTransition::to_string(bool verbose)
{
- executed_transitions_++;
+ textual_ = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
+ if (verbose)
+ textual_ += ", buff=" + xbt::string_printf("%p", dst_buff_);
+ textual_ += ")";
+ return textual_;
+}
+bool CommRecvTransition::depends(const Transition* other) const
+{
+ if (aid_ == other->aid_)
+ return false;
- simgrid::mc::RemotePtr<simgrid::kernel::actor::SimcallObserver> res = mc_model_checker->handle_simcall(*this);
- mc_model_checker->wait_for_requests();
+ if (const auto* other_irecv = dynamic_cast<const CommRecvTransition*>(other))
+ return mbox_ == other_irecv->mbox_;
+
+ if (auto* isend = dynamic_cast<const CommSendTransition*>(other))
+ return isend->depends(this);
- return res;
+ if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
+ if (wait->timeout_)
+ return true;
+
+ if (mbox_ != wait->mbox_)
+ return false;
+
+ if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
+ return false;
+
+ if (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<ActivityTestSimcall*>(other))
+ return false;
+#endif
+
+ return true;
+}
+
+CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
+ : Transition(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)
+{
+ textual_ = 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_;
+}
+bool CommSendTransition::depends(const Transition* other) const
+{
+ if (aid_ == other->aid_)
+ return false;
+
+ if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(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<const CommRecvTransition*>(other) != nullptr)
+ return false;
+
+ if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
+ if (wait->timeout_)
+ return true;
+
+ if (mbox_ != wait->mbox_)
+ return false;
+
+ if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
+ return false;
+
+ if (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<ActivityTestSimcall*>(other))
+ return false;
+#endif
+
+ return true;
+}
+
+Transition* recv_transition(aid_t issuer, int times_considered, kernel::actor::SimcallObserver::Simcall simcall,
+ char* buffer)
+{
+ 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::UNKNOWN:
+ return new Transition(issuer, times_considered);
+ default:
+ xbt_die("recv_transition of type %s unimplemented", kernel::actor::SimcallObserver::to_c_str(simcall));
+ }
}
} // namespace mc