Merge zizzer.eecs.umich.edu:/bk/m5
[gem5.git] / sim / eventq.hh
index a8eae12485724497be458a8d7659b130200bb1ad..d62e7df10a7954ab561dbbf0aab797bf2dffe65c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2000-2004 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,8 +30,8 @@
  * EventQueue interfaces
  */
 
-#ifndef __EVENTQ_HH__
-#define __EVENTQ_HH__
+#ifndef __SIM_EVENTQ_HH__
+#define __SIM_EVENTQ_HH__
 
 #include <assert.h>
 
 #include "sim/host.hh" // for Tick
 
 #include "base/fast_alloc.hh"
-#include "sim/serialize.hh"
 #include "base/trace.hh"
+#include "sim/serialize.hh"
 
 class EventQueue;      // forward declaration
 
+//////////////////////
+//
+// Main Event Queue
+//
+// Events on this queue are processed at the *beginning* of each
+// cycle, before the pipeline simulation is performed.
+//
+// defined in eventq.cc
+//
+//////////////////////
+extern EventQueue mainEventQueue;
+
+
 /*
  * An item on an event queue.  The action caused by a given
  * event is specified by deriving a subclass and overriding the
  * process() member function.
  */
-class Event : public Serializeable, public FastAlloc
+class Event : public Serializable, public FastAlloc
 {
     friend class EventQueue;
 
@@ -73,7 +86,8 @@ class Event : public Serializeable, public FastAlloc
         None = 0x0,
         Squashed = 0x1,
         Scheduled = 0x2,
-        AutoDelete = 0x4
+        AutoDelete = 0x4,
+        AutoSerialize = 0x8
     };
 
     bool getFlags(Flags f) const { return (_flags & f) == f; }
@@ -96,29 +110,53 @@ class Event : public Serializeable, public FastAlloc
 
   public:
 
-    static const std::string defaultName;
-
-    /*
-     * Event constructor
-     * @param queue that the event gets scheduled on
-     */
-    Event(EventQueue *q, int p = 0)
-        : Serializeable(defaultName), queue(q), next(NULL),
-          _priority(p), _flags(None),
-#if TRACING_ON
-          when_created(curTick), when_scheduled(0),
-#endif
-          annotated_value(0)
-    {
-    }
+    /// Event priorities, to provide tie-breakers for events scheduled
+    /// at the same cycle.  Most events are scheduled at the default
+    /// priority; these values are used to control events that need to
+    /// be ordered within a cycle.
+    enum Priority {
+        /// Breakpoints should happen before anything else, so we
+        /// don't miss any action when debugging.
+        Debug_Break_Pri                = -100,
+
+        /// For some reason "delayed" inter-cluster writebacks are
+        /// scheduled before regular writebacks (which have default
+        /// priority).  Steve?
+        Delayed_Writeback_Pri  =   -1,
+
+        /// Default is zero for historical reasons.
+        Default_Pri            =    0,
+
+        /// CPU switches schedule the new CPU's tick event for the
+        /// same cycle (after unscheduling the old CPU's tick event).
+        /// The switch needs to come before any tick events to make
+        /// sure we don't tick both CPUs in the same cycle.
+        CPU_Switch_Pri         =   31,
+
+        /// Serailization needs to occur before tick events also, so
+        /// that a serialize/unserialize is identical to an on-line
+        /// CPU switch.
+        Serialize_Pri          =   32,
+
+        /// CPU ticks must come after other associated CPU events
+        /// (such as writebacks).
+        CPU_Tick_Pri           =   50,
+
+        /// Statistics events (dump, reset, etc.) come after
+        /// everything else, but before exit.
+        Stat_Event_Pri         =   90,
+
+        /// If we want to exit on this cycle, it's the very last thing
+        /// we do.
+        Sim_Exit_Pri           =  100
+    };
 
     /*
      * 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),
+    Event(EventQueue *q, Priority p = Default_Pri)
+        : queue(q), next(NULL), _priority(p), _flags(None),
 #if TRACING_ON
           when_created(curTick), when_scheduled(0),
 #endif
@@ -128,21 +166,19 @@ class Event : public Serializeable, public FastAlloc
 
     ~Event() {}
 
+    virtual const std::string name() const {
+        return csprintf("Event_%x", (uintptr_t)this);
+    }
+
     /// Determine if the current event is scheduled
     bool scheduled() const { return getFlags(Scheduled); }
 
     /// Schedule the event with the current priority or default priority
     void schedule(Tick t);
 
-    /// Schedule the event with a specific priority
-    void schedule(Tick t, int priority);
-
     /// Reschedule the event with the current priority
     void reschedule(Tick t);
 
-    /// Reschedule the event with a specific priority
-    void reschedule(Tick t, int priority);
-
     /// Remove the event from the current schedule
     void deschedule();
 
@@ -190,7 +226,7 @@ class Event : public Serializeable, public FastAlloc
     };
 
     virtual void serialize(std::ostream &os);
-    virtual void unserialize(const IniFile *db, const std::string &section);
+    virtual void unserialize(Checkpoint *cp, const std::string &section);
 };
 
 template <class T, void (T::* F)()>
@@ -205,7 +241,7 @@ DelayFunction(Tick when, T *object)
       public:
         DelayEvent(Tick when, T *o)
             : Event(&mainEventQueue), object(o)
-            { setFlags(AutoDestroy); schedule(when); }
+            { setFlags(this->AutoDestroy); schedule(when); }
         void process() { (object->*F)(); }
         const char *description() { return "delay"; }
     };
@@ -213,11 +249,31 @@ DelayFunction(Tick when, T *object)
     new DelayEvent(when, object);
 }
 
+template <class T, void (T::* F)()>
+class EventWrapper : public Event
+{
+  private:
+    T *object;
+
+  public:
+    EventWrapper(T *obj, bool del = false, EventQueue *q = &mainEventQueue,
+                 Priority p = Default_Pri)
+        : Event(q, p), object(obj)
+    {
+        if (del)
+            setFlags(AutoDelete);
+    }
+    void process() { (object->*F)(); }
+};
+
 /*
  * Queue of events sorted in time order
  */
