Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add ex(C) computation for mutex lock/unlock
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Thu, 20 Apr 2023 08:05:29 +0000 (10:05 +0200)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Fri, 9 Jun 2023 08:01:13 +0000 (10:01 +0200)
The pseudcode for computing the incremental
portion of the extension set for the transitions
MUTEX_ASYNC_LOCK and MUTEX_UNLOCK were partially
added. What's importantly missing is one key
element of detecting dependencies in the specific
configuration context between a MUTEX_UNLOCK and
a MUTEX_WAIT. This will also prove to be an issue
when implementing the corresponding function for
MUTEX_WAIT.

src/mc/explo/udpor/ExtensionSetCalculator.cpp
src/mc/explo/udpor/ExtensionSetCalculator.hpp
src/mc/transition/TransitionComm.cpp
src/mc/transition/TransitionComm.hpp
src/mc/transition/TransitionSynchro.hpp

index 849337d..fe8969e 100644 (file)
@@ -28,20 +28,23 @@ EventSet ExtensionSetCalculator::partially_extend(const Configuration& C, Unfold
       HandlerMap{{Action::COMM_ASYNC_RECV, &ExtensionSetCalculator::partially_extend_CommRecv},
                  {Action::COMM_ASYNC_SEND, &ExtensionSetCalculator::partially_extend_CommSend},
                  {Action::COMM_WAIT, &ExtensionSetCalculator::partially_extend_CommWait},
-                 {Action::COMM_TEST, &ExtensionSetCalculator::partially_extend_CommTest}};
+                 {Action::COMM_TEST, &ExtensionSetCalculator::partially_extend_CommTest},
+                 {Action::MUTEX_ASYNC_LOCK, &ExtensionSetCalculator::partially_extend_MutexAsyncLock},
+                 {Action::MUTEX_UNLOCK, &ExtensionSetCalculator::partially_extend_MutexUnlock},
+                 {Action::MUTEX_WAIT, &ExtensionSetCalculator::partially_extend_MutexWait},
+                 {Action::MUTEX_TEST, &ExtensionSetCalculator::partially_extend_MutexTest},
+                 {Action::ACTOR_JOIN, &ExtensionSetCalculator::partially_extend_ActorJoin}};
 
   if (const auto handler = handlers.find(action->type_); handler != handlers.end()) {
     return handler->second(C, U, std::move(action));
   } else {
-    xbt_assert(false,
-               "There is currently no specialized computation for the transition "
-               "'%s' for computing extension sets in UDPOR, so the model checker cannot "
-               "determine how to proceed. Please submit a bug report requesting "
-               "that the transition be supported in SimGrid using UDPOR and consider "
-               "using the other model-checking algorithms supported by SimGrid instead "
-               "in the meantime",
-               action->to_string().c_str());
-    DIE_IMPOSSIBLE;
+    xbt_die("There is currently no specialized computation for the transition "
+            "'%s' for computing extension sets in UDPOR, so the model checker cannot "
+            "determine how to proceed. Please submit a bug report requesting "
+            "that the transition be supported in SimGrid using UDPOR and consider "
+            "using the other model-checking algorithms supported by SimGrid instead "
+            "in the meantime",
+            action->to_string().c_str());
   }
 }
 
