38 #include <unordered_map>
44 #include "debug/Checkpoint.hh"
89 return csprintf(
"Event_%d", instance);
91 return csprintf(
"Event_%x", (uintptr_t)
this);
102 if (!curr || *event < *curr) {
121 if (!head || *event <= *head) {
130 while (curr && *curr < *event) {
158 while (event != next) {
160 panic(
"event not found!");
175 panic(
"event not found!");
177 assert(event->
queue ==
this);
181 if (*head == *event) {
189 while (curr && *curr < *event) {
194 if (!curr || *curr != *event)
195 panic(
"event not found!");
206 std::lock_guard<EventQueue>
lock(*
this);
224 if (!
event->squashed()) {
226 setCurTick(
event->when());
229 if (
event->isExitEvent()) {
248 short _flags = flags;
255 assert(!scheduled());
269 assert(initialized());
271 flags.set(Initialized);
276 if (flags.isSet(Scheduled) && !flags.isSet(Squashed)) {
277 flags.clear(Squashed | Scheduled);
279 DPRINTF(Checkpoint,
"Event '%s' need to be scheduled @%d\n",
296 cprintf(
"============================================================\n");
298 cprintf(
"------------------------------------------------------------\n");
303 Event *nextBin = head;
305 Event *nextInBin = nextBin;
315 cprintf(
"============================================================\n");
321 std::unordered_map<long, bool> map;
326 Event *nextBin = head;
328 Event *nextInBin = nextBin;
330 if (nextInBin->
when() < time) {
331 cprintf(
"time goes backwards!");
334 }
else if (nextInBin->
when() == time &&
341 if (map[reinterpret_cast<long>(nextInBin)]) {
346 map[
reinterpret_cast<long>(nextInBin)] =
true;
348 time = nextInBin->
when();
395 DPRINTFN(
"%s event %s @ %d\n", description(), action, when());
402 cprintf(
"Flags: %#x\n", flags);
404 cprintf(
"Created: %d\n", whenCreated);
408 cprintf(
"Scheduled at %d\n", whenScheduled);
410 cprintf(
"Scheduled for %d, priority %d\n", when(), _priority);
417 : objName(n), head(NULL), _curTick(0)
void serialize(CheckpointOut &cp) const override
Serialize an object.
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
const std::string & name()
virtual const std::string name() const
static const FlagsType Managed
void asyncInsert(Event *event)
Function for adding events to the async queue.
static Event * insertBefore(Event *event, Event *curr)
vector< EventQueue * > mainEventQueue
Array for main event queues.
void insert(Event *event)
Insert / remove event from the queue.
bool inParallelMode
Current mode of execution: parallel / serial.
Priority priority() const
Get the event priority.
EventQueue(const EventQueue &)
static const FlagsType Squashed
#define UNSERIALIZE_SCALAR(scalar)
void remove(Event *event)
Tick curTick()
The current simulated tick.
std::string csprintf(const char *format, const Args &...args)
Queue of events sorted in time order.
static const FlagsType Scheduled
Tick when() const
Get the time that the event is scheduled.
uint64_t Tick
Tick count type.
EventQueue * curEventQueue()
int64_t Counter
Statistics counter type.
std::mutex async_queue_mutex
Mutex to protect async queue.
void checkpointReschedule(Event *event)
Reschedule an event after a checkpoint.
#define SERIALIZE_SCALAR(scalar)
Event * replaceHead(Event *s)
function for replacing the head of the event queue, so that a different set of events can run without...
void handleAsyncInsertions()
Function for moving events from the async_queue to the main queue.
std::ostream CheckpointOut
uint32_t numMainEventQueues
Current number of allocated main event queues.
static Event * removeItem(Event *event, Event *last)
virtual void trace(const char *action)
trace event activity
__thread EventQueue * _curEventQueue
The current event queue for the running thread.
void dump() const
Dump the current event data.
virtual const char * description() const
Return a C string describing the event.
std::list< Event * > async_queue
List of events added by other threads to this event queue.
static Counter instanceCounter
Global counter to generate unique IDs for Event instances.
EventQueue * queue
queue to which this event belongs (though it may or may not be scheduled on this queue yet) ...
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
void cprintf(const char *format, const Args &...args)
static const FlagsType IsMainQueue