2 * Copyright (c) 2000-2005 The Regents of The University of Michigan
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
40 #include "base/misc.hh"
42 #include "sim/eventq.hh"
43 #include "base/trace.hh"
44 #include "sim/core.hh"
51 // Events on this queue are processed at the *beginning* of each
52 // cycle, before the pipeline simulation is performed.
54 EventQueue
mainEventQueue("MainEventQueue");
57 Counter
Event::instanceCounter
= 0;
61 EventQueue::insert(Event
*event
)
63 if (head
== NULL
|| event
->when() < head
->when() ||
64 (event
->when() == head
->when() &&
65 event
->priority() <= head
->priority())) {
70 Event
*curr
= head
->next
;
73 if (event
->when() <= curr
->when() &&
74 (event
->when() < curr
->when() ||
75 event
->priority() <= curr
->priority()))
88 EventQueue::remove(Event
*event
)
99 Event
*curr
= head
->next
;
100 while (curr
&& curr
!= event
) {
106 prev
->next
= curr
->next
;
110 EventQueue::serviceOne()
113 event
->clearFlags(Event::Scheduled
);
117 if (!event
->squashed()) {
119 if (event
->isExitEvent()) {
120 assert(!event
->getFlags(Event::AutoDelete
)); // would be silly
124 event
->clearFlags(Event::Squashed
);
127 if (event
->getFlags(Event::AutoDelete
) && !event
->scheduled())
135 Event::serialize(std::ostream
&os
)
137 SERIALIZE_SCALAR(_when
);
138 SERIALIZE_SCALAR(_priority
);
139 SERIALIZE_ENUM(_flags
);
144 Event::unserialize(Checkpoint
*cp
, const string
§ion
)
149 UNSERIALIZE_SCALAR(_when
);
150 UNSERIALIZE_SCALAR(_priority
);
152 // need to see if original event was in a scheduled, unsquashed
153 // state, but don't want to restore those flags in the current
154 // object itself (since they aren't immediately true)
155 UNSERIALIZE_ENUM(_flags
);
156 bool wasScheduled
= (_flags
& Scheduled
) && !(_flags
& Squashed
);
157 _flags
&= ~(Squashed
| Scheduled
);
160 DPRINTF(Config
, "rescheduling at %d\n", _when
);
166 EventQueue::serialize(ostream
&os
)
168 std::list
<Event
*> eventPtrs
;
173 if (event
->getFlags(Event::AutoSerialize
)) {
174 eventPtrs
.push_back(event
);
175 paramOut(os
, csprintf("event%d", numEvents
++), event
->name());
180 SERIALIZE_SCALAR(numEvents
);
182 for (std::list
<Event
*>::iterator it
=eventPtrs
.begin();
183 it
!= eventPtrs
.end(); ++it
) {
185 (*it
)->serialize(os
);
190 EventQueue::unserialize(Checkpoint
*cp
, const std::string
§ion
)
193 UNSERIALIZE_SCALAR(numEvents
);
195 std::string eventName
;
196 for (int i
= 0; i
< numEvents
; i
++) {
197 // get the pointer value associated with the event
198 paramIn(cp
, section
, csprintf("event%d", i
), eventName
);
200 // create the event based on its pointer value
201 Serializable::create(cp
, eventName
);
208 cprintf("============================================================\n");
209 cprintf("EventQueue Dump (cycle %d)\n", curTick
);
210 cprintf("------------------------------------------------------------\n");
213 cprintf("<No Events>\n");
222 cprintf("============================================================\n");
228 mainEventQueue
.dump();
240 Event::trace(const char *action
)
242 // This DPRINTF is unconditional because calls to this function
243 // are protected by an 'if (DTRACE(Event))' in the inlined Event
246 // This is just a default implementation for derived classes where
247 // it's not worth doing anything special. If you want to put a
248 // more informative message in the trace, override this method on
249 // the particular subclass where you have the information that
250 // needs to be printed.
251 DPRINTFN("%s event %s @ %d\n", description(), action
, when());
258 cprintf("Event (%s)\n", description());
259 cprintf("Flags: %#x\n", _flags
);
261 cprintf("Created: %d\n", when_created
);
265 cprintf("Scheduled at %d\n", when_scheduled
);
267 cprintf("Scheduled for %d, priority %d\n", when(), _priority
);
270 cprintf("Not Scheduled\n");