@@ -80,7 +83,7 @@ EventSet ExtensionSetCalculator::partially_extend_CommSend(const Configuration&
     if (transition_type_check) {
       const EventSet K = EventSet({e, pre_event_a_C.value_or(e)}).get_largest_maximal_subset();
 
-      // TODO: Check D_K(a, lambda(e))
+      // TODO: Check D_K(a, lambda(e)) (only matters in the case of CommTest)
       if (true) {
         const auto* e_prime = U->discover_event(std::move(K), send_action);
         exC.insert(e_prime);
@@ -528,6 +531,103 @@ EventSet ExtensionSetCalculator::partially_extend_CommTest(const Configuration&
             "this case. Was a new transition added?",
             e_issuer->get_transition()->to_string().c_str());
   }
+  return exC;
+}
+
+EventSet ExtensionSetCalculator::partially_extend_MutexAsyncLock(const Configuration& C, Unfolding* U,
+                                                                 std::shared_ptr<Transition> action)
+{
+  EventSet exC;
+  const auto mutex_lock    = std::static_pointer_cast<MutexTransition>(std::move(action));
+  const auto pre_event_a_C = C.pre_event(mutex_lock->aid_);
+
+  // for each event e in C
+  // 1. If lambda(e) := pre(a) -> add it, otherwise don't bother if
+  // it's not there
+  if (pre_event_a_C.has_value()) {
+    const auto e_prime = U->discover_event(EventSet({pre_event_a_C.value()}), mutex_lock);
+    exC.insert(e_prime);
+  }
+
+  // for each event e in C
+  for (const auto e : C) {
+    // Check for other locks on the same mutex
+    if (const MutexTransition* e_mutex = dynamic_cast<const MutexTransition*>(e->get_transition());
+        e_mutex != nullptr) {
+
+      if (e_mutex->type_ == Transition::Type::MUTEX_ASYNC_LOCK && mutex_lock->get_mutex() == e_mutex->get_mutex()) {
+        const EventSet K = EventSet({e, pre_event_a_C.value_or(e)});
+        exC.insert(U->discover_event(std::move(K), mutex_lock));
+      }
+    }
+  }
+  return exC;
+}
+
+EventSet ExtensionSetCalculator::partially_extend_MutexUnlock(const Configuration& C, Unfolding* U,
+                                                              std::shared_ptr<Transition> action)
+{
+  EventSet exC;
+  const auto mutex_unlock  = std::static_pointer_cast<MutexTransition>(std::move(action));
+  const auto pre_event_a_C = C.pre_event(mutex_unlock->aid_);
+
+  // for each event e in C
+  // 1. If lambda(e) := pre(a) -> add it, otherwise don't bother if
+  // it's not there
+  if (pre_event_a_C.has_value()) {
+    const auto e_prime = U->discover_event(EventSet({pre_event_a_C.value()}), mutex_unlock);
+    exC.insert(e_prime);
+  }
+
+  // for each event e in C
+  for (const auto e : C) {
+    // Check for MutexTest
+    if (const MutexTransition* e_mutex = dynamic_cast<const MutexTransition*>(e->get_transition());
+        e_mutex != nullptr) {
+
+      if (e_mutex->type_ == Transition::Type::MUTEX_TEST || e_mutex->type_ == Transition::Type::MUTEX_WAIT) {
+        // TODO: Check if dependent or not
+        // This entails getting information about
+        // the relative position of the mutex in the queue, which
+        // again means we need more context...
+        const EventSet K = EventSet({e, pre_event_a_C.value_or(e)});
+        exC.insert(U->discover_event(std::move(K), mutex_unlock));
+      }
+    }
+  }
+  return exC;
+}
+
+EventSet ExtensionSetCalculator::partially_extend_MutexWait(const Configuration& C, Unfolding* U,
+                                                            std::shared_ptr<Transition> action)
+{
+  return EventSet();
+}
+
+EventSet ExtensionSetCalculator::partially_extend_MutexTest(const Configuration& C, Unfolding* U,
+                                                            std::shared_ptr<Transition> action)
+{
+  return EventSet();
+}
+
+EventSet ExtensionSetCalculator::partially_extend_ActorJoin(const Configuration& C, Unfolding* U,
+                                                            std::shared_ptr<Transition> action)
+{
+  EventSet exC;
+
+  const auto join_action   = std::static_pointer_cast<ActorJoinTransition>(std::move(action));
+  const auto pre_event_a_C = C.pre_event(join_action->aid_);
+
+  // Handling ActorJoin is very simple: it is independent with all
+  // other transitions. Thus the only event it could possibly depend
+  // on is pre(a, C) or the root
+  if (pre_event_a_C.has_value()) {
+    const auto e_prime = U->discover_event(EventSet({pre_event_a_C.value()}), join_action);
+    exC.insert(e_prime);
+  } else {
+    const auto e_prime = U->discover_event(EventSet(), join_action);
+    exC.insert(e_prime);
+  }
 
   return exC;
 }
index 02b8669..f257a7f 100644 (file)
@@ -30,6 +30,13 @@ private:
   static EventSet partially_extend_CommWait(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
   static EventSet partially_extend_CommTest(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
 
+  static EventSet partially_extend_MutexAsyncLock(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
+  static EventSet partially_extend_MutexWait(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
+  static EventSet partially_extend_MutexTest(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
+  static EventSet partially_extend_MutexUnlock(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
+
+  static EventSet partially_extend_ActorJoin(const Configuration&, Unfolding*, std::shared_ptr<Transition>);
+
 public:
   static EventSet partially_extend(const Configuration&, Unfolding*, const std::shared_ptr<Transition>);
 };
index e836f73..2e71920 100644 (file)
@@ -67,6 +67,19 @@ 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_,
+                                       aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
+                                       size_t size_)
+    : Transition(Type::COMM_TEST, issuer, times_considered)
+    , comm_(comm_)
+    , sender_(sender_)
+    , receiver_(receiver_)
+    , mbox_(mbox_)
+    , sbuff_(sbuff_)
+    , rbuff_(rbuff_)
+    , size_(size_)
+{
+}
 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
     : Transition(Type::COMM_TEST, issuer, times_considered)
 {
@@ -152,6 +165,11 @@ bool CommRecvTransition::depends(const Transition* other) const
     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
       return false;
 
+    // If the test is checking a paired comm already, we're independent!
+    // If we happen to make up that pair, then we're dependent...
+    if (test->comm_ != comm_)
+      return false;
+
     return true; // DEP with other send transitions
   }
 
@@ -223,6 +241,11 @@ bool CommSendTransition::depends(const Transition* other) const
     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
       return false;
 
+    // If the test is checking a paired comm already, we're independent!
+    // If we happen to make up that pair, then we're dependent...
+    if (test->comm_ != comm_)
+      return false;
+
     return true; // DEP with other test transitions
   }
 
index 35c445f..597a530 100644 (file)
@@ -67,6 +67,8 @@ 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, std::stringstream& stream);
   std::string to_string(bool verbose) const override;
   bool depends(const Transition* other) const override;
index 87e4865..a290ba4 100644 (file)
@@ -29,6 +29,8 @@ public:
   std::string to_string(bool verbose) const override;
   MutexTransition(aid_t issuer, int times_considered, Type type, std::stringstream& stream);
   bool depends(const Transition* other) const override;
+
+  uintptr_t get_mutex() const { return this->mutex_; }
 };
 
 class SemaphoreTransition : public Transition {