sim_object.cc revision 2901
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"
4056SN/A#include "sim/host.hh"
41330SN/A#include "sim/sim_object.hh"
42695SN/A#include "sim/stats.hh"
43843SN/A#include "sim/param.hh"
442SN/A
452SN/Ausing namespace std;
462SN/A
472SN/A
482SN/A////////////////////////////////////////////////////////////////////////
492SN/A//
502SN/A// SimObject member definitions
512SN/A//
522SN/A////////////////////////////////////////////////////////////////////////
532SN/A
542SN/A//
552SN/A// static list of all SimObjects, used for initialization etc.
562SN/A//
572SN/ASimObject::SimObjectList SimObject::simObjectList;
582SN/A
591031SN/Anamespace Stats {
601031SN/A    extern ObjectMatch event_ignore;
611031SN/A}
621031SN/A
632SN/A//
642SN/A// SimObject constructor: used to maintain static simObjectList
652SN/A//
661553SN/ASimObject::SimObject(Params *p)
671553SN/A    : _params(p)
682SN/A{
691031SN/A#ifdef DEBUG
701031SN/A    doDebugBreak = false;
711031SN/A#endif
721031SN/A
731553SN/A    doRecordEvent = !Stats::event_ignore.match(name());
741553SN/A    simObjectList.push_back(this);
752901Ssaidi@eecs.umich.edu    state = Running;
761553SN/A}
771553SN/A
781553SN/A//
791553SN/A// SimObject constructor: used to maintain static simObjectList
801553SN/A//
811553SN/ASimObject::SimObject(const string &_name)
821553SN/A    : _params(new Params)
831553SN/A{
841553SN/A    _params->name = _name;
851553SN/A#ifdef DEBUG
861553SN/A    doDebugBreak = false;
871553SN/A#endif
881553SN/A
891553SN/A    doRecordEvent = !Stats::event_ignore.match(name());
902SN/A    simObjectList.push_back(this);
912901Ssaidi@eecs.umich.edu    state = Running;
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
2232797Sktlim@umich.eduvoid
2242797Sktlim@umich.eduSimObject::unserializeAll(Checkpoint *cp)
2252797Sktlim@umich.edu{
2262797Sktlim@umich.edu    SimObjectList::reverse_iterator ri = simObjectList.rbegin();
2272797Sktlim@umich.edu    SimObjectList::reverse_iterator rend = simObjectList.rend();
2282797Sktlim@umich.edu
2292797Sktlim@umich.edu    for (; ri != rend; ++ri) {
2302797Sktlim@umich.edu        SimObject *obj = *ri;
2312797Sktlim@umich.edu        DPRINTFR(Config, "Unserializing '%s'\n",
2322797Sktlim@umich.edu                 obj->name());
2332797Sktlim@umich.edu        if(cp->sectionExists(obj->name()))
2342797Sktlim@umich.edu            obj->unserialize(cp, obj->name());
2352797Sktlim@umich.edu        else
2362797Sktlim@umich.edu            warn("Not unserializing '%s': no section found in checkpoint.\n",
2372797Sktlim@umich.edu                 obj->name());
2382797Sktlim@umich.edu   }
2392797Sktlim@umich.edu}
2402797Sktlim@umich.edu
2411031SN/A#ifdef DEBUG
2421031SN/A//
2431031SN/A// static function: flag which objects should have the debugger break
2441031SN/A//
2451031SN/Avoid
2461031SN/ASimObject::debugObjectBreak(const string &objs)
2471031SN/A{
2481031SN/A    SimObjectList::const_iterator i = simObjectList.begin();
2491031SN/A    SimObjectList::const_iterator end = simObjectList.end();
2501031SN/A
2511031SN/A    ObjectMatch match(objs);
2521031SN/A    for (; i != end; ++i) {
2531031SN/A        SimObject *obj = *i;
2541031SN/A        obj->doDebugBreak = match.match(obj->name());
2551031SN/A   }
2561031SN/A}
2571031SN/A
2581031SN/Avoid
2591031SN/AdebugObjectBreak(const char *objs)
2601031SN/A{
2611031SN/A    SimObject::debugObjectBreak(string(objs));
2621031SN/A}
2631031SN/A#endif
2641031SN/A
265938SN/Avoid
266938SN/ASimObject::recordEvent(const std::string &stat)
267938SN/A{
268938SN/A    if (doRecordEvent)
269938SN/A        Stats::recordEvent(stat);
270938SN/A}
271938SN/A
2722901Ssaidi@eecs.umich.eduunsigned int
2732839Sktlim@umich.eduSimObject::drain(Event *drain_event)
2742797Sktlim@umich.edu{
2752901Ssaidi@eecs.umich.edu    state = Drained;
2762901Ssaidi@eecs.umich.edu    return 0;
2772797Sktlim@umich.edu}
2782797Sktlim@umich.edu
2792609SN/Avoid
2802797Sktlim@umich.eduSimObject::resume()
2812609SN/A{
2822901Ssaidi@eecs.umich.edu    state = Running;
2832797Sktlim@umich.edu}
2842797Sktlim@umich.edu
2852797Sktlim@umich.eduvoid
2862797Sktlim@umich.eduSimObject::setMemoryMode(State new_mode)
2872797Sktlim@umich.edu{
2882901Ssaidi@eecs.umich.edu    panic("setMemoryMode() should only be called on systems");
2892797Sktlim@umich.edu}
2902797Sktlim@umich.edu
2912797Sktlim@umich.eduvoid
2922797Sktlim@umich.eduSimObject::switchOut()
2932797Sktlim@umich.edu{
2942797Sktlim@umich.edu    panic("Unimplemented!");
2952797Sktlim@umich.edu}
2962797Sktlim@umich.edu
2972797Sktlim@umich.eduvoid
2982797Sktlim@umich.eduSimObject::takeOverFrom(BaseCPU *cpu)
2992797Sktlim@umich.edu{
3002797Sktlim@umich.edu    panic("Unimplemented!");
3012609SN/A}
3022609SN/A
303843SN/ADEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject)
304