Move trace data function to .cc file.
[gem5.git] / sim / eventq.cc
index da9e85eeb6924d77d038e2ea1e7c163c9305ac2d..f975c5e974797927b0ddff58c175d790ae960fe7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2000-2003 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 using namespace std;
 
-const string Event::defaultName("event");
-
 //
 // Main Event Queue
 //
 // Events on this queue are processed at the *beginning* of each
 // cycle, before the pipeline simulation is performed.
 //
-EventQueue mainEventQueue("Main Event Queue");
+EventQueue mainEventQueue("MainEventQueue");
 
 void
 EventQueue::insert(Event *event)
@@ -114,40 +112,80 @@ EventQueue::serviceOne()
     else
         event->clearFlags(Event::Squashed);
 
-    if (event->getFlags(Event::AutoDelete))
+    if (event->getFlags(Event::AutoDelete) && !event->scheduled())
         delete event;
 }
 
+
 void
-EventQueue::nameChildren()
+Event::serialize(std::ostream &os)
 {
-    int j = 0;
+    SERIALIZE_SCALAR(_when);
+    SERIALIZE_SCALAR(_priority);
+    SERIALIZE_ENUM(_flags);
+}
 
-    Event *event = head;
-    while (event) {
-        stringstream stream;
-        ccprintf(stream, "%s.event%d", name(), j++);
-        event->setName(stream.str());
 
-        event = event->next;
+void
+Event::unserialize(Checkpoint *cp, 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::serialize(ostream &os)
 {
-    string objects = "";
+    std::list<Event *> eventPtrs;
 
+    int numEvents = 0;
     Event *event = head;
     while (event) {
-        objects += event->name();
-        objects += " ";
-        event->serialize(os);
-
+        if (event->getFlags(Event::AutoSerialize)) {
+            eventPtrs.push_back(event);
+            paramOut(os, csprintf("event%d", numEvents++), event->name());
+        }
         event = event->next;
     }
-    nameOut(os, "Serialized");
-    SERIALIZE_MEMBER(objects);
+
+    SERIALIZE_SCALAR(numEvents);
+
+    for (std::list<Event *>::iterator it=eventPtrs.begin();
+         it != eventPtrs.end(); ++it) {
+        (*it)->nameOut(os);
+        (*it)->serialize(os);
+    }
+}
+
+void
+EventQueue::unserialize(Checkpoint *cp, const std::string &section)
+{
+    int numEvents;
+    UNSERIALIZE_SCALAR(numEvents);
+
+    std::string eventName;
+    for (int i = 0; i < numEvents; i++) {
+        // get the pointer value associated with the event
+        paramIn(cp, section, csprintf("event%d", i), eventName);
+
+        // create the event based on its pointer value
+        Serializable::create(cp, eventName);
+    }
 }
 
 void
@@ -170,6 +208,13 @@ EventQueue::dump()
     cprintf("============================================================\n");
 }
 
+extern "C"
+void
+dumpMainQueue()
+{
+    mainEventQueue.dump();
+}
+
 
 const char *
 Event::description()
@@ -197,16 +242,18 @@ Event::trace(const char *action)
 void
 Event::dump()
 {
+    cprintf("Event  (%s)\n", description());
+    cprintf("Flags: %#x\n", _flags);
 #if TRACING_ON
-    cprintf("   Created: %d\n", when_created);
+    cprintf("Created: %d\n", when_created);
 #endif
     if (scheduled()) {
 #if TRACING_ON
-        cprintf("   Scheduled at  %d\n", when_scheduled);
+        cprintf("Scheduled at  %d\n", when_scheduled);
 #endif
-        cprintf("   Scheduled for %d\n", when());
+        cprintf("Scheduled for %d, priority %d\n", when(), _priority);
     }
     else {
-        cprintf("   Not Scheduled\n");
+        cprintf("Not Scheduled\n");
     }
 }