changeset 76c36516e0ae in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=76c36516e0ae description: sim: Ensure draining is deterministic
The traversal of drainable objects could potentially be non-deterministic when using an unordered set containing object pointers. To ensure that the iteration is deterministic, we switch to a vector. Note that the lookup and traversal of the drainable objects is not performance critical, so the change has no negative consequences. diffstat: src/mem/cache/cache.hh | 2 ++ src/mem/coherent_xbar.hh | 2 ++ src/sim/drain.cc | 11 +++++++++-- src/sim/drain.hh | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diffs (86 lines): diff -r 5869c83bc8c7 -r 76c36516e0ae src/mem/cache/cache.hh --- a/src/mem/cache/cache.hh Sun Feb 19 05:30:31 2017 -0500 +++ b/src/mem/cache/cache.hh Sun Feb 19 05:30:31 2017 -0500 @@ -52,6 +52,8 @@ #ifndef __MEM_CACHE_CACHE_HH__ #define __MEM_CACHE_CACHE_HH__ +#include <unordered_set> + #include "base/misc.hh" // fatal, panic, and warn #include "enums/Clusivity.hh" #include "mem/cache/base.hh" diff -r 5869c83bc8c7 -r 76c36516e0ae src/mem/coherent_xbar.hh --- a/src/mem/coherent_xbar.hh Sun Feb 19 05:30:31 2017 -0500 +++ b/src/mem/coherent_xbar.hh Sun Feb 19 05:30:31 2017 -0500 @@ -51,6 +51,8 @@ #ifndef __MEM_COHERENT_XBAR_HH__ #define __MEM_COHERENT_XBAR_HH__ +#include <unordered_set> + #include "mem/snoop_filter.hh" #include "mem/xbar.hh" #include "params/CoherentXBar.hh" diff -r 5869c83bc8c7 -r 76c36516e0ae src/sim/drain.cc --- a/src/sim/drain.cc Sun Feb 19 05:30:31 2017 -0500 +++ b/src/sim/drain.cc Sun Feb 19 05:30:31 2017 -0500 @@ -39,6 +39,8 @@ #include "sim/drain.hh" +#include <algorithm> + #include "base/misc.hh" #include "base/trace.hh" #include "debug/Drain.hh" @@ -126,6 +128,7 @@ void DrainManager::signalDrainDone() { + assert(_count > 0); if (--_count == 0) { DPRINTF(Drain, "All %u objects drained..\n", drainableCount()); exitSimLoop("Finished drain", 0); @@ -137,14 +140,18 @@ DrainManager::registerDrainable(Drainable *obj) { std::lock_guard<std::mutex> lock(globalLock); - _allDrainable.insert(obj); + assert(std::find(_allDrainable.begin(), _allDrainable.end(), obj) == + _allDrainable.end()); + _allDrainable.push_back(obj); } void DrainManager::unregisterDrainable(Drainable *obj) { std::lock_guard<std::mutex> lock(globalLock); - _allDrainable.erase(obj); + auto o = std::find(_allDrainable.begin(), _allDrainable.end(), obj); + assert(o != _allDrainable.end()); + _allDrainable.erase(o); } size_t diff -r 5869c83bc8c7 -r 76c36516e0ae src/sim/drain.hh --- a/src/sim/drain.hh Sun Feb 19 05:30:31 2017 -0500 +++ b/src/sim/drain.hh Sun Feb 19 05:30:31 2017 -0500 @@ -42,7 +42,7 @@ #include <atomic> #include <mutex> -#include <unordered_set> +#include <vector> class Drainable; @@ -162,7 +162,7 @@ mutable std::mutex globalLock; /** Set of all drainable objects */ - std::unordered_set<Drainable *> _allDrainable; + std::vector<Drainable *> _allDrainable; /** * Number of objects still draining. This is flagged atomic since _______________________________________________ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev