diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 09:51:05 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 09:51:05 +0100 |
commit | ed38e3432c732d71cf29dc3fd739f078be7de6b0 (patch) | |
tree | 2c8a307ef7e8188e699d27bb66e942186dc62787 /src/cpu/simple | |
parent | f16c0a4a90ad1050cf7d1140916c35d07b1cb28e (diff) | |
download | gem5-ed38e3432c732d71cf29dc3fd739f078be7de6b0.tar.xz |
sim: Refactor and simplify the drain API
The drain() call currently passes around a DrainManager pointer, which
is now completely pointless since there is only ever one global
DrainManager in the system. It also contains vestiges from the time
when SimObjects had to keep track of their child objects that needed
draining.
This changeset moves all of the DrainState handling to the Drainable
base class and changes the drain() and drainResume() calls to reflect
this. Particularly, the drain() call has been updated to take no
parameters (the DrainManager argument isn't needed) and return a
DrainState instead of an unsigned integer (there is no point returning
anything other than 0 or 1 any more). Drainable objects should return
either DrainState::Draining (equivalent to returning 1 in the old
system) if they need more time to drain or DrainState::Drained
(equivalent to returning 0 in the old system) if they are already in a
consistent state. Returning DrainState::Running is considered an
error.
Drain done signalling is now done through the signalDrainDone() method
in the Drainable class instead of using the DrainManager directly. The
new call checks if the state of the object is DrainState::Draining
before notifying the drain manager. This means that it is safe to call
signalDrainDone() without first checking if the simulator has
requested draining. The intention here is to reduce the code needed to
implement draining in simple objects.
Diffstat (limited to 'src/cpu/simple')
-rw-r--r-- | src/cpu/simple/atomic.cc | 19 | ||||
-rw-r--r-- | src/cpu/simple/atomic.hh | 11 | ||||
-rw-r--r-- | src/cpu/simple/timing.cc | 20 | ||||
-rw-r--r-- | src/cpu/simple/timing.hh | 11 |
4 files changed, 19 insertions, 42 deletions
diff --git a/src/cpu/simple/atomic.cc b/src/cpu/simple/atomic.cc index 4c1c45355..3777ddee9 100644 --- a/src/cpu/simple/atomic.cc +++ b/src/cpu/simple/atomic.cc @@ -108,7 +108,6 @@ AtomicSimpleCPU::AtomicSimpleCPU(AtomicSimpleCPUParams *p) : BaseSimpleCPU(p), tickEvent(this), width(p->width), locked(false), simulate_data_stalls(p->simulate_data_stalls), simulate_inst_stalls(p->simulate_inst_stalls), - drain_manager(NULL), icachePort(name() + ".icache_port", this), dcachePort(name() + ".dcache_port", this), fastmem(p->fastmem), dcache_access(false), dcache_latency(0), @@ -125,23 +124,21 @@ AtomicSimpleCPU::~AtomicSimpleCPU() } } -unsigned int -AtomicSimpleCPU::drain(DrainManager *dm) +DrainState +AtomicSimpleCPU::drain() { - assert(!drain_manager); if (switchedOut()) - return 0; + return DrainState::Drained; if (!isDrained()) { DPRINTF(Drain, "Requesting drain: %s\n", pcState()); - drain_manager = dm; - return 1; + return DrainState::Draining; } else { if (tickEvent.scheduled()) deschedule(tickEvent); DPRINTF(Drain, "Not executing microcode, no need to drain.\n"); - return 0; + return DrainState::Drained; } } @@ -149,7 +146,6 @@ void AtomicSimpleCPU::drainResume() { assert(!tickEvent.scheduled()); - assert(!drain_manager); if (switchedOut()) return; @@ -173,7 +169,7 @@ AtomicSimpleCPU::drainResume() bool AtomicSimpleCPU::tryCompleteDrain() { - if (!drain_manager) + if (drainState() != DrainState::Draining) return false; DPRINTF(Drain, "tryCompleteDrain: %s\n", pcState()); @@ -181,8 +177,7 @@ AtomicSimpleCPU::tryCompleteDrain() return false; DPRINTF(Drain, "CPU done draining, processing drain event\n"); - drain_manager->signalDrainDone(); - drain_manager = NULL; + signalDrainDone(); return true; } diff --git a/src/cpu/simple/atomic.hh b/src/cpu/simple/atomic.hh index 5ad5c4305..3f587e671 100644 --- a/src/cpu/simple/atomic.hh +++ b/src/cpu/simple/atomic.hh @@ -74,13 +74,6 @@ class AtomicSimpleCPU : public BaseSimpleCPU const bool simulate_data_stalls; const bool simulate_inst_stalls; - /** - * Drain manager to use when signaling drain completion - * - * This pointer is non-NULL when draining and NULL otherwise. - */ - DrainManager *drain_manager; - // main simulation loop (one cycle) void tick(); @@ -192,8 +185,8 @@ class AtomicSimpleCPU : public BaseSimpleCPU public: - unsigned int drain(DrainManager *drain_manager); - void drainResume(); + DrainState drain() M5_ATTR_OVERRIDE; + void drainResume() M5_ATTR_OVERRIDE; void switchOut(); void takeOverFrom(BaseCPU *oldCPU); diff --git a/src/cpu/simple/timing.cc b/src/cpu/simple/timing.cc index a3c4e27e8..5dc042f1e 100644 --- a/src/cpu/simple/timing.cc +++ b/src/cpu/simple/timing.cc @@ -91,7 +91,7 @@ TimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt, Tick t) TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p) : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this), dcachePort(this), ifetch_pkt(NULL), dcache_pkt(NULL), previousCycle(0), - fetchEvent(this), drainManager(NULL) + fetchEvent(this) { _status = Idle; } @@ -102,19 +102,17 @@ TimingSimpleCPU::~TimingSimpleCPU() { } -unsigned int -TimingSimpleCPU::drain(DrainManager *drain_manager) +DrainState +TimingSimpleCPU::drain() { - assert(!drainManager); if (switchedOut()) - return 0; + return DrainState::Drained; if (_status == Idle || (_status == BaseSimpleCPU::Running && isDrained())) { DPRINTF(Drain, "No need to drain.\n"); - return 0; + return DrainState::Drained; } else { - drainManager = drain_manager; DPRINTF(Drain, "Requesting drain: %s\n", pcState()); // The fetch event can become descheduled if a drain didn't @@ -123,7 +121,7 @@ TimingSimpleCPU::drain(DrainManager *drain_manager) if (_status == BaseSimpleCPU::Running && !fetchEvent.scheduled()) schedule(fetchEvent, clockEdge()); - return 1; + return DrainState::Draining; } } @@ -131,7 +129,6 @@ void TimingSimpleCPU::drainResume() { assert(!fetchEvent.scheduled()); - assert(!drainManager); if (switchedOut()) return; @@ -155,7 +152,7 @@ TimingSimpleCPU::drainResume() bool TimingSimpleCPU::tryCompleteDrain() { - if (!drainManager) + if (drainState() != DrainState::Draining) return false; DPRINTF(Drain, "tryCompleteDrain: %s\n", pcState()); @@ -163,8 +160,7 @@ TimingSimpleCPU::tryCompleteDrain() return false; DPRINTF(Drain, "CPU done draining, processing drain event\n"); - drainManager->signalDrainDone(); - drainManager = NULL; + signalDrainDone(); return true; } diff --git a/src/cpu/simple/timing.hh b/src/cpu/simple/timing.hh index 3ce596fc7..b6a1da4e2 100644 --- a/src/cpu/simple/timing.hh +++ b/src/cpu/simple/timing.hh @@ -270,8 +270,8 @@ class TimingSimpleCPU : public BaseSimpleCPU public: - unsigned int drain(DrainManager *drain_manager); - void drainResume(); + DrainState drain() M5_ATTR_OVERRIDE; + void drainResume() M5_ATTR_OVERRIDE; void switchOut(); void takeOverFrom(BaseCPU *oldCPU); @@ -351,13 +351,6 @@ class TimingSimpleCPU : public BaseSimpleCPU * @returns true if the CPU is drained, false otherwise. */ bool tryCompleteDrain(); - - /** - * Drain manager to use when signaling drain completion - * - * This pointer is non-NULL when draining and NULL otherwise. - */ - DrainManager *drainManager; }; #endif // __CPU_SIMPLE_TIMING_HH__ |