changeset b1beee9351a4 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=b1beee9351a4
summary: eventq: Clean up the Event class so that it uses fewer bytes. This

diffstat:

2 files changed, 2 insertions(+), 4 deletions(-)
src/sim/eventq.cc |    3 +--
src/sim/eventq.hh |    3 +--

diffs (truncated from 427 to 300 lines):

diff -r 57e76b2fde15 -r b1beee9351a4 src/sim/eventq.cc
--- a/src/sim/eventq.cc Tue Jul 01 10:30:08 2008 -0400
+++ b/src/sim/eventq.cc Thu Jul 10 21:35:42 2008 -0700
@@ -30,18 +30,16 @@
  *          Steve Raasch
  */
 
-#include <assert.h>
-
+#include <cassert>
 #include <iostream>
 #include <string>
 #include <vector>
 
+#include "base/misc.hh"
+#include "base/trace.hh"
 #include "cpu/smt.hh"
-#include "base/misc.hh"
-
+#include "sim/core.hh"
 #include "sim/eventq.hh"
-#include "base/trace.hh"
-#include "sim/core.hh"
 
 using namespace std;
 
@@ -203,7 +201,7 @@
 }
 
 void
-EventQueue::dump()
+EventQueue::dump() const
 {
     cprintf("============================================================\n");
     cprintf("EventQueue Dump  (cycle %d)\n", curTick);
@@ -235,7 +233,6 @@
     return "generic";
 }
 
-#if TRACING_ON
 void
 Event::trace(const char *action)
 {
@@ -250,23 +247,21 @@
     // needs to be printed.
     DPRINTFN("%s event %s @ %d\n", description(), action, when());
 }
-#endif
 
 void
-Event::dump()
+Event::dump() const
 {
-    cprintf("Event  (%s)\n", description());
+    cprintf("Event %s (%s)\n", name(), description());
     cprintf("Flags: %#x\n", _flags);
-#if TRACING_ON
-    cprintf("Created: %d\n", when_created);
+#ifdef EVENTQ_DEBUG
+    cprintf("Created: %d\n", whenCreated);
 #endif
     if (scheduled()) {
-#if TRACING_ON
-        cprintf("Scheduled at  %d\n", when_scheduled);
+#ifdef EVENTQ_DEBUG
+        cprintf("Scheduled at  %d\n", whenScheduled);
 #endif
         cprintf("Scheduled for %d, priority %d\n", when(), _priority);
-    }
-    else {
+    } else {
         cprintf("Not Scheduled\n");
     }
 }
diff -r 57e76b2fde15 -r b1beee9351a4 src/sim/eventq.hh
--- a/src/sim/eventq.hh Tue Jul 01 10:30:08 2008 -0400
+++ b/src/sim/eventq.hh Thu Jul 10 21:35:42 2008 -0700
@@ -36,19 +36,17 @@
 #ifndef __SIM_EVENTQ_HH__
 #define __SIM_EVENTQ_HH__
 
-#include <assert.h>
-
 #include <algorithm>
+#include <cassert>
 #include <map>
 #include <string>
 #include <vector>
-
-#include "sim/host.hh" // for Tick
 
 #include "base/fast_alloc.hh"
 #include "base/misc.hh"
 #include "base/trace.hh"
 #include "sim/serialize.hh"
+#include "sim/host.hh"
 
 class EventQueue;      // forward declaration
 
@@ -64,17 +62,27 @@
 //////////////////////
 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.
