From e15abd17f92db574dfcbf3798f6352712f897ebc Mon Sep 17 00:00:00 2001 From: Brad Beckmann Date: Fri, 29 Jan 2010 20:29:19 -0800 Subject: ruby: Wrapped ruby events into m5 events 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 | 68 ++++----------------------- src/mem/ruby/eventqueue/RubyEventQueue.hh | 18 +++---- src/mem/ruby/eventqueue/RubyEventQueueNode.cc | 1 - src/mem/ruby/eventqueue/RubyEventQueueNode.hh | 36 +++++--------- src/mem/ruby/system/System.cc | 2 +- 5 files changed, 28 insertions(+), 97 deletions(-) diff --git a/src/mem/ruby/eventqueue/RubyEventQueue.cc b/src/mem/ruby/eventqueue/RubyEventQueue.cc index 8e9b7b18d..c497f239a 100644 --- a/src/mem/ruby/eventqueue/RubyEventQueue.cc +++ b/src/mem/ruby/eventqueue/RubyEventQueue.cc @@ -33,83 +33,35 @@ #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; - 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:]"; } diff --git a/src/mem/ruby/eventqueue/RubyEventQueue.hh b/src/mem/ruby/eventqueue/RubyEventQueue.hh index 8bd74a36e..36aa4843e 100644 --- a/src/mem/ruby/eventqueue/RubyEventQueue.hh +++ b/src/mem/ruby/eventqueue/RubyEventQueue.hh @@ -62,15 +62,16 @@ #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 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* m_prio_heap_ptr; - Time m_globalTime; - Time m_timeOfLastRecovery; }; // Output operator declaration diff --git a/src/mem/ruby/eventqueue/RubyEventQueueNode.cc b/src/mem/ruby/eventqueue/RubyEventQueueNode.cc index 2783f5ede..5034069cc 100644 --- a/src/mem/ruby/eventqueue/RubyEventQueueNode.cc +++ b/src/mem/ruby/eventqueue/RubyEventQueueNode.cc @@ -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 { diff --git a/src/mem/ruby/eventqueue/RubyEventQueueNode.hh b/src/mem/ruby/eventqueue/RubyEventQueueNode.hh index fa66ab9a6..3b0c23162 100644 --- a/src/mem/ruby/eventqueue/RubyEventQueueNode.hh +++ b/src/mem/ruby/eventqueue/RubyEventQueueNode.hh @@ -36,31 +36,27 @@ #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) diff --git a/src/mem/ruby/system/System.cc b/src/mem/ruby/system/System.cc index 2dd978cad..ec7218680 100644 --- a/src/mem/ruby/system/System.cc +++ b/src/mem/ruby/system/System.cc @@ -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); -- cgit v1.2.3