eventq.cc revision 221
12SN/A/* 21762SN/A * Copyright (c) 2003 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A */ 282665SN/A 292SN/A#include <assert.h> 302SN/A 314826Ssaidi@eecs.umich.edu#include <iostream> 324826Ssaidi@eecs.umich.edu#include <string> 332SN/A#include <sstream> 346216Snate@binkert.org#include <vector> 352SN/A 364826Ssaidi@eecs.umich.edu#include "cpu/full_cpu/smt.hh" 3774SN/A#include "base/misc.hh" 386216Snate@binkert.org 394084SN/A#include "sim/eventq.hh" 402SN/A#include "base/trace.hh" 412680SN/A#include "sim/universe.hh" 422SN/A 433535SN/Ausing namespace std; 442SN/A 452SN/Aconst string Event::defaultName("event"); 462680SN/A 472SN/A// 487693SAli.Saidi@ARM.com// Main Event Queue 492SN/A// 502SN/A// Events on this queue are processed at the *beginning* of each 512SN/A// cycle, before the pipeline simulation is performed. 522SN/A// 532SN/AEventQueue mainEventQueue("MainEventQueue"); 542SN/A 552SN/Avoid 562SN/AEventQueue::insert(Event *event) 572SN/A{ 582SN/A if (head == NULL || event->when() < head->when() || 592SN/A (event->when() == head->when() && 602SN/A event->priority() <= head->priority())) { 612SN/A event->next = head; 622SN/A head = event; 632SN/A } else { 642SN/A Event *prev = head; 652SN/A Event *curr = head->next; 662SN/A 673535SN/A while (curr) { 682680SN/A if (event->when() <= curr->when() && 692SN/A (event->when() < curr->when() || 703535SN/A event->priority() <= curr->priority())) 712680SN/A break; 723535SN/A 732SN/A prev = curr; 742680SN/A curr = curr->next; 752SN/A } 763535SN/A 772680SN/A event->next = curr; 782SN/A prev->next = event; 792SN/A } 802SN/A} 812SN/A 822SN/Avoid 834826Ssaidi@eecs.umich.eduEventQueue::remove(Event *event) 844826Ssaidi@eecs.umich.edu{ 857693SAli.Saidi@ARM.com if (head == NULL) 864826Ssaidi@eecs.umich.edu return; 874826Ssaidi@eecs.umich.edu 883535SN/A if (head == event){ 892SN/A head = event->next; 902SN/A return; 912SN/A } 922SN/A 932SN/A Event *prev = head; 943535SN/A Event *curr = head->next; 953535SN/A while (curr && curr != event) { 962SN/A prev = curr; 972SN/A curr = curr->next; 982SN/A } 992SN/A 1002SN/A if (curr == event) 1013535SN/A prev->next = curr->next; 1022SN/A} 1032SN/A 1042SN/Avoid 1052SN/AEventQueue::serviceOne() 1062SN/A{ 1073535SN/A Event *event = head; 1083535SN/A event->clearFlags(Event::Scheduled); 1092SN/A head = event->next; 1102SN/A 1112SN/A // handle action 1122SN/A if (!event->squashed()) 1132SN/A event->process(); 1143535SN/A else 1152SN/A event->clearFlags(Event::Squashed); 1162SN/A 1172SN/A if (event->getFlags(Event::AutoDelete)) 1182SN/A delete event; 1192SN/A} 1203535SN/A 1212SN/Avoid 1222SN/AEventQueue::nameChildren() 1232SN/A{ 1242SN/A#if 0 1252SN/A int j = 0; 1263535SN/A 1273535SN/A Event *event = head; 1282SN/A while (event) { 1292SN/A stringstream stream; 1302SN/A ccprintf(stream, "%s.event%d", name(), j++); 1312SN/A event->setName(stream.str()); 1322SN/A 1337693SAli.Saidi@ARM.com event = event->next; 1342SN/A } 1352SN/A#endif 1362SN/A} 1372SN/A 1382SN/Avoid 1392SN/AEventQueue::serialize(ostream &os) 1407693SAli.Saidi@ARM.com{ 1412SN/A#if 0 1422SN/A string objects = ""; 1432SN/A 1442SN/A Event *event = head; 1452SN/A while (event) { 1467693SAli.Saidi@ARM.com objects += event->name(); 1472SN/A objects += " "; 1482SN/A event->serialize(os); 1492SN/A 1502SN/A event = event->next; 1514826Ssaidi@eecs.umich.edu } 152 nameOut(os, "Serialized"); 153 SERIALIZE_MEMBER(objects); 154#endif 155} 156 157void 158EventQueue::dump() 159{ 160 cprintf("============================================================\n"); 161 cprintf("EventQueue Dump (cycle %d)\n", curTick); 162 cprintf("------------------------------------------------------------\n"); 163 164 if (empty()) 165 cprintf("<No Events>\n"); 166 else { 167 Event *event = head; 168 while (event) { 169 event->dump(); 170 event = event->next; 171 } 172 } 173 174 cprintf("============================================================\n"); 175} 176 177 178const char * 179Event::description() 180{ 181 return "generic"; 182} 183 184#if TRACING_ON 185void 186Event::trace(const char *action) 187{ 188 // This DPRINTF is unconditional because calls to this function 189 // are protected by an 'if (DTRACE(Event))' in the inlined Event 190 // methods. 191 // 192 // This is just a default implementation for derived classes where 193 // it's not worth doing anything special. If you want to put a 194 // more informative message in the trace, override this method on 195 // the particular subclass where you have the information that 196 // needs to be printed. 197 DPRINTFN("%s event %s @ %d\n", description(), action, when()); 198} 199#endif 200 201void 202Event::dump() 203{ 204#if TRACING_ON 205 cprintf(" Created: %d\n", when_created); 206#endif 207 if (scheduled()) { 208#if TRACING_ON 209 cprintf(" Scheduled at %d\n", when_scheduled); 210#endif 211 cprintf(" Scheduled for %d\n", when()); 212 } 213 else { 214 cprintf(" Not Scheduled\n"); 215 } 216} 217