#include "base/misc.hh"
#include "base/trace.hh"
#include "cpu/smt.hh"
+#include "debug/Config.hh"
#include "sim/core.hh"
-#include "sim/eventq.hh"
+#include "sim/eventq_impl.hh"
using namespace std;
// Events on this queue are processed at the *beginning* of each
// cycle, before the pipeline simulation is performed.
//
-EventQueue mainEventQueue("MainEventQueue");
+EventQueue mainEventQueue("Main Event Queue");
#ifndef NDEBUG
Counter Event::instanceCounter = 0;
#endif
-inline Event *
-insertBefore(Event *event, Event *curr)
+Event::~Event()
+{
+ assert(!scheduled());
+ flags = 0;
+}
+
+const std::string
+Event::name() const
+{
+#ifndef NDEBUG
+ return csprintf("Event_%d", instance);
+#else
+ return csprintf("Event_%x", (uintptr_t)this);
+#endif
+}
+
+
+Event *
+Event::insertBefore(Event *event, Event *curr)
{
// Either way, event will be the top element in the 'in bin' list
// which is the pointer we need in order to look into the list, so
{
// Deal with the head case
if (!head || *event <= *head) {
- head = insertBefore(event, head);
+ head = Event::insertBefore(event, head);
return;
}
// Note: this operation may render all nextBin pointers on the
// prev 'in bin' list stale (except for the top one)
- prev->nextBin = insertBefore(event, curr);
+ prev->nextBin = Event::insertBefore(event, curr);
}
-inline Event *
-removeItem(Event *event, Event *top)
+Event *
+Event::removeItem(Event *event, Event *top)
{
Event *curr = top;
Event *next = top->nextInBin;
// deal with an event on the head's 'in bin' list (event has the same
// time as the head)
if (*head == *event) {
- head = removeItem(event, head);
+ head = Event::removeItem(event, head);
return;
}
// curr points to the top item of the the correct 'in bin' list, when
// we remove an item, it returns the new top item (which may be
// unchanged)
- prev->nextBin = removeItem(event, curr);
+ prev->nextBin = Event::removeItem(event, curr);
}
Event *
{
Event *event = head;
Event *next = head->nextInBin;
- event->clearFlags(Event::Scheduled);
+ event->flags.clear(Event::Scheduled);
if (next) {
// update the next bin pointer since it could be stale
// handle action
if (!event->squashed()) {
+ // forward current cycle to the time when this event occurs.
+ setCurTick(event->when());
+
event->process();
if (event->isExitEvent()) {
- assert(!event->getFlags(Event::AutoDelete)); // would be silly
+ assert(!event->flags.isSet(Event::AutoDelete) ||
+ !event->flags.isSet(Event::IsMainQueue)); // would be silly
return event;
}
} else {
- event->clearFlags(Event::Squashed);
+ event->flags.clear(Event::Squashed);
}
- if (event->getFlags(Event::AutoDelete) && !event->scheduled())
+ if (event->flags.isSet(Event::AutoDelete) && !event->scheduled())
delete event;
return NULL;
{
SERIALIZE_SCALAR(_when);
SERIALIZE_SCALAR(_priority);
- SERIALIZE_ENUM(_flags);
+ short _flags = flags;
+ SERIALIZE_SCALAR(_flags);
}
void
Event::unserialize(Checkpoint *cp, const string §ion)
{
if (scheduled())
- deschedule();
+ mainEventQueue.deschedule(this);
UNSERIALIZE_SCALAR(_when);
UNSERIALIZE_SCALAR(_priority);
+ short _flags;
+ UNSERIALIZE_SCALAR(_flags);
+
+ // Old checkpoints had no concept of the Initialized flag
+ // so restoring from old checkpoints always fail.
+ // Events are initialized on construction but original code
+ // "flags = _flags" would just overwrite the initialization.
+ // So, read in the checkpoint flags, but then set the Initialized
+ // flag on top of it in order to avoid failures.
+ assert(initialized());
+ flags = _flags;
+ flags.set(Initialized);
+
// need to see if original event was in a scheduled, unsquashed
// state, but don't want to restore those flags in the current
// object itself (since they aren't immediately true)
- UNSERIALIZE_ENUM(_flags);
- bool wasScheduled = (_flags & Scheduled) && !(_flags & Squashed);
- _flags &= ~(Squashed | Scheduled);
+ bool wasScheduled = flags.isSet(Scheduled) && !flags.isSet(Squashed);
+ flags.clear(Squashed | Scheduled);
if (wasScheduled) {
DPRINTF(Config, "rescheduling at %d\n", _when);
- schedule(_when);
+ mainEventQueue.schedule(this, _when);
}
}
Event *nextInBin = nextBin;
while (nextInBin) {
- if (nextInBin->getFlags(Event::AutoSerialize)) {
+ if (nextInBin->flags.isSet(Event::AutoSerialize)) {
eventPtrs.push_back(nextInBin);
paramOut(os, csprintf("event%d", numEvents++),
nextInBin->name());
EventQueue::dump() const
{
cprintf("============================================================\n");
- cprintf("EventQueue Dump (cycle %d)\n", curTick);
+ cprintf("EventQueue Dump (cycle %d)\n", curTick());
cprintf("------------------------------------------------------------\n");
if (empty())
return true;
}
+Event*
+EventQueue::replaceHead(Event* s)
+{
+ Event* t = head;
+ head = s;
+ return t;
+}
+
void
dumpMainQueue()
{
Event::dump() const
{
cprintf("Event %s (%s)\n", name(), description());
- cprintf("Flags: %#x\n", _flags);
+ cprintf("Flags: %#x\n", flags);
#ifdef EVENTQ_DEBUG
cprintf("Created: %d\n", whenCreated);
#endif
cprintf("Not Scheduled\n");
}
}
+
+EventQueue::EventQueue(const string &n)
+ : objName(n), head(NULL), _curTick(0)
+{}