Serialization support for Alpha TLBs, PhysicalMemory, and SimpleCPU.
authorSteve Reinhardt <stever@eecs.umich.edu>
Wed, 29 Oct 2003 21:35:07 +0000 (13:35 -0800)
committerSteve Reinhardt <stever@eecs.umich.edu>
Wed, 29 Oct 2003 21:35:07 +0000 (13:35 -0800)
arch/alpha/alpha_memory.cc:
arch/alpha/alpha_memory.hh:
    Serialize TLB contents.
cpu/simple_cpu/simple_cpu.cc:
cpu/simple_cpu/simple_cpu.hh:
    Complete serialization of SimpleCPU (including owned events).
sim/eventq.cc:
sim/eventq.hh:
    Basic serialization for events.
    Still need to handle dynamic events (not owned by a SimObject).
sim/serialize.cc:
sim/serialize.hh:
    Export serialization filename so PhysicalMemory can
    derive its filename from that.

--HG--
extra : convert_revision : 4db851c5880f73f576ca092d5e5ad4256048eb51

arch/alpha/alpha_memory.cc
arch/alpha/alpha_memory.hh
cpu/simple_cpu/simple_cpu.cc
cpu/simple_cpu/simple_cpu.hh
sim/eventq.cc
sim/eventq.hh
sim/serialize.cc
sim/serialize.hh

index b959161054e4da70b9c00850d7c02b9f37d578f3..7c0b1120fe87f2fccdf80342b2128ac6366645bf 100644 (file)
@@ -197,47 +197,10 @@ AlphaTlb::serialize(ostream &os)
     SERIALIZE_SCALAR(size);
     SERIALIZE_SCALAR(nlu);
 
-    // should just add serialize/unserialize methods to AlphaPTE
-#if 0
-    stringstream buf;
     for (int i = 0; i < size; i++) {
-        buf.str("");
-        ccprintf(buf, "pte%02d.valid", i);
-        paramOut(buf.str(), table[i].valid);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.tag", i);
-        paramOut(buf.str(), table[i].tag);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.ppn", i);
-        paramOut(buf.str(), table[i].ppn);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.xre", i);
-        paramOut(buf.str(), table[i].xre);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.xwe", i);
-        paramOut(buf.str(), table[i].xwe);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.fonr", i);
-        paramOut(buf.str(), table[i].fonr);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.fonw", i);
-        paramOut(buf.str(), table[i].fonw);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.asma", i);
-        paramOut(buf.str(), table[i].asma);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.asn", i);
-        paramOut(buf.str(), table[i].asn);
+        nameOut(os, csprintf("%s.PTE%d", name(), i));
+        table[i].serialize(os);
     }
-#endif
 }
 
 void
@@ -246,56 +209,12 @@ AlphaTlb::unserialize(const IniFile *db, const string &section)
     UNSERIALIZE_SCALAR(size);
     UNSERIALIZE_SCALAR(nlu);
 
-#if 0
-    string data;
-    stringstream buf;
     for (int i = 0; i < size; i++) {
-        buf.str("");
-        ccprintf(buf, "pte%02d.valid", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].valid);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.tag", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].tag);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.ppn", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].ppn);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.xre", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].xre);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.xwe", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].xwe);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.fonr", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].fonr);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.fonw", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].fonw);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.asma", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].asma);
-
-        buf.str("");
-        ccprintf(buf, "pte%02d.asn", i);
-        db.findDefault(category, buf.str(), data);
-        to_number(data, table[i].asn);
+        table[i].unserialize(db, csprintf("%s.PTE%d", section, i));
+        if (table[i].valid) {
+            lookupTable.insert(make_pair(table[i].tag, i));
+        }
     }
-#endif
 }
 
 
index e6637893cbc69df9fe77c205d6169af52f76868c..fc4d46191406ab9aa9e85034bb48feadbcef3c18 100644 (file)
@@ -75,7 +75,6 @@ class AlphaTlb : public SimObject
     // Checkpointing
     virtual void serialize(std::ostream &os);
     virtual void unserialize(const IniFile *db, const std::string &section);
-
 };
 
 class AlphaItb : public AlphaTlb
index 27576d55867e4ad1f36fac624c7cfef44b77e5e5..3179b7b1f420c30a70b8dfc1b7bbaba3a22fd8bc 100644 (file)
 
 using namespace std;
 
+SimpleCPU::TickEvent::TickEvent(SimpleCPU *c)
+    : Event(&mainEventQueue, "SimpleCPU::TickEvent", 100), cpu(c)
+{
+}
+
+void
+SimpleCPU::TickEvent::process()
+{
+    cpu->tick();
+}
+
+const char *
+SimpleCPU::TickEvent::description()
+{
+    return "SimpleCPU tick event";
+}
+
+
 SimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu)
-    : Event(&mainEventQueue),
+    : Event(&mainEventQueue, "SimpleCPU::CacheCompletionEvent"),
       cpu(_cpu)
 {
 }
@@ -89,7 +107,7 @@ void SimpleCPU::CacheCompletionEvent::process()
 const char *
 SimpleCPU::CacheCompletionEvent::description()
 {
-    return "cache completion event";
+    return "SimpleCPU cache completion event";
 }
 
 #ifdef FULL_SYSTEM
@@ -242,17 +260,24 @@ SimpleCPU::regStats()
 void
 SimpleCPU::serialize(ostream &os)
 {
+    SERIALIZE_ENUM(_status);
+    SERIALIZE_SCALAR(inst);
     xc->serialize(os);
+    nameOut(os, csprintf("%s.tickEvent", name()));
+    tickEvent.serialize(os);
+    nameOut(os, csprintf("%s.cacheCompletionEvent", name()));
+    cacheCompletionEvent.serialize(os);
 }
 
 void
