From 024b33a1ef6f83be634f7afe644777f070ccd692 Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Wed, 11 Oct 2006 18:44:48 -0400 Subject: [PATCH 1/3] some drain changes in timing (kevin's) and some memory mode assertion changes so that when you come out of resume, you only assert if you're really wrong. src/cpu/simple/atomic.cc: memory mode assertion change so that it only goes off if it's supposed to. src/cpu/simple/timing.cc: some drain changes (kevin's) and some changes to memoryMode assertions so that they don't go off when they're not supposed to. --HG-- extra : convert_revision : 007d8610f097e08f01367b905ada49f93cf37ca3 --- src/cpu/simple/atomic.cc | 2 +- src/cpu/simple/timing.cc | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cpu/simple/atomic.cc b/src/cpu/simple/atomic.cc index 490be20ae..fe421ae6c 100644 --- a/src/cpu/simple/atomic.cc +++ b/src/cpu/simple/atomic.cc @@ -182,9 +182,9 @@ AtomicSimpleCPU::unserialize(Checkpoint *cp, const string §ion) void AtomicSimpleCPU::resume() { - assert(system->getMemoryMode() == System::Atomic); changeState(SimObject::Running); if (thread->status() == ThreadContext::Active) { + assert(system->getMemoryMode() == System::Atomic); if (!tickEvent.scheduled()) tickEvent.schedule(curTick); } diff --git a/src/cpu/simple/timing.cc b/src/cpu/simple/timing.cc index 48362c42a..88aa882e3 100644 --- a/src/cpu/simple/timing.cc +++ b/src/cpu/simple/timing.cc @@ -146,6 +146,8 @@ void TimingSimpleCPU::resume() { if (_status != SwitchedOut && _status != Idle) { + assert(system->getMemoryMode() == System::Timing); + // Delete the old event if it existed. if (fetchEvent) { if (fetchEvent->scheduled()) @@ -159,7 +161,6 @@ TimingSimpleCPU::resume() fetchEvent->schedule(curTick); } - assert(system->getMemoryMode() == System::Timing); changeState(SimObject::Running); } @@ -190,6 +191,10 @@ TimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU) break; } } + + if (_status != Running) { + _status = Idle; + } } @@ -533,15 +538,6 @@ TimingSimpleCPU::completeDataAccess(Packet *pkt) assert(_status == DcacheWaitResponse); _status = Running; - if (getState() == SimObject::Draining) { - completeDrain(); - - delete pkt->req; - delete pkt; - - return; - } - Fault fault = curStaticInst->completeAcc(pkt, this, traceData); if (pkt->isRead() && pkt->req->isLocked()) { @@ -551,6 +547,13 @@ TimingSimpleCPU::completeDataAccess(Packet *pkt) delete pkt->req; delete pkt; + if (getState() == SimObject::Draining) { + advancePC(fault); + completeDrain(); + + return; + } + postExecute(); advanceInst(fault); } From 8acecfef9b0e9a1c34b338a6862a3cc38b2f490b Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Wed, 11 Oct 2006 18:53:50 -0400 Subject: [PATCH 2/3] since memoryMode was put into the System (from SimObject), things got broken - this fixes it so that changeToTiming/changeToAtomic works. src/python/m5/SimObject.py: now that setMemoryMode is a method in System, need to convert the SimObject * _ccObject into a system ptr to call setMemoryMode. src/sim/main.cc: need this conversion now. src/sim/sim_object.hh: put the enum back into SimObject. src/sim/system.hh: memoryMode is now a part of SimObject, need the ::'s --HG-- extra : convert_revision : 0ade06957fa57b497798e1f50c237ca1badc821d --- src/python/m5/SimObject.py | 7 ++++++- src/sim/main.cc | 12 ++++++++++++ src/sim/sim_object.hh | 7 +++++++ src/sim/system.hh | 14 ++++---------- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index a0d66e643..716f584b0 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -726,7 +726,12 @@ class SimObject(object): child.resume() def changeTiming(self, mode): - if isinstance(self, System): + if isinstance(self, m5.objects.System): + # i don't know if there's a better way to do this - calling + # setMemoryMode directly from self._ccObject results in calling + # SimObject::setMemoryMode, not the System::setMemoryMode +## system_ptr = cc_main.convertToSystemPtr(self._ccObject) +## system_ptr.setMemoryMode(mode) self._ccObject.setMemoryMode(mode) for child in self._children.itervalues(): child.changeTiming(mode) diff --git a/src/sim/main.cc b/src/sim/main.cc index 874d0ac85..8bb0d7aaa 100644 --- a/src/sim/main.cc +++ b/src/sim/main.cc @@ -66,6 +66,7 @@ #include "sim/sim_events.hh" #include "sim/sim_exit.hh" #include "sim/sim_object.hh" +#include "sim/system.hh" #include "sim/stat_control.hh" #include "sim/stats.hh" #include "sim/root.hh" @@ -440,6 +441,17 @@ convertToBaseCPUPtr(SimObject *obj) return ptr; } +System * +convertToSystemPtr(SimObject *obj) +{ + System *ptr = dynamic_cast(obj); + + if (ptr == NULL) + warn("Casting to System pointer failed"); + return ptr; +} + + /** * Do C++ simulator exit processing. Exported to SWIG to be invoked * when simulator terminates via Python's atexit mechanism. diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh index 38f2bdd23..32807b69d 100644 --- a/src/sim/sim_object.hh +++ b/src/sim/sim_object.hh @@ -64,6 +64,13 @@ class SimObject : public Serializable, protected StartupCallback Draining, Drained }; + + enum MemoryMode { + Invalid=0, + Atomic, + Timing + }; + private: State state; diff --git a/src/sim/system.hh b/src/sim/system.hh index 3ab1d81f2..827fe5c78 100644 --- a/src/sim/system.hh +++ b/src/sim/system.hh @@ -62,22 +62,16 @@ class RemoteGDB; class System : public SimObject { public: - enum MemoryMode { - Invalid=0, - Atomic, - Timing - }; static const char *MemoryModeStrings[3]; - - MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; } + SimObject::MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; } /** Change the memory mode of the system. This should only be called by the * python!! * @param mode Mode to change to (atomic/timing) */ - void setMemoryMode(MemoryMode mode); + void setMemoryMode(SimObject::MemoryMode mode); PhysicalMemory *physmem; PCEventQueue pcEventQueue; @@ -126,7 +120,7 @@ class System : public SimObject protected: - MemoryMode memoryMode; + SimObject::MemoryMode memoryMode; #if FULL_SYSTEM /** @@ -173,7 +167,7 @@ class System : public SimObject { std::string name; PhysicalMemory *physmem; - MemoryMode mem_mode; + SimObject::MemoryMode mem_mode; #if FULL_SYSTEM Tick boot_cpu_frequency; From ba795552f58525e34c26a79224ff24c11145103e Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Wed, 11 Oct 2006 18:54:31 -0400 Subject: [PATCH 3/3] System not global object, need to preface it with objects. --HG-- extra : convert_revision : 5e105d7082a8c103fb5d5383c3093734bfd590f5 --- src/python/m5/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 5717b49b6..03e0508fb 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -144,7 +144,7 @@ def restoreCheckpoint(root, dir): resume(root) def changeToAtomic(system): - if not isinstance(system, objects.Root) and not isinstance(system, System): + if not isinstance(system, objects.Root) and not isinstance(system, objects.System): raise TypeError, "Object is not a root or system object. Checkpoint must be " "called on a root object." doDrain(system) @@ -153,7 +153,7 @@ def changeToAtomic(system): resume(system) def changeToTiming(system): - if not isinstance(system, objects.Root) and not isinstance(system, System): + if not isinstance(system, objects.Root) and not isinstance(system, objects.System): raise TypeError, "Object is not a root or system object. Checkpoint must be " "called on a root object." doDrain(system) @@ -162,6 +162,7 @@ def changeToTiming(system): resume(system) def switchCpus(cpuList): + print "switching cpus" if not isinstance(cpuList, list): raise RuntimeError, "Must pass a list to this function" for i in cpuList: @@ -189,9 +190,9 @@ def switchCpus(cpuList): cc_main.cleanupCountedDrain(drain_event) # Now all of the CPUs are ready to be switched out for old_cpu in old_cpus: + print "switching" old_cpu._ccObject.switchOut() index = 0 - print "Switching CPUs" for new_cpu in new_cpus: new_cpu.takeOverFrom(old_cpus[index]) new_cpu._ccObject.resume()