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/kvm | |
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/kvm')
-rw-r--r-- | src/cpu/kvm/base.cc | 32 | ||||
-rw-r--r-- | src/cpu/kvm/base.hh | 11 |
2 files changed, 14 insertions, 29 deletions
diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc index 30e984366..47cff5917 100644 --- a/src/cpu/kvm/base.cc +++ b/src/cpu/kvm/base.cc @@ -78,7 +78,6 @@ BaseKvmCPU::BaseKvmCPU(BaseKvmCPUParams *params) activeInstPeriod(0), perfControlledByTimer(params->usePerfOverflow), hostFactor(params->hostFactor), - drainManager(NULL), ctrInsts(0) { if (pageSize == -1) @@ -282,11 +281,11 @@ BaseKvmCPU::unserializeThread(CheckpointIn &cp, ThreadID tid) threadContextDirty = true; } -unsigned int -BaseKvmCPU::drain(DrainManager *dm) +DrainState +BaseKvmCPU::drain() { if (switchedOut()) - return 0; + return DrainState::Drained; DPRINTF(Drain, "BaseKvmCPU::drain\n"); switch (_status) { @@ -296,10 +295,8 @@ BaseKvmCPU::drain(DrainManager *dm) // of a different opinion. This may happen when the CPU been // notified of an event that hasn't been accepted by the vCPU // yet. - if (!archIsDrained()) { - drainManager = dm; - return 1; - } + if (!archIsDrained()) + return DrainState::Draining; // The state of the CPU is consistent, so we don't need to do // anything special to drain it. We simply de-schedule the @@ -318,7 +315,7 @@ BaseKvmCPU::drain(DrainManager *dm) // switch CPUs or checkpoint the CPU. syncThreadContext(); - return 0; + return DrainState::Drained; case RunningServiceCompletion: // The CPU has just requested a service that was handled in @@ -327,22 +324,18 @@ BaseKvmCPU::drain(DrainManager *dm) // update the register state ourselves instead of letting KVM // handle it, but that would be tricky. Instead, we enter KVM // and let it do its stuff. - drainManager = dm; - DPRINTF(Drain, "KVM CPU is waiting for service completion, " "requesting drain.\n"); - return 1; + return DrainState::Draining; case RunningService: // We need to drain since the CPU is waiting for service (e.g., MMIOs) - drainManager = dm; - DPRINTF(Drain, "KVM CPU is waiting for service, requesting drain.\n"); - return 1; + return DrainState::Draining; default: panic("KVM: Unhandled CPU state in drain()\n"); - return 0; + return DrainState::Drained; } } @@ -551,7 +544,7 @@ BaseKvmCPU::tick() setupInstStop(); DPRINTF(KvmRun, "Entering KVM...\n"); - if (drainManager) { + if (drainState() == DrainState::Draining) { // Force an immediate exit from KVM after completing // pending operations. The architecture-specific code // takes care to run until it is in a state where it can @@ -1198,7 +1191,7 @@ BaseKvmCPU::setupCounters() bool BaseKvmCPU::tryDrain() { - if (!drainManager) + if (drainState() != DrainState::Draining) return false; if (!archIsDrained()) { @@ -1209,8 +1202,7 @@ BaseKvmCPU::tryDrain() if (_status == Idle || _status == Running) { DPRINTF(Drain, "tryDrain: CPU transitioned into the Idle state, drain done\n"); - drainManager->signalDrainDone(); - drainManager = NULL; + signalDrainDone(); return true; } else { DPRINTF(Drain, "tryDrain: CPU not ready.\n"); diff --git a/src/cpu/kvm/base.hh b/src/cpu/kvm/base.hh index a8e429dfa..df6a67808 100644 --- a/src/cpu/kvm/base.hh +++ b/src/cpu/kvm/base.hh @@ -89,8 +89,8 @@ class BaseKvmCPU : public BaseCPU void unserializeThread(CheckpointIn &cp, ThreadID tid) M5_ATTR_OVERRIDE; - unsigned int drain(DrainManager *dm); - void drainResume(); + DrainState drain() M5_ATTR_OVERRIDE; + void drainResume() M5_ATTR_OVERRIDE; void switchOut(); void takeOverFrom(BaseCPU *cpu); @@ -749,13 +749,6 @@ class BaseKvmCPU : public BaseCPU /** Host factor as specified in the configuration */ float hostFactor; - /** - * Drain manager to use when signaling drain completion - * - * This pointer is non-NULL when draining and NULL otherwise. - */ - DrainManager *drainManager; - public: /* @{ */ Stats::Scalar numInsts; |