-SimpleCPU::unserialize(const IniFile *db, const string &category)
+SimpleCPU::unserialize(const IniFile *db, const string &section)
 {
-    xc->unserialize(db, category);
-
-    // Read in Special registers
-
-    // CPUTraitsType::unserializeSpecialRegs(db,category,node,xc->regs);
+    UNSERIALIZE_ENUM(_status);
+    UNSERIALIZE_SCALAR(inst);
+    xc->unserialize(db, section);
+    tickEvent.unserialize(db, csprintf("%s.tickEvent", name()));
+    cacheCompletionEvent
+        .unserialize(db, csprintf("%s.cacheCompletionEvent", name()));
 }
 
 void
index aee8159ce204df74cf06a797e7a253d052a4a5ac..61831cb3c963aa40c848bdeb123939bbc409f6be 100644 (file)
@@ -68,10 +68,9 @@ class SimpleCPU : public BaseCPU
         SimpleCPU *cpu;
 
       public:
-        TickEvent(SimpleCPU *c)
-            : Event(&mainEventQueue, 100), cpu(c) { }
-        void process() { cpu->tick(); }
-        virtual const char *description() { return "tick event"; }
+        TickEvent(SimpleCPU *c);
+        void process();
+        const char *description();
     };
 
     TickEvent tickEvent;
index 7138d868846098ad6f80bbd694ef8d26c4ba58a2..77eb490c74e0eff813b1c3bb9226a00af5cbb248 100644 (file)
@@ -118,6 +118,39 @@ EventQueue::serviceOne()
         delete event;
 }
 
+
+void
+Event::serialize(std::ostream &os)
+{
+    SERIALIZE_SCALAR(_when);
+    SERIALIZE_SCALAR(_priority);
+    SERIALIZE_ENUM(_flags);
+}
+
+
+void
+Event::unserialize(const IniFile *db, const string &section)
+{
+    if (scheduled())
+        deschedule();
+
+    UNSERIALIZE_SCALAR(_when);
+    UNSERIALIZE_SCALAR(_priority);
+
+    // need to see if original event was in a scheduled, unsquashed
+    // state, but don't want to restore those flags in the current
+    // object itself (since they aren't immediately true)
+    UNSERIALIZE_ENUM(_flags);
+    bool wasScheduled = (_flags & Scheduled) && !(_flags & Squashed);
+    _flags &= ~(Squashed | Scheduled);
+
+    if (wasScheduled) {
+        DPRINTF(Config, "rescheduling at %d\n", _when);
+        schedule(_when);
+    }
+}
+
+
 void
 EventQueue::nameChildren()
 {
index cd86512e4daab422cb44c31d803e7c79de0a112c..a8eae12485724497be458a8d7659b130200bb1ad 100644 (file)
@@ -112,6 +112,20 @@ class Event : public Serializeable, public FastAlloc
     {
     }
 
+    /*
+     * Event constructor
+     * @param queue that the event gets scheduled on
+     */
+    Event(EventQueue *q, std::string _name, int p = 0)
+        : Serializeable(_name), queue(q), next(NULL),
+          _priority(p), _flags(None),
+#if TRACING_ON
+          when_created(curTick), when_scheduled(0),
+#endif
+          annotated_value(0)
+    {
+    }
+
     ~Event() {}
 
     /// Determine if the current event is scheduled
@@ -174,6 +188,9 @@ class Event : public Serializeable, public FastAlloc
             return l->when() >= r->when() || l->priority() >= r->priority();
         }
     };
+
+    virtual void serialize(std::ostream &os);
+    virtual void unserialize(const IniFile *db, const std::string &section);
 };
 
 template <class T, void (T::* F)()>
index 00321b93238e148b0aa371fbef446f8d588c90cd..f838acc8d9c5a5487896a9604cedcbbe7984c9c3 100644 (file)
@@ -355,6 +355,10 @@ Param<string> serialize_file(&serialParams,
                              "file",
                              "file to write to", "");
 
+// Copy filename into regular string so we can export it without
+// having to include param.hh all over the place.
+string serializeFilename;
+
 SerializeParamContext::SerializeParamContext(const string &section)
     : ParamContext(section), event(NULL)
 { }
@@ -366,9 +370,10 @@ SerializeParamContext::~SerializeParamContext()
 void
 SerializeParamContext::checkParams()
 {
-    if (!((string)serialize_file).empty() && serialize_cycle > 0)
-    event = new SerializeEvent(&mainEventQueue, serialize_cycle,
-                               serialize_file);
+    serializeFilename = serialize_file;
+    if (!serializeFilename.empty() && serialize_cycle > 0)
+        event = new SerializeEvent(&mainEventQueue, serialize_cycle,
+                                   serializeFilename);
 }
 
 void
index d7842b47d25cc63ace6ab7eceb2d8762fddd1167..4e0dbd1bd9313e62576afe6957451c0a206ca82b 100644 (file)
@@ -235,5 +235,10 @@ SerializeableClass the##OBJ_CLASS##Class(CLASS_NAME,               \
                                      new##OBJ_CLASS##Builder);
 
 
+//
+// Export checkpoint filename param so other objects can derive
+// filenames from it (e.g., memory).
+//
+extern std::string serializeFilename;
 
 #endif // __SERIALIZE_HH__