sim_object.cc revision 2665
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 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. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302SN/A */ 312SN/A 322SN/A#include <assert.h> 332SN/A 34330SN/A#include "base/callback.hh" 3556SN/A#include "base/inifile.hh" 361031SN/A#include "base/match.hh" 37330SN/A#include "base/misc.hh" 38330SN/A#include "base/trace.hh" 39938SN/A#include "base/stats/events.hh" 402609SN/A#include "base/serializer.hh" 4156SN/A#include "sim/configfile.hh" 4256SN/A#include "sim/host.hh" 43330SN/A#include "sim/sim_object.hh" 44695SN/A#include "sim/stats.hh" 45843SN/A#include "sim/param.hh" 462SN/A 472SN/Ausing namespace std; 482SN/A 492SN/A 502SN/A//////////////////////////////////////////////////////////////////////// 512SN/A// 522SN/A// SimObject member definitions 532SN/A// 542SN/A//////////////////////////////////////////////////////////////////////// 552SN/A 562SN/A// 572SN/A// static list of all SimObjects, used for initialization etc. 582SN/A// 592SN/ASimObject::SimObjectList SimObject::simObjectList; 602SN/A 611031SN/Anamespace Stats { 621031SN/A extern ObjectMatch event_ignore; 631031SN/A} 641031SN/A 652SN/A// 662SN/A// SimObject constructor: used to maintain static simObjectList 672SN/A// 681553SN/ASimObject::SimObject(Params *p) 691553SN/A : _params(p) 702SN/A{ 711031SN/A#ifdef DEBUG 721031SN/A doDebugBreak = false; 731031SN/A#endif 741031SN/A 751553SN/A doRecordEvent = !Stats::event_ignore.match(name()); 761553SN/A simObjectList.push_back(this); 771553SN/A} 781553SN/A 791553SN/A// 801553SN/A// SimObject constructor: used to maintain static simObjectList 811553SN/A// 821553SN/ASimObject::SimObject(const string &_name) 831553SN/A : _params(new Params) 841553SN/A{ 851553SN/A _params->name = _name; 861553SN/A#ifdef DEBUG 871553SN/A doDebugBreak = false; 881553SN/A#endif 891553SN/A 901553SN/A doRecordEvent = !Stats::event_ignore.match(name()); 912SN/A simObjectList.push_back(this); 922SN/A} 932SN/A 94465SN/Avoid 952499SN/ASimObject::connect() 962499SN/A{ 972499SN/A} 982499SN/A 992499SN/Avoid 100465SN/ASimObject::init() 101465SN/A{ 102465SN/A} 103465SN/A 1042SN/A// 1052SN/A// no default statistics, so nothing to do in base implementation 1062SN/A// 1072SN/Avoid 1082SN/ASimObject::regStats() 1092SN/A{ 1102SN/A} 1112SN/A 1122SN/Avoid 1132SN/ASimObject::regFormulas() 1142SN/A{ 1152SN/A} 1162SN/A 117330SN/Avoid 118330SN/ASimObject::resetStats() 119330SN/A{ 120330SN/A} 121330SN/A 1222SN/A// 12353SN/A// static function: 12453SN/A// call regStats() on all SimObjects and then regFormulas() on all 12553SN/A// SimObjects. 1262SN/A// 127334SN/Astruct SimObjectResetCB : public Callback 128334SN/A{ 129334SN/A virtual void process() { SimObject::resetAllStats(); } 130334SN/A}; 131334SN/A 132334SN/Anamespace { 133334SN/A static SimObjectResetCB StatResetCB; 134334SN/A} 135334SN/A 1362SN/Avoid 1372SN/ASimObject::regAllStats() 1382SN/A{ 1392SN/A SimObjectList::iterator i; 1402SN/A SimObjectList::iterator end = simObjectList.end(); 1412SN/A 1422SN/A /** 1432SN/A * @todo change cprintfs to DPRINTFs 1442SN/A */ 1452SN/A for (i = simObjectList.begin(); i != end; ++i) { 1462SN/A#ifdef STAT_DEBUG 1472SN/A cprintf("registering stats for %s\n", (*i)->name()); 1482SN/A#endif 1492SN/A (*i)->regStats(); 1502SN/A } 1512SN/A 1522SN/A for (i = simObjectList.begin(); i != end; ++i) { 1532SN/A#ifdef STAT_DEBUG 1542SN/A cprintf("registering formulas for %s\n", (*i)->name()); 1552SN/A#endif 1562SN/A (*i)->regFormulas(); 157334SN/A } 158334SN/A 159729SN/A Stats::registerResetCallback(&StatResetCB); 1602SN/A} 1612SN/A 1622SN/A// 1632499SN/A// static function: call connect() on all SimObjects. 1642499SN/A// 1652499SN/Avoid 1662499SN/ASimObject::connectAll() 1672499SN/A{ 1682499SN/A SimObjectList::iterator i = simObjectList.begin(); 1692499SN/A SimObjectList::iterator end = simObjectList.end(); 1702499SN/A 1712499SN/A for (; i != end; ++i) { 1722499SN/A SimObject *obj = *i; 1732499SN/A obj->connect(); 1742499SN/A } 1752499SN/A} 1762499SN/A 1772499SN/A// 178465SN/A// static function: call init() on all SimObjects. 179465SN/A// 180465SN/Avoid 181465SN/ASimObject::initAll() 182465SN/A{ 183465SN/A SimObjectList::iterator i = simObjectList.begin(); 184465SN/A SimObjectList::iterator end = simObjectList.end(); 185465SN/A 186465SN/A for (; i != end; ++i) { 187465SN/A SimObject *obj = *i; 188465SN/A obj->init(); 189465SN/A } 190465SN/A} 191465SN/A 192465SN/A// 193330SN/A// static function: call resetStats() on all SimObjects. 194330SN/A// 195330SN/Avoid 196330SN/ASimObject::resetAllStats() 197330SN/A{ 198332SN/A SimObjectList::iterator i = simObjectList.begin(); 199332SN/A SimObjectList::iterator end = simObjectList.end(); 200332SN/A 201332SN/A for (; i != end; ++i) { 202332SN/A SimObject *obj = *i; 203332SN/A obj->resetStats(); 204332SN/A } 205330SN/A} 206330SN/A 207330SN/A// 208395SN/A// static function: serialize all SimObjects. 209395SN/A// 210395SN/Avoid 211395SN/ASimObject::serializeAll(ostream &os) 212395SN/A{ 213573SN/A SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 214573SN/A SimObjectList::reverse_iterator rend = simObjectList.rend(); 215395SN/A 216573SN/A for (; ri != rend; ++ri) { 217573SN/A SimObject *obj = *ri; 218395SN/A obj->nameOut(os); 219395SN/A obj->serialize(os); 220395SN/A } 221395SN/A} 222843SN/A 2231031SN/A#ifdef DEBUG 2241031SN/A// 2251031SN/A// static function: flag which objects should have the debugger break 2261031SN/A// 2271031SN/Avoid 2281031SN/ASimObject::debugObjectBreak(const string &objs) 2291031SN/A{ 2301031SN/A SimObjectList::const_iterator i = simObjectList.begin(); 2311031SN/A SimObjectList::const_iterator end = simObjectList.end(); 2321031SN/A 2331031SN/A ObjectMatch match(objs); 2341031SN/A for (; i != end; ++i) { 2351031SN/A SimObject *obj = *i; 2361031SN/A obj->doDebugBreak = match.match(obj->name()); 2371031SN/A } 2381031SN/A} 2391031SN/A 2401031SN/Aextern "C" 2411031SN/Avoid 2421031SN/AdebugObjectBreak(const char *objs) 2431031SN/A{ 2441031SN/A SimObject::debugObjectBreak(string(objs)); 2451031SN/A} 2461031SN/A#endif 2471031SN/A 248938SN/Avoid 249938SN/ASimObject::recordEvent(const std::string &stat) 250938SN/A{ 251938SN/A if (doRecordEvent) 252938SN/A Stats::recordEvent(stat); 253938SN/A} 254938SN/A 2552609SN/Avoid 2562609SN/ASimObject::drain(Serializer *serializer) 2572609SN/A{ 2582609SN/A serializer->signalDrained(); 2592609SN/A} 2602609SN/A 261843SN/ADEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject) 262