/*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2000-2004 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* EventQueue interfaces
*/
-#ifndef __EVENTQ_HH__
-#define __EVENTQ_HH__
+#ifndef __SIM_EVENTQ_HH__
+#define __SIM_EVENTQ_HH__
#include <assert.h>
#include "sim/host.hh" // for Tick
#include "base/fast_alloc.hh"
-#include "sim/serialize.hh"
#include "base/trace.hh"
+#include "sim/serialize.hh"
class EventQueue; // forward declaration
+//////////////////////
+//
+// Main Event Queue
+//
+// Events on this queue are processed at the *beginning* of each
+// cycle, before the pipeline simulation is performed.
+//
+// defined in eventq.cc
+//
+//////////////////////
+extern EventQueue mainEventQueue;
+
+
/*
* An item on an event queue. The action caused by a given
* event is specified by deriving a subclass and overriding the
* process() member function.
*/
-class Event : public Serializeable, public FastAlloc
+class Event : public Serializable, public FastAlloc
{
friend class EventQueue;
None = 0x0,
Squashed = 0x1,
Scheduled = 0x2,
- AutoDelete = 0x4
+ AutoDelete = 0x4,
+ AutoSerialize = 0x8
};
bool getFlags(Flags f) const { return (_flags & f) == f; }
public:
- static const std::string defaultName;
-
- /*
- * Event constructor
- * @param queue that the event gets scheduled on
- */
- Event(EventQueue *q, int p = 0)
- : Serializeable(defaultName), queue(q), next(NULL),
- _priority(p), _flags(None),
-#if TRACING_ON
- when_created(curTick), when_scheduled(0),
-#endif
- annotated_value(0)
- {
- }
+ /// Event priorities, to provide tie-breakers for events scheduled
+ /// at the same cycle. Most events are scheduled at the default
+ /// priority; these values are used to control events that need to
+ /// be ordered within a cycle.
+ enum Priority {
+ /// Breakpoints should happen before anything else, so we
+ /// don't miss any action when debugging.
+ Debug_Break_Pri = -100,
+
+ /// For some reason "delayed" inter-cluster writebacks are
+ /// scheduled before regular writebacks (which have default
+ /// priority). Steve?
+ Delayed_Writeback_Pri = -1,
+
+ /// Default is zero for historical reasons.
+ Default_Pri = 0,
+
+ /// CPU switches schedule the new CPU's tick event for the
+ /// same cycle (after unscheduling the old CPU's tick event).
+ /// The switch needs to come before any tick events to make
+ /// sure we don't tick both CPUs in the same cycle.
+ CPU_Switch_Pri = 31,
+
+ /// Serailization needs to occur before tick events also, so
+ /// that a serialize/unserialize is identical to an on-line
+ /// CPU switch.
+ Serialize_Pri = 32,
+
+ /// CPU ticks must come after other associated CPU events
+ /// (such as writebacks).
+ CPU_Tick_Pri = 50,
+
+ /// Statistics events (dump, reset, etc.) come after
+ /// everything else, but before exit.
+ Stat_Event_Pri = 90,
+
+ /// If we want to exit on this cycle, it's the very last thing
+ /// we do.
+ Sim_Exit_Pri = 100
+ };
/*
* Event constructor
* @param queue that the event gets scheduled on
*/
- Event(EventQueue *q, std::string _name, int p = 0)
- : Serializeable(_name), queue(q), next(NULL),
- _priority(p), _flags(None),
+ Event(EventQueue *q, Priority p = Default_Pri)
+ : queue(q), next(NULL), _priority(p), _flags(None),
#if TRACING_ON
when_created(curTick), when_scheduled(0),
#endif
~Event() {}
+ virtual const std::string name() const {
+ return csprintf("Event_%x", (uintptr_t)this);
+ }
+
/// Determine if the current event is scheduled
bool scheduled() const { return getFlags(Scheduled); }
/// Schedule the event with the current priority or default priority
void schedule(Tick t);
- /// Schedule the event with a specific priority
- void schedule(Tick t, int priority);
-
/// Reschedule the event with the current priority
void reschedule(Tick t);
- /// Reschedule the event with a specific priority
- void reschedule(Tick t, int priority);
-
/// Remove the event from the current schedule
void deschedule();
};
virtual void serialize(std::ostream &os);
- virtual void unserialize(const IniFile *db, const std::string §ion);
+ virtual void unserialize(Checkpoint *cp, const std::string §ion);
};
template <class T, void (T::* F)()>
public:
DelayEvent(Tick when, T *o)
: Event(&mainEventQueue), object(o)
- { setFlags(AutoDestroy); schedule(when); }
+ { setFlags(this->AutoDestroy); schedule(when); }
void process() { (object->*F)(); }
const char *description() { return "delay"; }
};
new DelayEvent(when, object);
}
+template <class T, void (T::* F)()>
+class EventWrapper : public Event
+{
+ private:
+ T *object;
+
+ public:
+ EventWrapper(T *obj, bool del = false, EventQueue *q = &mainEventQueue,
+ Priority p = Default_Pri)
+ : Event(q, p), object(obj)
+ {
+ if (del)
+ setFlags(AutoDelete);
+ }
+ void process() { (object->*F)(); }
+};
+
/*
* Queue of events sorted in time order
*/
-class EventQueue : public Serializeable
+class EventQueue : public Serializable
{
+ protected:
+ std::string objName;
+
private:
Event *head;
// constructor
EventQueue(const std::string &n)
- : Serializeable(n), head(NULL)
+ : objName(n), head(NULL)
{}
+ virtual const std::string name() const { return objName; }
+
// schedule the given event on this queue
void schedule(Event *ev);
void deschedule(Event *ev);
Tick nextEventTime() { return empty() ? curTick : head->when(); }
- virtual void nameChildren();
virtual void serialize(std::ostream &os);
+ virtual void unserialize(Checkpoint *cp, const std::string §ion);
};
Event::schedule(Tick t)
{
assert(!scheduled());
+ assert(t >= curTick);
+
setFlags(Scheduled);
#if TRACING_ON
when_scheduled = curTick;
queue->schedule(this);
}
-inline void
-Event::schedule(Tick t, int p)
-{
- _priority = p;
- schedule(t);
-}
-
inline void
Event::deschedule()
{
queue->reschedule(this);
}
-inline void
-Event::reschedule(Tick t, int p)
-{
- _priority = p;
- reschedule(t);
-}
-
inline void
EventQueue::schedule(Event *event)
{
}
-//////////////////////
-//
-// Main Event Queue
-//
-// Events on this queue are processed at the *beginning* of each
-// cycle, before the pipeline simulation is performed.
-//
-// defined in eventq.cc
-//
-//////////////////////
-extern EventQueue mainEventQueue;
-#endif // __EVENTQ_HH__
+#endif // __SIM_EVENTQ_HH__