Deleted Added
sdiff udiff text old ( 5336:c7e21f4e5a2e ) new ( 5501:b1beee9351a4 )
full compact
1/*
2 * Copyright (c) 2000-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 22 unchanged lines hidden (view full) ---

31
32/* @file
33 * EventQueue interfaces
34 */
35
36#ifndef __SIM_EVENTQ_HH__
37#define __SIM_EVENTQ_HH__
38
39#include <assert.h>
40
41#include <algorithm>
42#include <map>
43#include <string>
44#include <vector>
45
46#include "sim/host.hh" // for Tick
47
48#include "base/fast_alloc.hh"
49#include "base/misc.hh"
50#include "base/trace.hh"
51#include "sim/serialize.hh"
52
53class EventQueue; // forward declaration
54
55//////////////////////
56//
57// Main Event Queue
58//
59// Events on this queue are processed at the *beginning* of each
60// cycle, before the pipeline simulation is performed.
61//
62// defined in eventq.cc
63//
64//////////////////////
65extern EventQueue mainEventQueue;
66
67
68/*
69 * An item on an event queue. The action caused by a given
70 * event is specified by deriving a subclass and overriding the
71 * process() member function.
72 */
73class Event : public Serializable, public FastAlloc
74{
75 friend class EventQueue;
76
77 private:
78
79#ifndef NDEBUG
80 /// Global counter to generate unique IDs for Event instances
81 static Counter instanceCounter;
82
83 /// This event's unique ID. We can also use pointer values for
84 /// this but they're not consistent across runs making debugging
85 /// more difficult. Thus we use a global counter value when
86 /// debugging.
87 Counter instanceId;
88#endif // NDEBUG
89
90 /// queue to which this event belongs (though it may or may not be
91 /// scheduled on this queue yet)
92 EventQueue *queue;
93
94 Event *next;
95
96 Tick _when; //!< timestamp when event should be processed
97 int _priority; //!< event priority
98 char _flags;
99
100 protected:
101 enum Flags {
102 None = 0x0,
103 Squashed = 0x1,
104 Scheduled = 0x2,
105 AutoDelete = 0x4,
106 AutoSerialize = 0x8,
107 IsExitEvent = 0x10
108 };
109
110 bool getFlags(Flags f) const { return (_flags & f) == f; }
111 void setFlags(Flags f) { _flags |= f; }
112 void clearFlags(Flags f) { _flags &= ~f; }
113
114 protected:
115 EventQueue *theQueue() const { return queue; }
116
117#if TRACING_ON
118 Tick when_created; //!< Keep track of creation time For debugging
119 Tick when_scheduled; //!< Keep track of creation time For debugging
120
121 virtual void trace(const char *action); //!< trace event activity
122#else
123 void trace(const char *) {}
124#endif
125
126 unsigned annotated_value;
127
128 public:
129
130 /// Event priorities, to provide tie-breakers for events scheduled
131 /// at the same cycle. Most events are scheduled at the default
132 /// priority; these values are used to control events that need to
133 /// be ordered within a cycle.
134 enum Priority {
135 /// If we enable tracing on a particular cycle, do that as the
136 /// very first thing so we don't miss any of the events on
137 /// that cycle (even if we enter the debugger).
138 Trace_Enable_Pri = -101,
139
140 /// Breakpoints should happen before anything else (except
141 /// enabling trace output), so we don't miss any action when
142 /// debugging.

--- 26 unchanged lines hidden (view full) ---

169 /// everything else, but before exit.
170 Stat_Event_Pri = 90,
171
172 /// Progress events come at the end.
173 Progress_Event_Pri = 95,
174
175 /// If we want to exit on this cycle, it's the very last thing
176 /// we do.
177 Sim_Exit_Pri = 100
178 };
179
180 /*
181 * Event constructor
182 * @param queue that the event gets scheduled on
183 */
184 Event(EventQueue *q, Priority p = Default_Pri)
185 : queue(q), next(NULL), _priority(p), _flags(None),
186#if TRACING_ON
187 when_created(curTick), when_scheduled(0),
188#endif
189 annotated_value(0)
190 {
191#ifndef NDEBUG
192 instanceId = ++instanceCounter;
193#endif
194 }
195
196 ~Event() {}
197
198 virtual const std::string name() const {
199#ifndef NDEBUG
200 return csprintf("Event_%d", instanceId);
201#else
202 return csprintf("Event_%x", (uintptr_t)this);
203#endif
204 }
205
206 /// Determine if the current event is scheduled
207 bool scheduled() const { return getFlags(Scheduled); }
208
209 /// Schedule the event with the current priority or default priority
210 void schedule(Tick t);
211
212 /// Reschedule the event with the current priority
213 // always parameter means to schedule if not already scheduled
214 void reschedule(Tick t, bool always = false);
215
216 /// Remove the event from the current schedule
217 void deschedule();
218
219 /// Return a C string describing the event. This string should
220 /// *not* be dynamically allocated; just a const char array
221 /// describing the event class.
222 virtual const char *description() const;
223
224 /// Dump the current event data
225 void dump();
226
227 /*
228 * This member function is invoked when the event is processed
229 * (occurs). There is no default implementation; each subclass
230 * must provide its own implementation. The event is not
231 * automatically deleted after it is processed (to allow for
232 * statically allocated event objects).
233 *
234 * If the AutoDestroy flag is set, the object is deleted once it
235 * is processed.
236 */
237 virtual void process() = 0;
238
239 void annotate(unsigned value) { annotated_value = value; };
240 unsigned annotation() { return annotated_value; }
241
242 /// Squash the current event
243 void squash() { setFlags(Squashed); }
244
245 /// Check whether the event is squashed
246 bool squashed() { return getFlags(Squashed); }
247
248 /// See if this is a SimExitEvent (without resorting to RTTI)
249 bool isExitEvent() { return getFlags(IsExitEvent); }
250
251 /// Get the time that the event is scheduled
252 Tick when() const { return _when; }
253
254 /// Get the event priority
255 int priority() const { return _priority; }
256
257 struct priority_compare :
258 public std::binary_function
259 {
260 bool operator()(const Event *l, const Event *r) const {
261 return l->when() >= r->when() || l->priority() >= r->priority();
262 }
263 };
264
265 virtual void serialize(std::ostream &os);
266 virtual void unserialize(Checkpoint *cp, const std::string &section);
267};
268

