sim: Decouple draining from the SimObject hierarchy
Review Request #2874 - Created June 8, 2015 and submitted
| Information | |
|---|---|
| Andreas Sandberg | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
Changeset 10884:1505317a33a8 --------------------------- sim: Decouple draining from the SimObject hierarchy Draining is currently done by traversing the SimObject graph and calling drain()/drainResume() on the SimObjects. This is not ideal when non-SimObjects (e.g., ports) need draining since this means that SimObjects owning those objects need to be aware of this. This changeset moves the responsibility for finding objects that need draining from SimObjects and the Python-side of the simulator to the DrainManager. The DrainManager now maintains a set of all objects that need draining. To reduce the overhead in classes owning non-SimObjects that need draining, objects inheriting from Drainable now automatically register with the DrainManager. If such an object is destroyed, it is automatically unregistered. This means that drain() and drainResume() should never be called directly on a Drainable object. While implementing the new functionality, the DrainManager has now been made thread safe. In practice, this means that it takes a lock whenever it manipulates the set of Drainable objects since SimObjects in different threads may create Drainable objects dynamically. Similarly, the drain counter is now an atomic_uint, which ensures that it is manipulated correctly when objects signal that they are done draining. A nice side effect of these changes is that it makes the drain state changes stricter, which the simulation scripts can exploit to avoid redundant drains.
Regressions pass. Minor stats difference (due to changes in drain call order) in one of the pc switcheroo tests.
I'll read the patch once more after you have answered my queries,
-
src/python/m5/simulate.py (Diff revision 1) -
Why do we not need this resume()?
-
src/sim/drain.hh (Diff revision 1) -
Redundant?
-
src/sim/drain.cc (Diff revision 1) -
missing some words
-
src/sim/drain.cc (Diff revision 1) -
pre not post.
-
tests/configs/switcheroo.py (Diff revision 1) -
I am not very clear of the flow of the code. So again the same question, why do we not need this resume() call?
Ship It!
So I think the Drainable class is a great idea, it's nice not to pollute random SimObjects with code that forces them to track what sub-objects of theirs need to be drained.
I'm less convinced about the benefits of irreversibly requiring draining to encompass the entire simulation. While that may be how we use it now, are we sure we'll never have a use case in the future that would benefit from the ability to do a partial drain? And even if we are skeptical about that, how much harm does it really do to pass a drainManager pointer around? It seems like there's a middle ground here where we maintain the drainManager as an actual object (not just effectively a namespace for a bunch of static members), but have it be a singleton; fuctionally it's not that different, but if we ever did decide to go back to needing partial draining, that would be a much smaller change (particularly for the following changeset).
-
src/sim/drain.hh (Diff revision 1) -
"in within the system" -> "in the simulation"
-
src/sim/drain.hh (Diff revision 1) -
since (almost) all of the members of this object are static, would it make more sense to have a normal class with non-static members, but then have a static singleton instance of that class?
Oddly enough, the only thing that isn't static in this patch (other than the trivial constructor and destructor) is signalDrainDone(); for some reason you wait until the next patch to make that static :).
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 2 (+247 -331) |
Ship It!