-class EventQueue : public Serializeable
+class EventQueue : public Serializable
 {
+  protected:
+    std::string objName;
+
   private:
     Event *head;
 
@@ -228,9 +284,11 @@ class EventQueue : public Serializeable
 
     // constructor
     EventQueue(const std::string &n)
-        : Serializeable(n), head(NULL)
+        : objName(n), head(NULL)
     {}
 
+    virtual const std::string name() const { return objName; }
+
     // schedule the given event on this queue
     void schedule(Event *ev);
     void deschedule(Event *ev);
@@ -262,8 +320,8 @@ class EventQueue : public Serializeable
 
     Tick nextEventTime() { return empty() ? curTick : head->when(); }
 
-    virtual void nameChildren();
     virtual void serialize(std::ostream &os);
+    virtual void unserialize(Checkpoint *cp, const std::string &section);
 };
 
 
@@ -282,6 +340,8 @@ inline void
 Event::schedule(Tick t)
 {
     assert(!scheduled());
+    assert(t >= curTick);
+
     setFlags(Scheduled);
 #if TRACING_ON
     when_scheduled = curTick;
@@ -290,13 +350,6 @@ Event::schedule(Tick t)
     queue->schedule(this);
 }
 
-inline void
-Event::schedule(Tick t, int p)
-{
-    _priority = p;
-    schedule(t);
-}
-
 inline void
 Event::deschedule()
 {
@@ -320,13 +373,6 @@ Event::reschedule(Tick t)
     queue->reschedule(this);
 }
 
-inline void
-Event::reschedule(Tick t, int p)
-{
-    _priority = p;
-    reschedule(t);
-}
-
 inline void
 EventQueue::schedule(Event *event)
 {
@@ -353,16 +399,5 @@ EventQueue::reschedule(Event *event)
 }
 
 
-//////////////////////
-//
-// Main Event Queue
-//
-// Events on this queue are processed at the *beginning* of each
-// cycle, before the pipeline simulation is performed.
-//
-// defined in eventq.cc
-//
-//////////////////////
-extern EventQueue mainEventQueue;
 
-#endif // __EVENTQ_HH__
+#endif // __SIM_EVENTQ_HH__