ruby: Wrapped ruby events into m5 events
authorBrad Beckmann <Brad.Beckmann@amd.com>
Sat, 30 Jan 2010 04:29:19 +0000 (20:29 -0800)
committerBrad Beckmann <Brad.Beckmann@amd.com>
Sat, 30 Jan 2010 04:29:19 +0000 (20:29 -0800)
Wrapped ruby events using the m5 event object.  Removed the prio_heap
from ruby's event queue and instead schedule ruby events on the m5 event
queue.

src/mem/ruby/eventqueue/RubyEventQueue.cc
src/mem/ruby/eventqueue/RubyEventQueue.hh
src/mem/ruby/eventqueue/RubyEventQueueNode.cc
src/mem/ruby/eventqueue/RubyEventQueueNode.hh
src/mem/ruby/system/System.cc

index 8e9b7b18db1e9b19f3ee26ae8c35085c112fa469..c497f239a003a3da6532ddb8e910f7c12a3ff635 100644 (file)
 
 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
 #include "mem/ruby/common/Consumer.hh"
-#include "mem/ruby/profiler/Profiler.hh"
 #include "mem/ruby/system/System.hh"
-#include "mem/gems_common/PrioHeap.hh"
 #include "mem/ruby/eventqueue/RubyEventQueueNode.hh"
 
 // Class public method definitions
 
-RubyEventQueue::RubyEventQueue(Tick _clock)
-  : m_clock(_clock)
+RubyEventQueue::RubyEventQueue(EventQueue* eventq, Tick _clock)
+  : EventManager(eventq), m_clock(_clock)
 {
-  m_prio_heap_ptr = NULL;
-  init();
-  assert(g_eventQueue_ptr == NULL);
-  g_eventQueue_ptr = this;
 }
 
 RubyEventQueue::~RubyEventQueue()
 {
-  delete m_prio_heap_ptr;
 }
 
