Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: Give an ID to comms to not use their pointer value, that can be reused over time
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 15 Jun 2023 15:58:16 +0000 (17:58 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 15 Jun 2023 18:58:18 +0000 (20:58 +0200)
Not doing so made the dependency architecture- and system- dependent:
if a pointer address got reused for another comm, that would have
impacted the depends() result on the MC side.

src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/kernel/actor/CommObserver.cpp
src/mc/explo/udpor/ExtensionSetCalculator.cpp
src/mc/transition/TransitionComm.cpp
src/mc/transition/TransitionComm.hpp

index 7452071..f3b7f48 100644 (file)
@@ -21,6 +21,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_network, kernel, "Kernel network-related syn
 
 namespace simgrid::kernel::activity {
 
+unsigned CommImpl::next_id_ = 0;
+
 std::function<void(CommImpl*, void*, size_t)> CommImpl::copy_data_callback_ = [](kernel::activity::CommImpl* comm,
                                                                                  void* buff, size_t buff_size) {
   xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
index 340a19d..a096940 100644 (file)
@@ -32,6 +32,9 @@ class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
   s4u::Host* to_     = nullptr; /* Otherwise, computed at start() time from the actors */
   CommImplType type_ = CommImplType::SEND; /* Type of the communication (SEND or RECEIVE) */
 
+  static unsigned next_id_;        // Next ID to be given (for MC)
+  const unsigned id_ = ++next_id_; // ID of this comm (for MC) -- 0 as an ID denotes "invalid/unknown comm"
+
 public:
   CommImpl() = default;
 
@@ -52,7 +55,8 @@ public:
 
   double get_rate() const { return rate_; }
   MailboxImpl* get_mailbox() const { return mbox_; }
-  long get_mailbox_id() const { return mbox_id_; }
+  unsigned get_mailbox_id() const { return mbox_id_; }
+  unsigned get_id() const { return id_; }
   bool is_detached() const { return detached_; }
   bool is_assigned() const { return (to_ != nullptr && from_ != nullptr); }
 
index d330caf..6975bc3 100644 (file)
@@ -42,7 +42,7 @@ static void serialize_activity_test(const activity::ActivityImpl* act, std::stri
 {
   if (const auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     stream << "  " << (short)mc::Transition::Type::COMM_TEST;
-    stream << ' ' << (uintptr_t)comm;
+    stream << ' ' << comm->get_id();
     stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
     stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
     stream << ' ' << comm->get_mailbox_id();
@@ -56,7 +56,7 @@ static std::string to_string_activity_test(const activity::ActivityImpl* act)
   if (const auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     const std::string src_buff_id = ptr_to_id<unsigned char>(comm->src_buff_);
     const std::string dst_buff_id = ptr_to_id<unsigned char>(comm->dst_buff_);
-    return "CommTest(comm_id:" + ptr_to_id<activity::CommImpl const>(comm) +
+    return "CommTest(comm_id:" + std::to_string(comm->get_id()) +
            " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) +
            " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) +
            " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id +
@@ -94,7 +94,7 @@ static void serialize_activity_wait(const activity::ActivityImpl* act, bool time
 {
   if (const auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     stream << (short)mc::Transition::Type::COMM_WAIT << ' ';
-    stream << timeout << ' ' << (uintptr_t)comm;
+    stream << timeout << ' ' << comm->get_id();
 
     stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
     stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
@@ -109,7 +109,7 @@ static std::string to_string_activity_wait(const activity::ActivityImpl* act)
   if (const auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     const std::string src_buff_id = ptr_to_id<unsigned char>(comm->src_buff_);
     const std::string dst_buff_id = ptr_to_id<unsigned char>(comm->dst_buff_);
-    return "CommWait(comm_id:" + ptr_to_id<activity::CommImpl const>(comm) +
+    return "CommWait(comm_id:" + std::to_string(comm->get_id()) +
            " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) +
            " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) +
            " mbox:" + (comm->get_mailbox() == nullptr ? "-" : comm->get_mailbox()->get_name()) +
@@ -199,14 +199,14 @@ void CommIsendSimcall::serialize(std::stringstream& stream) const
 {
   /* Note that the comm_ is 0 until after the execution of the simcall */
   stream << (short)mc::Transition::Type::COMM_ASYNC_SEND << ' ';
-  stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)src_buff_ << ' ' << src_buff_size_ << ' '
-         << tag_;
+  stream << (comm_ ? comm_->get_id() : 0) << ' ' << mbox_->get_id() << ' ' << (uintptr_t)src_buff_ << ' '
+         << src_buff_size_ << ' ' << tag_;
   XBT_DEBUG("SendObserver comm:%p mbox:%u buff:%p size:%zu tag:%d", comm_, mbox_->get_id(), src_buff_, src_buff_size_,
             tag_);
 }
 std::string CommIsendSimcall::to_string() const
 {
-  return "CommAsyncSend(comm_id: " + std::to_string((uintptr_t)comm_) + " mbox:" + std::to_string(mbox_->get_id()) +
+  return "CommAsyncSend(comm_id: " + std::to_string(comm_->get_id()) + " mbox:" + std::to_string(mbox_->get_id()) +
          " srcbuf:" + ptr_to_id<unsigned char>(src_buff_) + " bufsize:" + std::to_string(src_buff_size_) +
          " tag: " + std::to_string(tag_) + ")";
 }
@@ -215,14 +215,13 @@ void CommIrecvSimcall::serialize(std::stringstream& stream) const
 {
   /* Note that the comm_ is 0 until after the execution of the simcall */
   stream << (short)mc::Transition::Type::COMM_ASYNC_RECV << ' ';
-  stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)dst_buff_ << ' ' << tag_;
+  stream << (comm_ ? comm_->get_id() : 0) << ' ' << mbox_->get_id() << ' ' << (uintptr_t)dst_buff_ << ' ' << tag_;
   XBT_DEBUG("RecvObserver comm:%p mbox:%u buff:%p tag:%d", comm_, mbox_->get_id(), dst_buff_, tag_);
 }
 std::string CommIrecvSimcall::to_string() const
 {
-  return "CommAsyncRecv(comm_id: " + ptr_to_id<activity::CommImpl const>(comm_) +
-         " mbox:" + std::to_string(mbox_->get_id()) + " dstbuf:" + ptr_to_id<unsigned char>(dst_buff_) +
-         " tag: " + std::to_string(tag_) + ")";
+  return "CommAsyncRecv(comm_id: " + std::to_string(comm_->get_id()) + " mbox:" + std::to_string(mbox_->get_id()) +
+         " dstbuf:" + ptr_to_id<unsigned char>(dst_buff_) + " tag: " + std::to_string(tag_) + ")";
 }
 
 } // namespace simgrid::kernel::actor
index d9d8e26..deeec23 100644 (file)
@@ -166,7 +166,7 @@ EventSet ExtensionSetCalculator::partially_extend_CommWait(const Configuration&
   });
   xbt_assert(issuer != C.end(),
              "Invariant violation! A (supposedly) enabled `CommWait` transition "
-             "waiting on communication %lu should not be enabled: the receive/send "
+             "waiting on communication %u should not be enabled: the receive/send "
              "transition which generated the communication is not an action taken "
              "to reach state(C) (the state of the configuration), which should "
              "be an impossibility if `%s` is enabled. Please report this as "
@@ -409,7 +409,7 @@ EventSet ExtensionSetCalculator::partially_extend_CommTest(const Configuration&
   });
   xbt_assert(issuer != C.end(),
              "An enabled `CommTest` transition (%s) is testing a communication"
-             "%lu not created by a receive/send "
+             "%u not created by a receive/send "
              "transition. SimGrid cannot currently handle test actions "
              "under which a test is performed on a communication that was "
              "not directly created by a receive/send operation of the same actor.",
index c9fe6bc..65d45cc 100644 (file)
@@ -18,15 +18,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
 
 namespace simgrid::mc {
 
-CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, uintptr_t comm_,
-                                       aid_t sender_, aid_t receiver_, unsigned mbox_, uintptr_t sbuff_,
-                                       uintptr_t rbuff_, size_t size_)
+CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, unsigned comm_, aid_t sender_,
+                                       aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
+                                       size_t size_)
     : Transition(Type::COMM_WAIT, issuer, times_considered)
     , timeout_(timeout_)
     , comm_(comm_)
+    , mbox_(mbox_)
     , sender_(sender_)
     , receiver_(receiver_)
-    , mbox_(mbox_)
     , sbuff_(sbuff_)
     , rbuff_(rbuff_)
     , size_(size_)
@@ -36,8 +36,8 @@ CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::
     : Transition(Type::COMM_WAIT, issuer, times_considered)
 {
   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
-  XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
-            " rbuff:%" PRIxPTR " size:%zu",
+  XBT_DEBUG("CommWaitTransition %s comm:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
+            " size:%zu",
             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
 }
 std::string CommWaitTransition::to_string(bool verbose) const
@@ -67,14 +67,14 @@ bool CommWaitTransition::depends(const Transition* other) const
 
   return false; // Comm transitions are INDEP with non-comm transitions
 }
-CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, uintptr_t comm_, aid_t sender_,
+CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_,
                                        aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
                                        size_t size_)
     : Transition(Type::COMM_TEST, issuer, times_considered)
     , comm_(comm_)
+    , mbox_(mbox_)
     , sender_(sender_)
     , receiver_(receiver_)
-    , mbox_(mbox_)
     , sbuff_(sbuff_)
     , rbuff_(rbuff_)
     , size_(size_)
@@ -84,7 +84,7 @@ CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::
     : Transition(Type::COMM_TEST, issuer, times_considered)
 {
   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
-  XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
+  XBT_DEBUG("CommTestTransition comm:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
             " size:%zu",
             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
 }
@@ -121,7 +121,7 @@ bool CommTestTransition::depends(const Transition* other) const
   return false; // Comm transitions are INDEP with non-comm transitions
 }
 
-CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_,
+CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
                                        uintptr_t rbuff_, int tag_)
     : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
     , comm_(comm_)
@@ -194,7 +194,7 @@ bool CommRecvTransition::depends(const Transition* other) const
   return false; // Comm transitions are INDEP with non-comm transitions
 }
 
-CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_,
+CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
                                        uintptr_t sbuff_, size_t size_, int tag_)
     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
     , comm_(comm_)
@@ -208,7 +208,7 @@ CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::
     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
 {
   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
-  XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
+  XBT_DEBUG("SendTransition comm:%u mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
 }
 std::string CommSendTransition::to_string(bool verbose = false) const
 {
index 597a530..cf51c18 100644 (file)
@@ -21,10 +21,10 @@ class CommTestTransition;
 
 class CommWaitTransition : public Transition {
   bool timeout_;
-  uintptr_t comm_;
+  unsigned comm_;
+  unsigned mbox_;
   aid_t sender_;
   aid_t receiver_;
-  unsigned mbox_;
   uintptr_t sbuff_;
   uintptr_t rbuff_;
   size_t size_;
@@ -33,15 +33,15 @@ class CommWaitTransition : public Transition {
   friend CommTestTransition;
 
 public:
-  CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, uintptr_t comm_, aid_t sender_, aid_t receiver_,
+  CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, unsigned comm_, aid_t sender_, aid_t receiver_,
                      unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_, size_t size_);
   CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream);
   std::string to_string(bool verbose) const override;
   bool depends(const Transition* other) const override;
 
   bool get_timeout() const { return timeout_; }
-  /** Address of the corresponding Communication object in the application */
-  uintptr_t get_comm() const { return comm_; }
+  /** ID of the corresponding Communication object in the application, or 0 if unknown */
+  unsigned get_comm() const { return comm_; }
   /** Sender ID */
   aid_t get_sender() const { return sender_; }
   /** Receiver ID */
@@ -56,10 +56,10 @@ public:
   size_t get_size() const { return size_; }
 };
 class CommTestTransition : public Transition {
-  uintptr_t comm_;
+  unsigned comm_;
+  unsigned mbox_;
   aid_t sender_;
   aid_t receiver_;
-  unsigned mbox_;
   uintptr_t sbuff_;
   uintptr_t rbuff_;
   size_t size_;
@@ -67,14 +67,14 @@ class CommTestTransition : public Transition {
   friend CommRecvTransition;
 
 public:
-  CommTestTransition(aid_t issuer, int times_considered, uintptr_t comm_, aid_t sender_, aid_t receiver_,
-                     unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_, size_t size_);
+  CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_, aid_t receiver_, unsigned mbox_,
+                     uintptr_t sbuff_, uintptr_t rbuff_, size_t size_);
   CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream);
   std::string to_string(bool verbose) const override;
   bool depends(const Transition* other) const override;
 
-  /** Address of the corresponding Communication object in the application */
-  uintptr_t get_comm() const { return comm_; }
+  /** ID of the corresponding Communication object in the application, or 0 if unknown */
+  unsigned get_comm() const { return comm_; }
   /** Sender ID */
   aid_t get_sender() const { return sender_; }
   /** Receiver ID */
@@ -90,19 +90,19 @@ public:
 };
 
 class CommRecvTransition : public Transition {
-  uintptr_t comm_; /* Addr of the CommImpl */
+  unsigned comm_; /* ID of the CommImpl or 0 if not known */
   unsigned mbox_;
   uintptr_t rbuff_;
   int tag_;
 
 public:
-  CommRecvTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_, uintptr_t rbuff_, int tag_);
+  CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, uintptr_t rbuff_, int tag_);
   CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
   std::string to_string(bool verbose) const override;
   bool depends(const Transition* other) const override;
 
-  /** Address of the corresponding Communication object in the application */
-  uintptr_t get_comm() const { return comm_; }
+  /** ID of the corresponding Communication object in the application (or 0 if unknown)*/
+  unsigned get_comm() const { return comm_; }
   /** Mailbox ID */
   unsigned get_mailbox() const { return mbox_; }
   /** Receiver buffer */
@@ -112,21 +112,21 @@ public:
 };
 
 class CommSendTransition : public Transition {
-  uintptr_t comm_; /* Addr of the CommImpl */
+  unsigned comm_;
   unsigned mbox_;
   uintptr_t sbuff_;
   size_t size_;
   int tag_;
 
 public:
-  CommSendTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_, uintptr_t sbuff_,
-                     size_t size_, int tag_);
+  CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, uintptr_t sbuff_, size_t size_,
+                     int tag_);
   CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream);
   std::string to_string(bool verbose) const override;
   bool depends(const Transition* other) const override;
 
-  /** Address of the corresponding Communication object in the application */
-  uintptr_t get_comm() const { return comm_; }
+  /** ID of the corresponding Communication object in the application, or 0 if unknown */
+  unsigned get_comm() const { return comm_; }
   /** Mailbox ID */
   unsigned get_mailbox() const { return mbox_; }
   /** Sender buffer */