1/* 2 * Copyright (c) 2001-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 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. 15 * 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.
| 1/* 2 * Copyright (c) 2001-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 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. 15 * 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.
|
27 */ 28 29#include <assert.h> 30 31#include "base/callback.hh" 32#include "base/inifile.hh" 33#include "base/match.hh" 34#include "base/misc.hh" 35#include "base/trace.hh" 36#include "base/stats/events.hh" 37#include "base/serializer.hh" 38#include "sim/configfile.hh" 39#include "sim/host.hh" 40#include "sim/sim_object.hh" 41#include "sim/stats.hh" 42#include "sim/param.hh" 43 44using namespace std; 45 46 47//////////////////////////////////////////////////////////////////////// 48// 49// SimObject member definitions 50// 51//////////////////////////////////////////////////////////////////////// 52 53// 54// static list of all SimObjects, used for initialization etc. 55// 56SimObject::SimObjectList SimObject::simObjectList; 57 58namespace Stats { 59 extern ObjectMatch event_ignore; 60} 61 62// 63// SimObject constructor: used to maintain static simObjectList 64// 65SimObject::SimObject(Params *p) 66 : _params(p) 67{ 68#ifdef DEBUG 69 doDebugBreak = false; 70#endif 71 72 doRecordEvent = !Stats::event_ignore.match(name()); 73 simObjectList.push_back(this); 74} 75 76// 77// SimObject constructor: used to maintain static simObjectList 78// 79SimObject::SimObject(const string &_name) 80 : _params(new Params) 81{ 82 _params->name = _name; 83#ifdef DEBUG 84 doDebugBreak = false; 85#endif 86 87 doRecordEvent = !Stats::event_ignore.match(name()); 88 simObjectList.push_back(this); 89} 90 91void 92SimObject::connect() 93{ 94} 95 96void 97SimObject::init() 98{ 99} 100 101// 102// no default statistics, so nothing to do in base implementation 103// 104void 105SimObject::regStats() 106{ 107} 108 109void 110SimObject::regFormulas() 111{ 112} 113 114void 115SimObject::resetStats() 116{ 117} 118 119// 120// static function: 121// call regStats() on all SimObjects and then regFormulas() on all 122// SimObjects. 123// 124struct SimObjectResetCB : public Callback 125{ 126 virtual void process() { SimObject::resetAllStats(); } 127}; 128 129namespace { 130 static SimObjectResetCB StatResetCB; 131} 132 133void 134SimObject::regAllStats() 135{ 136 SimObjectList::iterator i; 137 SimObjectList::iterator end = simObjectList.end(); 138 139 /** 140 * @todo change cprintfs to DPRINTFs 141 */ 142 for (i = simObjectList.begin(); i != end; ++i) { 143#ifdef STAT_DEBUG 144 cprintf("registering stats for %s\n", (*i)->name()); 145#endif 146 (*i)->regStats(); 147 } 148 149 for (i = simObjectList.begin(); i != end; ++i) { 150#ifdef STAT_DEBUG 151 cprintf("registering formulas for %s\n", (*i)->name()); 152#endif 153 (*i)->regFormulas(); 154 } 155 156 Stats::registerResetCallback(&StatResetCB); 157} 158 159// 160// static function: call connect() on all SimObjects. 161// 162void 163SimObject::connectAll() 164{ 165 SimObjectList::iterator i = simObjectList.begin(); 166 SimObjectList::iterator end = simObjectList.end(); 167 168 for (; i != end; ++i) { 169 SimObject *obj = *i; 170 obj->connect(); 171 } 172} 173 174// 175// static function: call init() on all SimObjects. 176// 177void 178SimObject::initAll() 179{ 180 SimObjectList::iterator i = simObjectList.begin(); 181 SimObjectList::iterator end = simObjectList.end(); 182 183 for (; i != end; ++i) { 184 SimObject *obj = *i; 185 obj->init(); 186 } 187} 188 189// 190// static function: call resetStats() on all SimObjects. 191// 192void 193SimObject::resetAllStats() 194{ 195 SimObjectList::iterator i = simObjectList.begin(); 196 SimObjectList::iterator end = simObjectList.end(); 197 198 for (; i != end; ++i) { 199 SimObject *obj = *i; 200 obj->resetStats(); 201 } 202} 203 204// 205// static function: serialize all SimObjects. 206// 207void 208SimObject::serializeAll(ostream &os) 209{ 210 SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 211 SimObjectList::reverse_iterator rend = simObjectList.rend(); 212 213 for (; ri != rend; ++ri) { 214 SimObject *obj = *ri; 215 obj->nameOut(os); 216 obj->serialize(os); 217 } 218} 219 220#ifdef DEBUG 221// 222// static function: flag which objects should have the debugger break 223// 224void 225SimObject::debugObjectBreak(const string &objs) 226{ 227 SimObjectList::const_iterator i = simObjectList.begin(); 228 SimObjectList::const_iterator end = simObjectList.end(); 229 230 ObjectMatch match(objs); 231 for (; i != end; ++i) { 232 SimObject *obj = *i; 233 obj->doDebugBreak = match.match(obj->name()); 234 } 235} 236 237extern "C" 238void 239debugObjectBreak(const char *objs) 240{ 241 SimObject::debugObjectBreak(string(objs)); 242} 243#endif 244 245void 246SimObject::recordEvent(const std::string &stat) 247{ 248 if (doRecordEvent) 249 Stats::recordEvent(stat); 250} 251 252void 253SimObject::drain(Serializer *serializer) 254{ 255 serializer->signalDrained(); 256} 257 258DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject)
| 30 */ 31 32#include <assert.h> 33 34#include "base/callback.hh" 35#include "base/inifile.hh" 36#include "base/match.hh" 37#include "base/misc.hh" 38#include "base/trace.hh" 39#include "base/stats/events.hh" 40#include "base/serializer.hh" 41#include "sim/configfile.hh" 42#include "sim/host.hh" 43#include "sim/sim_object.hh" 44#include "sim/stats.hh" 45#include "sim/param.hh" 46 47using namespace std; 48 49 50//////////////////////////////////////////////////////////////////////// 51// 52// SimObject member definitions 53// 54//////////////////////////////////////////////////////////////////////// 55 56// 57// static list of all SimObjects, used for initialization etc. 58// 59SimObject::SimObjectList SimObject::simObjectList; 60 61namespace Stats { 62 extern ObjectMatch event_ignore; 63} 64 65// 66// SimObject constructor: used to maintain static simObjectList 67// 68SimObject::SimObject(Params *p) 69 : _params(p) 70{ 71#ifdef DEBUG 72 doDebugBreak = false; 73#endif 74 75 doRecordEvent = !Stats::event_ignore.match(name()); 76 simObjectList.push_back(this); 77} 78 79// 80// SimObject constructor: used to maintain static simObjectList 81// 82SimObject::SimObject(const string &_name) 83 : _params(new Params) 84{ 85 _params->name = _name; 86#ifdef DEBUG 87 doDebugBreak = false; 88#endif 89 90 doRecordEvent = !Stats::event_ignore.match(name()); 91 simObjectList.push_back(this); 92} 93 94void 95SimObject::connect() 96{ 97} 98 99void 100SimObject::init() 101{ 102} 103 104// 105// no default statistics, so nothing to do in base implementation 106// 107void 108SimObject::regStats() 109{ 110} 111 112void 113SimObject::regFormulas() 114{ 115} 116 117void 118SimObject::resetStats() 119{ 120} 121 122// 123// static function: 124// call regStats() on all SimObjects and then regFormulas() on all 125// SimObjects. 126// 127struct SimObjectResetCB : public Callback 128{ 129 virtual void process() { SimObject::resetAllStats(); } 130}; 131 132namespace { 133 static SimObjectResetCB StatResetCB; 134} 135 136void 137SimObject::regAllStats() 138{ 139 SimObjectList::iterator i; 140 SimObjectList::iterator end = simObjectList.end(); 141 142 /** 143 * @todo change cprintfs to DPRINTFs 144 */ 145 for (i = simObjectList.begin(); i != end; ++i) { 146#ifdef STAT_DEBUG 147 cprintf("registering stats for %s\n", (*i)->name()); 148#endif 149 (*i)->regStats(); 150 } 151 152 for (i = simObjectList.begin(); i != end; ++i) { 153#ifdef STAT_DEBUG 154 cprintf("registering formulas for %s\n", (*i)->name()); 155#endif 156 (*i)->regFormulas(); 157 } 158 159 Stats::registerResetCallback(&StatResetCB); 160} 161 162// 163// static function: call connect() on all SimObjects. 164// 165void 166SimObject::connectAll() 167{ 168 SimObjectList::iterator i = simObjectList.begin(); 169 SimObjectList::iterator end = simObjectList.end(); 170 171 for (; i != end; ++i) { 172 SimObject *obj = *i; 173 obj->connect(); 174 } 175} 176 177// 178// static function: call init() on all SimObjects. 179// 180void 181SimObject::initAll() 182{ 183 SimObjectList::iterator i = simObjectList.begin(); 184 SimObjectList::iterator end = simObjectList.end(); 185 186 for (; i != end; ++i) { 187 SimObject *obj = *i; 188 obj->init(); 189 } 190} 191 192// 193// static function: call resetStats() on all SimObjects. 194// 195void 196SimObject::resetAllStats() 197{ 198 SimObjectList::iterator i = simObjectList.begin(); 199 SimObjectList::iterator end = simObjectList.end(); 200 201 for (; i != end; ++i) { 202 SimObject *obj = *i; 203 obj->resetStats(); 204 } 205} 206 207// 208// static function: serialize all SimObjects. 209// 210void 211SimObject::serializeAll(ostream &os) 212{ 213 SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 214 SimObjectList::reverse_iterator rend = simObjectList.rend(); 215 216 for (; ri != rend; ++ri) { 217 SimObject *obj = *ri; 218 obj->nameOut(os); 219 obj->serialize(os); 220 } 221} 222 223#ifdef DEBUG 224// 225// static function: flag which objects should have the debugger break 226// 227void 228SimObject::debugObjectBreak(const string &objs) 229{ 230 SimObjectList::const_iterator i = simObjectList.begin(); 231 SimObjectList::const_iterator end = simObjectList.end(); 232 233 ObjectMatch match(objs); 234 for (; i != end; ++i) { 235 SimObject *obj = *i; 236 obj->doDebugBreak = match.match(obj->name()); 237 } 238} 239 240extern "C" 241void 242debugObjectBreak(const char *objs) 243{ 244 SimObject::debugObjectBreak(string(objs)); 245} 246#endif 247 248void 249SimObject::recordEvent(const std::string &stat) 250{ 251 if (doRecordEvent) 252 Stats::recordEvent(stat); 253} 254 255void 256SimObject::drain(Serializer *serializer) 257{ 258 serializer->signalDrained(); 259} 260 261DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject)
|