--- 69 unchanged lines hidden (view full) ---

338
339 virtual const std::string name() const { return objName; }
340
341 // schedule the given event on this queue
342 void schedule(Event *ev);
343 void deschedule(Event *ev);
344 void reschedule(Event *ev);
345
346 Tick nextTick() { return head->when(); }
347 Event *serviceOne();
348
349 // process all events up to the given timestamp. we inline a
350 // quick test to see if there are any events to process; if so,
351 // call the internal out-of-line version to process them all.
352 void serviceEvents(Tick when) {
353 while (!empty()) {
354 if (nextTick() > when)
355 break;
356
357 /**
358 * @todo this assert is a good bug catcher. I need to
359 * make it true again.
360 */
361 //assert(head->when() >= when && "event scheduled in the past");
362 serviceOne();
363 }
364 }
365
366 // default: process all events up to 'now' (curTick)
367 void serviceEvents() { serviceEvents(curTick); }
368
369 // return true if no events are queued
370 bool empty() { return head == NULL; }
371
372 void dump();
373
374 Tick nextEventTime() { return empty() ? curTick : head->when(); }
375
376 virtual void serialize(std::ostream &os);
377 virtual void unserialize(Checkpoint *cp, const std::string &section);
378};
379
380

--- 7 unchanged lines hidden (view full) ---

388//////////////////////
389
390// schedule at specified time (place on event queue specified via
391// constructor)
392inline void
393Event::schedule(Tick t)
394{
395 assert(!scheduled());
396// if (t < curTick)
397// warn("t is less than curTick, ensure you don't want cycles");
398
399 setFlags(Scheduled);
400#if TRACING_ON
401 when_scheduled = curTick;
402#endif
403 _when = t;
404 queue->schedule(this);
405}
406
407inline void
408Event::deschedule()
409{
410 assert(scheduled());
411
412 clearFlags(Squashed);
413 clearFlags(Scheduled);
414 queue->deschedule(this);
415}
416
417inline void
418Event::reschedule(Tick t, bool always)
419{
420 assert(scheduled() || always);
421
422#if TRACING_ON
423 when_scheduled = curTick;
424#endif
425 _when = t;
426
427 if (scheduled()) {
428 clearFlags(Squashed);
429 queue->reschedule(this);
430 } else {
431 setFlags(Scheduled);
432 queue->schedule(this);
433 }
434}
435
436inline void
437EventQueue::schedule(Event *event)
438{
439 insert(event);
440 if (DTRACE(Event))
441 event->trace("scheduled");
442}
443
444inline void
445EventQueue::deschedule(Event *event)
446{
447 remove(event);
448 if (DTRACE(Event))
449 event->trace("descheduled");
450}
451
452inline void
453EventQueue::reschedule(Event *event)
454{
455 remove(event);
456 insert(event);
457 if (DTRACE(Event))
458 event->trace("rescheduled");
459}
460
461
462
463#endif // __SIM_EVENTQ_HH__