X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/97e476dc536bfd9fada85509d1c1f93714d46a10..0f0aacb167ddc9427ea1da1c8f1b66ef2d6f532e:/src/mc/transition/TransitionSynchro.cpp diff --git a/src/mc/transition/TransitionSynchro.cpp b/src/mc/transition/TransitionSynchro.cpp index 2c6b916f8c..8486a0ca83 100644 --- a/src/mc/transition/TransitionSynchro.cpp +++ b/src/mc/transition/TransitionSynchro.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,8 +13,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_synchro, mc_transition, "Logging specific to MC synchronization transitions"); -namespace simgrid { -namespace mc { +namespace simgrid::mc { std::string BarrierTransition::to_string(bool verbose) const { @@ -30,12 +29,16 @@ bool BarrierTransition::depends(const Transition* o) const if (o->type_ < type_) return o->depends(this); - if (auto* other = dynamic_cast(o)) { + // Actions executed by the same actor are always dependent + if (o->aid_ == aid_) + return true; + + if (const auto* other = dynamic_cast(o)) { if (bar_ != other->bar_) return false; // LOCK indep LOCK: requests are not ordered in a barrier - if (type_ == Type::BARRIER_LOCK && other->type_ == Type::BARRIER_LOCK) + if (type_ == Type::BARRIER_ASYNC_LOCK && other->type_ == Type::BARRIER_ASYNC_LOCK) return false; // WAIT indep WAIT: requests are not ordered @@ -50,7 +53,7 @@ bool BarrierTransition::depends(const Transition* o) const std::string MutexTransition::to_string(bool verbose) const { - return xbt::string_printf("%s(mutex: %" PRIxPTR ", owner:%ld)", Transition::to_c_str(type_), mutex_, owner_); + return xbt::string_printf("%s(mutex: %" PRIxPTR ", owner: %ld)", Transition::to_c_str(type_), mutex_, owner_); } MutexTransition::MutexTransition(aid_t issuer, int times_considered, Type type, std::stringstream& stream) @@ -64,21 +67,25 @@ bool MutexTransition::depends(const Transition* o) const if (o->type_ < type_) return o->depends(this); + // Actions executed by the same actor are always dependent + if (o->aid_ == aid_) + return true; + // type_ <= other->type_ in MUTEX_LOCK, MUTEX_TEST, MUTEX_TRYLOCK, MUTEX_UNLOCK, MUTEX_WAIT, - if (auto* other = dynamic_cast(o)) { + if (const auto* other = dynamic_cast(o)) { // Theorem 4.4.7: Any pair of synchronization actions of distinct actors concerning distinct mutexes are independent if (mutex_ != other->mutex_) return false; // Theorem 4.4.11: LOCK indep TEST/WAIT. // If both enabled, the result does not depend on their order. If WAIT is not enabled, LOCK won't enable it. - if (type_ == Type::MUTEX_LOCK && (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_WAIT)) + if (type_ == Type::MUTEX_ASYNC_LOCK && (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_WAIT)) return false; // Theorem 4.4.8: LOCK indep UNLOCK. // pop_front and push_back are independent. - if (type_ == Type::MUTEX_LOCK && other->type_ == Type::MUTEX_UNLOCK) + if (type_ == Type::MUTEX_ASYNC_LOCK && other->type_ == Type::MUTEX_UNLOCK) return false; // TEST is a pure function; TEST/WAIT won't change the owner; TRYLOCK will always fail if TEST is enabled (because a @@ -101,40 +108,48 @@ bool MutexTransition::depends(const Transition* o) const std::string SemaphoreTransition::to_string(bool verbose) const { - if (type_ == Type::SEM_LOCK || type_ == Type::SEM_UNLOCK) - return xbt::string_printf("%s(semaphore: %" PRIxPTR ")", Transition::to_c_str(type_), sem_); + if (type_ == Type::SEM_ASYNC_LOCK || type_ == Type::SEM_UNLOCK) + return xbt::string_printf("%s(semaphore: %u, capacity: %u)", Transition::to_c_str(type_), sem_, capacity_); if (type_ == Type::SEM_WAIT) - return xbt::string_printf("%s(semaphore: %" PRIxPTR ", granted: %s)", Transition::to_c_str(type_), sem_, - granted_ ? "yes" : "no"); + return xbt::string_printf("%s(semaphore: %u, capacity: %u, granted: %s)", Transition::to_c_str(type_), sem_, + capacity_, granted_ ? "yes" : "no"); THROW_IMPOSSIBLE; } SemaphoreTransition::SemaphoreTransition(aid_t issuer, int times_considered, Type type, std::stringstream& stream) : Transition(type, issuer, times_considered) { - xbt_assert(stream >> sem_ >> granted_); + xbt_assert(stream >> sem_ >> granted_ >> capacity_); } bool SemaphoreTransition::depends(const Transition* o) const { if (o->type_ < type_) return o->depends(this); - if (auto* other = dynamic_cast(o)) { + // Actions executed by the same actor are always dependent + if (o->aid_ == aid_) + return true; + + if (const auto* other = dynamic_cast(o)) { if (sem_ != other->sem_) return false; // LOCK indep UNLOCK: pop_front and push_back are independent. - if (type_ == Type::SEM_LOCK && other->type_ == Type::SEM_UNLOCK) + if (type_ == Type::SEM_ASYNC_LOCK && other->type_ == Type::SEM_UNLOCK) return false; // LOCK indep WAIT: If both enabled, ordering has no impact on the result. If WAIT is not enabled, LOCK won't enable // it. - if (type_ == Type::SEM_LOCK && other->type_ == Type::SEM_WAIT) + if (type_ == Type::SEM_ASYNC_LOCK && other->type_ == Type::SEM_WAIT) return false; // UNLOCK indep UNLOCK: ordering of two pop_front has no impact if (type_ == Type::SEM_UNLOCK && other->type_ == Type::SEM_UNLOCK) return false; + // UNLCOK indep with a WAIT if the semaphore had enought capacity anyway + if (type_ == Type::SEM_UNLOCK && capacity_ > 1 && other->type_ == Type::SEM_WAIT) + return false; + // WAIT indep WAIT: // if both enabled (may happen in the initial value is sufficient), the ordering has no impact on the result. // If only one enabled, the other won't be enabled by the first one. @@ -148,5 +163,4 @@ bool SemaphoreTransition::depends(const Transition* o) const return false; // semaphores are INDEP with non-semaphore transitions } -} // namespace mc -} // namespace simgrid +} // namespace simgrid::mc