+ *
+ * Caution, the order of members is chosen to maximize data packing.
  */
 class Event : public Serializable, public FastAlloc
 {
     friend class EventQueue;
 
   private:
+    Event *next;
+
+    /// queue to which this event belongs (though it may or may not be
+    /// scheduled on this queue yet)
+    EventQueue *_queue;
+
+    Tick _when;                //!< timestamp when event should be processed
+    short _priority;   //!< event priority
+    short _flags;
 
 #ifndef NDEBUG
     /// Global counter to generate unique IDs for Event instances
@@ -84,19 +92,13 @@
     /// this but they're not consistent across runs making debugging
     /// more difficult.  Thus we use a global counter value when
     /// debugging.
-    Counter instanceId;
-#endif // NDEBUG
+    Counter instance;
+#endif
 
-    /// queue to which this event belongs (though it may or may not be
-    /// scheduled on this queue yet)
-    EventQueue *queue;
-
-    Event *next;
-
-    Tick _when;        //!< timestamp when event should be processed
-    int _priority;     //!< event priority
-    char _flags;
-
+#ifdef DEBUG_EVENTQ
+    Tick whenCreated;   //!< time created
+    Tick whenScheduled; //!< time scheduled
+#endif
   protected:
     enum Flags {
         None = 0x0,
@@ -112,26 +114,20 @@
     void clearFlags(Flags f) { _flags &= ~f; }
 
   protected:
-    EventQueue *theQueue() const { return queue; }
+    EventQueue *queue() const { return _queue; }
 
-#if TRACING_ON
-    Tick when_created; //!< Keep track of creation time For debugging
-    Tick when_scheduled;       //!< Keep track of creation time For debugging
-
+    // This function isn't really useful if TRACING_ON is not defined
     virtual void trace(const char *action);    //!< trace event activity
-#else
-    void trace(const char *) {}
-#endif
-
-    unsigned annotated_value;
 
   public:
-
     /// 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 {
+        /// Minimum priority
+        Minimum_Pri            = SHRT_MIN,
+
         /// If we enable tracing on a particular cycle, do that as the
         /// very first thing so we don't miss any of the events on
         /// that cycle (even if we enter the debugger).
@@ -174,7 +170,10 @@
 
         /// If we want to exit on this cycle, it's the very last thing
         /// we do.
-        Sim_Exit_Pri           =  100
+        Sim_Exit_Pri           =  100,
+
+        /// Maximum priority
+        Maximum_Pri            = SHRT_MAX
     };
 
     /*
@@ -182,26 +181,52 @@
      * @param queue that the event gets scheduled on
      */
     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
-          annotated_value(0)
+        : next(NULL), _queue(q), _priority(p), _flags(None)
     {
 #ifndef NDEBUG
-        instanceId = ++instanceCounter;
+        instance = ++instanceCounter;
+#endif
+#ifdef EVENTQ_DEBUG
+        whenCreated = curTick;
+        whenScheduled = 0;
 #endif
     }
 
-    ~Event() {}
+    virtual
+    ~Event()
+    {
+    }
 
-    virtual const std::string name() const {
+    virtual const std::string
+    name() const
+    {
 #ifndef NDEBUG
-        return csprintf("Event_%d", instanceId);
+        return csprintf("Event_%d", instance);
 #else
         return csprintf("Event_%x", (uintptr_t)this);
 #endif
     }
+
+    /// Return a C string describing the event.  This string should
+    /// *not* be dynamically allocated; just a const char array
+    /// describing the event class.
+    virtual const char *description() const;
+
+    /// Dump the current event data
+    void dump() const;
+
+  public:
+    /*
+     * This member function is invoked when the event is processed
+     * (occurs).  There is no default implementation; each subclass
+     * must provide its own implementation.  The event is not
+     * automatically deleted after it is processed (to allow for
+     * statically allocated event objects).
+     *
+     * If the AutoDestroy flag is set, the object is deleted once it
+     * is processed.
+     */
+    virtual void process() = 0;
 
     /// Determine if the current event is scheduled
     bool scheduled() const { return getFlags(Scheduled); }
@@ -216,37 +241,14 @@
     /// Remove the event from the current schedule
     void deschedule();
 
-    /// Return a C string describing the event.  This string should
-    /// *not* be dynamically allocated; just a const char array
-    /// describing the event class.
-    virtual const char *description() const;
-
-    /// Dump the current event data
-    void dump();
-
-    /*
-     * This member function is invoked when the event is processed
-     * (occurs).  There is no default implementation; each subclass
-     * must provide its own implementation.  The event is not
-     * automatically deleted after it is processed (to allow for
-     * statically allocated event objects).
-     *
-     * If the AutoDestroy flag is set, the object is deleted once it
-     * is processed.
-     */
-    virtual void process() = 0;
-
-    void annotate(unsigned value) { annotated_value = value; };
-    unsigned annotation() { return annotated_value; }
-
     /// Squash the current event
     void squash() { setFlags(Squashed); }
 
     /// Check whether the event is squashed
-    bool squashed() { return getFlags(Squashed); }
+    bool squashed() const { return getFlags(Squashed); }
 
     /// See if this is a SimExitEvent (without resorting to RTTI)
-    bool isExitEvent() { return getFlags(IsExitEvent); }
+    bool isExitEvent() const { return getFlags(IsExitEvent); }
 
     /// Get the time that the event is scheduled
     Tick when() const { return _when; }
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to