#include "base/misc.hh"
#include "base/trace.hh"
#include "cpu/smt.hh"
+#include "debug/Config.hh"
#include "sim/core.hh"
#include "sim/eventq.hh"
// 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
+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)
{
{
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
if (!event->squashed()) {
event->process();
if (event->isExitEvent()) {
- assert(!event->getFlags(Event::AutoDelete)); // would be silly
+ assert(!event->flags.isSet(Event::AutoDelete)); // 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())
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)
+{}