Deleted Added
sdiff udiff text old ( 5501:b1beee9351a4 ) new ( 5502:f0f8a3ee5aad )
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

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

30 * Steve Raasch
31 */
32
33#include <cassert>
34#include <iostream>
35#include <string>
36#include <vector>
37
38#include "base/misc.hh"
39#include "base/trace.hh"
40#include "cpu/smt.hh"
41#include "sim/core.hh"
42#include "sim/eventq.hh"
43
44using namespace std;
45

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

50// cycle, before the pipeline simulation is performed.
51//
52EventQueue mainEventQueue("MainEventQueue");
53
54#ifndef NDEBUG
55Counter Event::instanceCounter = 0;
56#endif
57
58void
59EventQueue::insert(Event *event)
60{
61 if (head == NULL || event->when() < head->when() ||
62 (event->when() == head->when() &&
63 event->priority() <= head->priority())) {
64 event->next = head;
65 head = event;
66 } else {
67 Event *prev = head;
68 Event *curr = head->next;
69
70 while (curr) {
71 if (event->when() <= curr->when() &&
72 (event->when() < curr->when() ||
73 event->priority() <= curr->priority()))
74 break;
75
76 prev = curr;
77 curr = curr->next;
78 }
79
80 event->next = curr;
81 prev->next = event;
82 }
83}
84
85void
86EventQueue::remove(Event *event)
87{
88 if (head == NULL)
89 return;
90
91 if (head == event){
92 head = event->next;
93 return;
94 }
95
96 Event *prev = head;
97 Event *curr = head->next;
98 while (curr && curr != event) {
99 prev = curr;
100 curr = curr->next;
101 }
102
103 if (curr == event)
104 prev->next = curr->next;
105}
106
107Event *
108EventQueue::serviceOne()
109{
110 Event *event = head;
111 event->clearFlags(Event::Scheduled);
112 head = event->next;
113
114 // handle action
115 if (!event->squashed()) {
116 event->process();
117 if (event->isExitEvent()) {
118 assert(!event->getFlags(Event::AutoDelete)); // would be silly
119 return event;
120 }
121 } else {
122 event->clearFlags(Event::Squashed);
123 }
124
125 if (event->getFlags(Event::AutoDelete) && !event->scheduled())
126 delete event;
127
128 return NULL;
129}
130
131
132void
133Event::serialize(std::ostream &os)
134{
135 SERIALIZE_SCALAR(_when);
136 SERIALIZE_SCALAR(_priority);
137 SERIALIZE_ENUM(_flags);
138}
139
140
141void
142Event::unserialize(Checkpoint *cp, const string &section)
143{
144 if (scheduled())
145 deschedule();
146
147 UNSERIALIZE_SCALAR(_when);
148 UNSERIALIZE_SCALAR(_priority);

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

161}
162
163void
164EventQueue::serialize(ostream &os)
165{
166 std::list<Event *> eventPtrs;
167
168 int numEvents = 0;
169 Event *event = head;
170 while (event) {
171 if (event->getFlags(Event::AutoSerialize)) {
172 eventPtrs.push_back(event);
173 paramOut(os, csprintf("event%d", numEvents++), event->name());
174 }
175 event = event->next;
176 }
177
178 SERIALIZE_SCALAR(numEvents);
179
180 for (std::list<Event *>::iterator it=eventPtrs.begin();
181 it != eventPtrs.end(); ++it) {
182 (*it)->nameOut(os);
183 (*it)->serialize(os);
184 }
185}
186
187void
188EventQueue::unserialize(Checkpoint *cp, const std::string &section)

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

202
203void
204EventQueue::dump() const
205{
206 cprintf("============================================================\n");
207 cprintf("EventQueue Dump (cycle %d)\n", curTick);
208 cprintf("------------------------------------------------------------\n");
209
210 if (empty())
211 cprintf("<No Events>\n");
212 else {
213 Event *event = head;
214 while (event) {
215 event->dump();
216 event = event->next;
217 }
218 }
219
220 cprintf("============================================================\n");
221}
222
223void
224dumpMainQueue()
225{
226 mainEventQueue.dump();
227}
228
229
230const char *

--- 37 unchanged lines hidden ---