-void RubyEventQueue::init()
-{
-  m_globalTime = 1;
-  m_timeOfLastRecovery = 1;
-  m_prio_heap_ptr = new PrioHeap<RubyEventQueueNode>;
-  m_prio_heap_ptr->init();
-}
-
-bool RubyEventQueue::isEmpty() const
-{
-  return (m_prio_heap_ptr->size() == 0);
+void RubyEventQueue::scheduleEvent(Consumer* consumer, Time timeDelta) 
+{ 
+  scheduleEventAbsolute(consumer, timeDelta + getTime()); 
 }
 
 void RubyEventQueue::scheduleEventAbsolute(Consumer* consumer, Time timeAbs)
 {
   // Check to see if this is a redundant wakeup
-  //  Time time = timeDelta + m_globalTime;
   ASSERT(consumer != NULL);
   if (consumer->getLastScheduledWakeup() != timeAbs) {
     // This wakeup is not redundant
-    RubyEventQueueNode thisNode;
-    thisNode.m_consumer_ptr = consumer;
-    assert(timeAbs > m_globalTime);
-    thisNode.m_time = timeAbs;
-    m_prio_heap_ptr->insert(thisNode);
-    consumer->setLastScheduledWakeup(timeAbs);
-  }
-}
-
-void RubyEventQueue::triggerEvents(Time t)
-{
-  RubyEventQueueNode thisNode;
-
-  while(m_prio_heap_ptr->size() > 0 && m_prio_heap_ptr->peekMin().m_time <= t) {
-    m_globalTime = m_prio_heap_ptr->peekMin().m_time;
-    thisNode = m_prio_heap_ptr->extractMin();
-    assert(thisNode.m_consumer_ptr != NULL);
-    DEBUG_EXPR(EVENTQUEUE_COMP,MedPrio,*(thisNode.m_consumer_ptr));
-    DEBUG_EXPR(EVENTQUEUE_COMP,MedPrio,thisNode.m_time);
-    thisNode.m_consumer_ptr->triggerWakeup(this);
-  }
-  m_globalTime = t;
-}
-
-void RubyEventQueue::triggerAllEvents()
-{
-  // FIXME - avoid repeated code
-  RubyEventQueueNode thisNode;
-
-  while(m_prio_heap_ptr->size() > 0) {
-    m_globalTime = m_prio_heap_ptr->peekMin().m_time;
-    thisNode = m_prio_heap_ptr->extractMin();
-    assert(thisNode.m_consumer_ptr != NULL);
-    DEBUG_EXPR(EVENTQUEUE_COMP,MedPrio,*(thisNode.m_consumer_ptr));
-    DEBUG_EXPR(EVENTQUEUE_COMP,MedPrio,thisNode.m_time);
-    thisNode.m_consumer_ptr->triggerWakeup(this);
+    RubyEventQueueNode *thisNode = new RubyEventQueueNode(consumer);
+    assert(timeAbs > getTime());
+    schedule(thisNode, (timeAbs * m_clock));
+    consumer->setLastScheduledWakeup(timeAbs * m_clock);
   }
 }
 
@@ -118,5 +70,5 @@ void RubyEventQueue::triggerAllEvents()
 void
 RubyEventQueue::print(ostream& out) const
 {
-  out << "[Event Queue: " << *m_prio_heap_ptr << "]";
+  out << "[Event Queue:]";
 }
index 8bd74a36ea2d228ba56dbc3afe7f8aab006589fd..36aa4843eac72e22b403a845e3b0e39d8a4d64b5 100644 (file)
 #include "config/no_vector_bounds_checks.hh"
 #include "mem/ruby/common/Global.hh"
 #include "mem/gems_common/Vector.hh"
+#include "sim/eventq.hh"
 
 class Consumer;
 template <class TYPE> class PrioHeap;
 class RubyEventQueueNode;
 
-class RubyEventQueue {
+class RubyEventQueue : public EventManager {
 public:
   // Constructors
-  RubyEventQueue(Tick clock);
+  RubyEventQueue(EventQueue* eventq, Tick _clock);
 
   // Destructor
   ~RubyEventQueue();
@@ -78,28 +79,21 @@ public:
   // Public Methods
 
   Time getTime() const { return curTick/m_clock; }
-  void scheduleEvent(Consumer* consumer, Time timeDelta) { scheduleEventAbsolute(consumer, timeDelta + m_globalTime); }
+  void scheduleEvent(Consumer* consumer, Time timeDelta);
   void scheduleEventAbsolute(Consumer* consumer, Time timeAbs);
-  void triggerEvents(Time t); // called to handle all events <= time t
-  void triggerAllEvents();
   void print(ostream& out) const;
-  bool isEmpty() const;
 
-  Time getTimeOfLastRecovery() {return m_timeOfLastRecovery;}
-  void setTimeOfLastRecovery(Time t) {m_timeOfLastRecovery = t;}
+  void triggerEvents(Time t) { assert(0); }
+  void triggerAllEvents() { assert(0); }
 
   // Private Methods
 private:
   // Private copy constructor and assignment operator
-  void init();
   RubyEventQueue(const RubyEventQueue& obj);
   RubyEventQueue& operator=(const RubyEventQueue& obj);
 
   // Data Members (m_ prefix)
   Tick m_clock;
-  PrioHeap<RubyEventQueueNode>* m_prio_heap_ptr;
-  Time m_globalTime;
-  Time m_timeOfLastRecovery;
 };
 
 // Output operator declaration
index 2783f5edebc1bb5f697c8f177fca42bae8971597..5034069cc71ee3b55199319a551555d9b1e325f9 100644 (file)
@@ -37,7 +37,6 @@
 void RubyEventQueueNode::print(ostream& out) const
 {
   out << "[";
-  out << "Time=" << m_time;
   if (m_consumer_ptr != NULL) {
     out << " Consumer=" << m_consumer_ptr;
   } else {
index fa66ab9a65fd06408737b0b3d7e2df37951a92e2..3b0c231623778d76eb4cb3dcf1c5224d0189ea38 100644 (file)
 #define RUBYEVENTQUEUENODE_H
 
 #include "mem/ruby/common/Global.hh"
-class Consumer;
+#include "sim/eventq.hh"
+#include "mem/ruby/common/Consumer.hh"
+//class Consumer;
 
-class RubyEventQueueNode {
+class RubyEventQueueNode : public Event {
 public:
   // Constructors
-  RubyEventQueueNode() { m_time = 0; m_consumer_ptr = NULL; }
+  RubyEventQueueNode(Consumer* _consumer) 
+    : m_consumer_ptr(_consumer)
+  { 
+    setFlags(AutoDelete); 
+  }
 
   // Destructor
   //~RubyEventQueueNode();
 
   // Public Methods
   void print(ostream& out) const;
+  virtual void process() { m_consumer_ptr->wakeup(); }
+  virtual const char *description() const { return "Ruby Event"; }
 
-  // Assignment operator and copy constructor since the default
-  // constructors confuse purify when long longs are present.
-  RubyEventQueueNode& operator=(const RubyEventQueueNode& obj) {
-    m_time = obj.m_time;
-    m_consumer_ptr = obj.m_consumer_ptr;
-    return *this;
-  }
-
-  RubyEventQueueNode(const RubyEventQueueNode& obj) {
-    m_time = obj.m_time;
-    m_consumer_ptr = obj.m_consumer_ptr;
-  }
 private:
   // Private Methods
 
@@ -68,8 +64,6 @@ private:
   // RubyEventQueueNode(const RubyEventQueueNode& obj);
 
   // Data Members (m_ prefix)
-public:
-  Time m_time;
   Consumer* m_consumer_ptr;
 };
 
@@ -78,14 +72,6 @@ ostream& operator<<(ostream& out, const RubyEventQueueNode& obj);
 
 // ******************* Definitions *******************
 
-inline extern bool node_less_then_eq(const RubyEventQueueNode& n1, const RubyEventQueueNode& n2);
-
-inline extern
-bool node_less_then_eq(const RubyEventQueueNode& n1, const RubyEventQueueNode& n2)
-{
-  return (n1.m_time <= n2.m_time);
-}
-
 // Output operator definition
 extern inline
 ostream& operator<<(ostream& out, const RubyEventQueueNode& obj)
index 2dd978caddb1faeb41177647001058f497a9a160..ec7218680beec8a3f26e4f486d797f1d863ac871 100644 (file)
@@ -105,7 +105,7 @@ RubySystem::RubySystem(const Params *p)
     m_profiler_ptr = p->profiler;
     m_tracer_ptr = p->tracer;
 
-    g_eventQueue_ptr = new RubyEventQueue(m_clock);
+    g_eventQueue_ptr = new RubyEventQueue(p->eventq, m_clock);
     g_system_ptr = this;
     m_mem_vec_ptr = new MemoryVector;
     m_mem_vec_ptr->setSize(m_memory_size_bytes);