From: Andreas Hansson Date: Sun, 19 Feb 2017 10:30:31 +0000 (-0500) Subject: sim: Ensure draining is deterministic X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=184c6d7ebd7faa0869f294526a54a239a216b7c8;p=gem5.git 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. --- diff --git a/src/mem/cache/cache.hh b/src/mem/cache/cache.hh index 4f9142f7c..7f9130d62 100644 --- a/src/mem/cache/cache.hh +++ b/src/mem/cache/cache.hh @@ -52,6 +52,8 @@ #ifndef __MEM_CACHE_CACHE_HH__ #define __MEM_CACHE_CACHE_HH__ +#include + #include "base/misc.hh" // fatal, panic, and warn #include "enums/Clusivity.hh" #include "mem/cache/base.hh" diff --git a/src/mem/coherent_xbar.hh b/src/mem/coherent_xbar.hh index 0f641664d..edfc47d4b 100644 --- a/src/mem/coherent_xbar.hh +++ b/src/mem/coherent_xbar.hh @@ -51,6 +51,8 @@ #ifndef __MEM_COHERENT_XBAR_HH__ #define __MEM_COHERENT_XBAR_HH__ +#include + #include "mem/snoop_filter.hh" #include "mem/xbar.hh" #include "params/CoherentXBar.hh" diff --git a/src/sim/drain.cc b/src/sim/drain.cc index 085f781dc..bb8abd735 100644 --- a/src/sim/drain.cc +++ b/src/sim/drain.cc @@ -39,6 +39,8 @@ #include "sim/drain.hh" +#include + #include "base/misc.hh" #include "base/trace.hh" #include "debug/Drain.hh" @@ -126,6 +128,7 @@ DrainManager::preCheckpointRestore() 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 @@ void DrainManager::registerDrainable(Drainable *obj) { std::lock_guard 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 lock(globalLock); - _allDrainable.erase(obj); + auto o = std::find(_allDrainable.begin(), _allDrainable.end(), obj); + assert(o != _allDrainable.end()); + _allDrainable.erase(o); } size_t diff --git a/src/sim/drain.hh b/src/sim/drain.hh index b3145e7ed..663946616 100644 --- a/src/sim/drain.hh +++ b/src/sim/drain.hh @@ -42,7 +42,7 @@ #include #include -#include +#include class Drainable; @@ -162,7 +162,7 @@ class DrainManager mutable std::mutex globalLock; /** Set of all drainable objects */ - std::unordered_set _allDrainable; + std::vector _allDrainable; /** * Number of objects still draining. This is flagged atomic since