#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);
}
}
void
RubyEventQueue::print(ostream& out) const
{
- out << "[Event Queue: " << *m_prio_heap_ptr << "]";
+ out << "[Event Queue:]";
}
#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();
// 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
#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
// RubyEventQueueNode(const RubyEventQueueNode& obj);
// Data Members (m_ prefix)
-public:
- Time m_time;
Consumer* m_consumer_ptr;
};
// ******************* 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)