eventq.cc revision 2665:a124942bacb8
16019SN/A/* 26019SN/A * Copyright (c) 2000-2005 The Regents of The University of Michigan 36019SN/A * All rights reserved. 46019SN/A * 56019SN/A * Redistribution and use in source and binary forms, with or without 66019SN/A * modification, are permitted provided that the following conditions are 76019SN/A * met: redistributions of source code must retain the above copyright 86019SN/A * notice, this list of conditions and the following disclaimer; 96019SN/A * redistributions in binary form must reproduce the above copyright 106019SN/A * notice, this list of conditions and the following disclaimer in the 116019SN/A * documentation and/or other materials provided with the distribution; 126019SN/A * neither the name of the copyright holders nor the names of its 136019SN/A * contributors may be used to endorse or promote products derived from 146019SN/A * this software without specific prior written permission. 156019SN/A * 166019SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176019SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186019SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196019SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206019SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216019SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226019SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236019SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246019SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256019SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266019SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276019SN/A * 286019SN/A * Authors: Steve Reinhardt 296019SN/A * Nathan Binkert 306019SN/A * Steve Raasch 316329Sgblack@eecs.umich.edu */ 326329Sgblack@eecs.umich.edu 336019SN/A#include <assert.h> 346329Sgblack@eecs.umich.edu 356717Sgblack@eecs.umich.edu#include <iostream> 366329Sgblack@eecs.umich.edu#include <string> 376328SN/A#include <vector> 386329Sgblack@eecs.umich.edu 396328SN/A#include "cpu/smt.hh" 406329Sgblack@eecs.umich.edu#include "base/misc.hh" 416329Sgblack@eecs.umich.edu 426328SN/A#include "sim/eventq.hh" 437310Sgblack@eecs.umich.edu#include "base/trace.hh" 446328SN/A#include "sim/root.hh" 456329Sgblack@eecs.umich.edu 466328SN/Ausing namespace std; 476329Sgblack@eecs.umich.edu 486329Sgblack@eecs.umich.edu// 496329Sgblack@eecs.umich.edu// Main Event Queue 506328SN/A// 516329Sgblack@eecs.umich.edu// Events on this queue are processed at the *beginning* of each 526329Sgblack@eecs.umich.edu// cycle, before the pipeline simulation is performed. 536328SN/A// 546329Sgblack@eecs.umich.eduEventQueue mainEventQueue("MainEventQueue"); 556717Sgblack@eecs.umich.edu 567177Sgblack@eecs.umich.eduvoid 577177Sgblack@eecs.umich.eduEventQueue::insert(Event *event) 587592SAli.Saidi@ARM.com{ 596328SN/A if (head == NULL || event->when() < head->when() || 606717Sgblack@eecs.umich.edu (event->when() == head->when() && 616329Sgblack@eecs.umich.edu event->priority() <= head->priority())) { 626328SN/A event->next = head; 636329Sgblack@eecs.umich.edu head = event; 646328SN/A } else { 656328SN/A Event *prev = head; 666329Sgblack@eecs.umich.edu Event *curr = head->next; 676329Sgblack@eecs.umich.edu 686329Sgblack@eecs.umich.edu while (curr) { 696329Sgblack@eecs.umich.edu if (event->when() <= curr->when() && 706329Sgblack@eecs.umich.edu (event->when() < curr->when() || 716329Sgblack@eecs.umich.edu event->priority() <= curr->priority())) 726329Sgblack@eecs.umich.edu break; 736329Sgblack@eecs.umich.edu 746329Sgblack@eecs.umich.edu prev = curr; 756717Sgblack@eecs.umich.edu curr = curr->next; 766717Sgblack@eecs.umich.edu } 776717Sgblack@eecs.umich.edu 786328SN/A event->next = curr; 796717Sgblack@eecs.umich.edu prev->next = event; 806328SN/A } 816329Sgblack@eecs.umich.edu} 826329Sgblack@eecs.umich.edu 836329Sgblack@eecs.umich.eduvoid 846328SN/AEventQueue::remove(Event *event) 856329Sgblack@eecs.umich.edu{ 867498Sgblack@eecs.umich.edu if (head == NULL) 876329Sgblack@eecs.umich.edu return; 886329Sgblack@eecs.umich.edu 896329Sgblack@eecs.umich.edu if (head == event){ 906329Sgblack@eecs.umich.edu head = event->next; 916329Sgblack@eecs.umich.edu return; 926329Sgblack@eecs.umich.edu } 936329Sgblack@eecs.umich.edu 946329Sgblack@eecs.umich.edu Event *prev = head; 956329Sgblack@eecs.umich.edu Event *curr = head->next; 966329Sgblack@eecs.umich.edu while (curr && curr != event) { 976329Sgblack@eecs.umich.edu prev = curr; 986329Sgblack@eecs.umich.edu curr = curr->next; 996329Sgblack@eecs.umich.edu } 1006329Sgblack@eecs.umich.edu 1016329Sgblack@eecs.umich.edu if (curr == event) 1026329Sgblack@eecs.umich.edu prev->next = curr->next; 1036329Sgblack@eecs.umich.edu} 1046329Sgblack@eecs.umich.edu 1056329Sgblack@eecs.umich.eduvoid 1066329Sgblack@eecs.umich.eduEventQueue::serviceOne() 1076329Sgblack@eecs.umich.edu{ 1086329Sgblack@eecs.umich.edu Event *event = head; 1096329Sgblack@eecs.umich.edu event->clearFlags(Event::Scheduled); 1106329Sgblack@eecs.umich.edu head = event->next; 1116329Sgblack@eecs.umich.edu 1126329Sgblack@eecs.umich.edu // handle action 1136329Sgblack@eecs.umich.edu if (!event->squashed()) 1146329Sgblack@eecs.umich.edu event->process(); 1156329Sgblack@eecs.umich.edu else 1166329Sgblack@eecs.umich.edu event->clearFlags(Event::Squashed); 1176329Sgblack@eecs.umich.edu 1186328SN/A if (event->getFlags(Event::AutoDelete) && !event->scheduled()) 1196019SN/A delete event; 1206019SN/A} 121 122 123void 124Event::serialize(std::ostream &os) 125{ 126 SERIALIZE_SCALAR(_when); 127 SERIALIZE_SCALAR(_priority); 128 SERIALIZE_ENUM(_flags); 129} 130 131 132void 133Event::unserialize(Checkpoint *cp, const string §ion) 134{ 135 if (scheduled()) 136 deschedule(); 137 138 UNSERIALIZE_SCALAR(_when); 139 UNSERIALIZE_SCALAR(_priority); 140 141 // need to see if original event was in a scheduled, unsquashed 142 // state, but don't want to restore those flags in the current 143 // object itself (since they aren't immediately true) 144 UNSERIALIZE_ENUM(_flags); 145 bool wasScheduled = (_flags & Scheduled) && !(_flags & Squashed); 146 _flags &= ~(Squashed | Scheduled); 147 148 if (wasScheduled) { 149 DPRINTF(Config, "rescheduling at %d\n", _when); 150 schedule(_when); 151 } 152} 153 154void 155EventQueue::serialize(ostream &os) 156{ 157 std::list<Event *> eventPtrs; 158 159 int numEvents = 0; 160 Event *event = head; 161 while (event) { 162 if (event->getFlags(Event::AutoSerialize)) { 163 eventPtrs.push_back(event); 164 paramOut(os, csprintf("event%d", numEvents++), event->name()); 165 } 166 event = event->next; 167 } 168 169 SERIALIZE_SCALAR(numEvents); 170 171 for (std::list<Event *>::iterator it=eventPtrs.begin(); 172 it != eventPtrs.end(); ++it) { 173 (*it)->nameOut(os); 174 (*it)->serialize(os); 175 } 176} 177 178void 179EventQueue::unserialize(Checkpoint *cp, const std::string §ion) 180{ 181 int numEvents; 182 UNSERIALIZE_SCALAR(numEvents); 183 184 std::string eventName; 185 for (int i = 0; i < numEvents; i++) { 186 // get the pointer value associated with the event 187 paramIn(cp, section, csprintf("event%d", i), eventName); 188 189 // create the event based on its pointer value 190 Serializable::create(cp, eventName); 191 } 192} 193 194void 195EventQueue::dump() 196{ 197 cprintf("============================================================\n"); 198 cprintf("EventQueue Dump (cycle %d)\n", curTick); 199 cprintf("------------------------------------------------------------\n"); 200 201 if (empty()) 202 cprintf("<No Events>\n"); 203 else { 204 Event *event = head; 205 while (event) { 206 event->dump(); 207 event = event->next; 208 } 209 } 210 211 cprintf("============================================================\n"); 212} 213 214extern "C" 215void 216dumpMainQueue() 217{ 218 mainEventQueue.dump(); 219} 220 221 222const char * 223Event::description() 224{ 225 return "generic"; 226} 227 228#if TRACING_ON 229void 230Event::trace(const char *action) 231{ 232 // This DPRINTF is unconditional because calls to this function 233 // are protected by an 'if (DTRACE(Event))' in the inlined Event 234 // methods. 235 // 236 // This is just a default implementation for derived classes where 237 // it's not worth doing anything special. If you want to put a 238 // more informative message in the trace, override this method on 239 // the particular subclass where you have the information that 240 // needs to be printed. 241 DPRINTFN("%s event %s @ %d\n", description(), action, when()); 242} 243#endif 244 245void 246Event::dump() 247{ 248 cprintf("Event (%s)\n", description()); 249 cprintf("Flags: %#x\n", _flags); 250#if TRACING_ON 251 cprintf("Created: %d\n", when_created); 252#endif 253 if (scheduled()) { 254#if TRACING_ON 255 cprintf("Scheduled at %d\n", when_scheduled); 256#endif 257 cprintf("Scheduled for %d, priority %d\n", when(), _priority); 258 } 259 else { 260 cprintf("Not Scheduled\n"); 261 } 262} 263