sim_object.hh revision 10422
113559Snikos.nikoleris@arm.com/* 212109SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 312109SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 412109SRekai.GonzalezAlberquilla@arm.com * All rights reserved. 512109SRekai.GonzalezAlberquilla@arm.com * 612109SRekai.GonzalezAlberquilla@arm.com * Redistribution and use in source and binary forms, with or without 712109SRekai.GonzalezAlberquilla@arm.com * modification, are permitted provided that the following conditions are 812109SRekai.GonzalezAlberquilla@arm.com * met: redistributions of source code must retain the above copyright 912109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer; 1012109SRekai.GonzalezAlberquilla@arm.com * redistributions in binary form must reproduce the above copyright 1112109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer in the 1212109SRekai.GonzalezAlberquilla@arm.com * documentation and/or other materials provided with the distribution; 134486Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 144486Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 154486Sbinkertn@umich.edu * this software without specific prior written permission. 164486Sbinkertn@umich.edu * 174486Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184486Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194486Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204486Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214486Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224486Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234486Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244486Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254486Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264486Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274486Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284486Sbinkertn@umich.edu * 294486Sbinkertn@umich.edu * Authors: Steve Reinhardt 304486Sbinkertn@umich.edu * Nathan Binkert 314486Sbinkertn@umich.edu */ 324486Sbinkertn@umich.edu 334486Sbinkertn@umich.edu/* @file 344486Sbinkertn@umich.edu * User Console Definitions 354486Sbinkertn@umich.edu */ 364486Sbinkertn@umich.edu 374486Sbinkertn@umich.edu#ifndef __SIM_OBJECT_HH__ 384486Sbinkertn@umich.edu#define __SIM_OBJECT_HH__ 394486Sbinkertn@umich.edu 404486Sbinkertn@umich.edu#include <iostream> 4112563Sgabeblack@google.com#include <list> 4212563Sgabeblack@google.com#include <map> 436654Snate@binkert.org#include <string> 443102SN/A#include <vector> 453102SN/A 4613665Sandreas.sandberg@arm.com#include "enums/MemoryMode.hh" 4713665Sandreas.sandberg@arm.com#include "params/SimObject.hh" 4813665Sandreas.sandberg@arm.com#include "sim/drain.hh" 4913665Sandreas.sandberg@arm.com#include "sim/eventq_impl.hh" 5013665Sandreas.sandberg@arm.com#include "sim/serialize.hh" 514486Sbinkertn@umich.edu 5213559Snikos.nikoleris@arm.comclass BaseCPU; 5313559Snikos.nikoleris@arm.comclass Event; 5413559Snikos.nikoleris@arm.comclass ProbeManager; 5513560Snikos.nikoleris@arm.com/** 5613560Snikos.nikoleris@arm.com * Abstract superclass for simulation objects. Represents things that 5713560Snikos.nikoleris@arm.com * correspond to physical components and can be specified via the 5813563Snikos.nikoleris@arm.com * config file (CPUs, caches, etc.). 5913563Snikos.nikoleris@arm.com * 6013563Snikos.nikoleris@arm.com * SimObject initialization is controlled by the instantiate method in 612817SN/A * src/python/m5/simulate.py. There are slightly different 622817SN/A * initialization paths when starting the simulation afresh and when 639341SAndreas.Sandberg@arm.com * loading from a checkpoint. After instantiation and connecting 649341SAndreas.Sandberg@arm.com * ports, simulate.py initializes the object using the following call 659518SAndreas.Sandberg@ARM.com * sequence: 669518SAndreas.Sandberg@ARM.com * 679518SAndreas.Sandberg@ARM.com * <ol> 689518SAndreas.Sandberg@ARM.com * <li>SimObject::init() 699518SAndreas.Sandberg@ARM.com * <li>SimObject::regStats() 709518SAndreas.Sandberg@ARM.com * <li><ul> 719518SAndreas.Sandberg@ARM.com * <li>SimObject::initState() if starting afresh. 729518SAndreas.Sandberg@ARM.com * <li>SimObject::loadState() if restoring from a checkpoint. 739518SAndreas.Sandberg@ARM.com * </ul> 749518SAndreas.Sandberg@ARM.com * <li>SimObject::resetStats() 759518SAndreas.Sandberg@ARM.com * <li>SimObject::startup() 769518SAndreas.Sandberg@ARM.com * <li>Drainable::drainResume() if resuming from a checkpoint. 772932SN/A * </ol> 781681SN/A * 7911780Sarthur.perais@inria.fr * @note Whenever a method is called on all objects in the simulator's 8013710Sgabor.dozsa@arm.com * object tree (e.g., init(), startup(), or loadState()), a pre-order 8113710Sgabor.dozsa@arm.com * depth-first traversal is performed (see descendants() in 8213710Sgabor.dozsa@arm.com * SimObject.py). This has the effect of calling the method on the 831681SN/A * parent node <i>before</i> its children. 849184Sandreas.hansson@arm.com */ 859184Sandreas.hansson@arm.comclass SimObject : public EventManager, public Serializable, public Drainable 869184Sandreas.hansson@arm.com{ 879184Sandreas.hansson@arm.com private: 889184Sandreas.hansson@arm.com typedef std::vector<SimObject *> SimObjectList; 892932SN/A 909982Satgutier@umich.edu /** List of all instantiated simulation objects. */ 9110331Smitch.hayenga@arm.com static SimObjectList simObjectList; 9210331Smitch.hayenga@arm.com 932932SN/A /** Manager coordinates hooking up probe points with listeners. */ 949184Sandreas.hansson@arm.com ProbeManager *probeManager; 959184Sandreas.hansson@arm.com 969184Sandreas.hansson@arm.com protected: 979184Sandreas.hansson@arm.com /** Cached copy of the object parameters. */ 989184Sandreas.hansson@arm.com const SimObjectParams *_params; 992932SN/A 1001681SN/A public: 1019184Sandreas.hansson@arm.com typedef SimObjectParams Params; 1029184Sandreas.hansson@arm.com const Params *params() const { return _params; } 1039184Sandreas.hansson@arm.com SimObject(const Params *_params); 1049184Sandreas.hansson@arm.com virtual ~SimObject(); 1052932SN/A 1061681SN/A public: 1079184Sandreas.hansson@arm.com 1082932SN/A virtual const std::string name() const { return params()->name; } 1099184Sandreas.hansson@arm.com 1102932SN/A /** 1119184Sandreas.hansson@arm.com * init() is called after all C++ SimObjects have been created and 1122932SN/A * all ports are connected. Initializations that are independent 1132932SN/A * of unserialization but rely on a fully instantiated and 1142932SN/A * connected SimObject graph should be done here. 1152932SN/A */ 1163223SN/A virtual void init(); 1172932SN/A 1189184Sandreas.hansson@arm.com /** 1191681SN/A * loadState() is called on each SimObject when restoring from a 1209184Sandreas.hansson@arm.com * checkpoint. The default implementation simply calls 1212932SN/A * unserialize() if there is a corresponding section in the 1222932SN/A * checkpoint. However, objects can override loadState() to get 1239184Sandreas.hansson@arm.com * other behaviors, e.g., doing other programmed initializations 1249184Sandreas.hansson@arm.com * after unserialize(), or complaining if no checkpoint section is 1251681SN/A * found. 1262932SN/A * 1272932SN/A * @param cp Checkpoint to restore the state from. 1281681SN/A */ 1292932SN/A virtual void loadState(Checkpoint *cp); 1302932SN/A 1318199SAli.Saidi@ARM.com /** 1328199SAli.Saidi@ARM.com * initState() is called on each SimObject when *not* restoring 1338199SAli.Saidi@ARM.com * from a checkpoint. This provides a hook for state 1348519SAli.Saidi@ARM.com * initializations that are only required for a "cold start". 1358519SAli.Saidi@ARM.com */ 1362932SN/A virtual void initState(); 1372932SN/A 1381681SN/A /** 1392932SN/A * Register statistics for this object. 1401681SN/A */ 1412932SN/A virtual void regStats(); 1422932SN/A 1432932SN/A /** 1449921Syasuko.eckert@amd.com * Reset statistics associated with this object. 1459921Syasuko.eckert@amd.com */ 14610338SCurtis.Dunham@arm.com virtual void resetStats(); 1479921Syasuko.eckert@amd.com 1489921Syasuko.eckert@amd.com /** 1499921Syasuko.eckert@amd.com * Register probe points for this object. 1509921Syasuko.eckert@amd.com */ 1519921Syasuko.eckert@amd.com virtual void regProbePoints(); 1529921Syasuko.eckert@amd.com 1539921Syasuko.eckert@amd.com /** 15412109SRekai.GonzalezAlberquilla@arm.com * Register probe listeners for this object. 15512109SRekai.GonzalezAlberquilla@arm.com */ 15613610Sgiacomo.gabrielli@arm.com virtual void regProbeListeners(); 15713610Sgiacomo.gabrielli@arm.com 1589921Syasuko.eckert@amd.com /** 1599921Syasuko.eckert@amd.com * Get the probe manager for this object. 1602932SN/A */ 1612932SN/A ProbeManager *getProbeManager(); 1621681SN/A 1634597Sbinkertn@umich.edu /** 16413559Snikos.nikoleris@arm.com * startup() is the final initialization call before simulation. 16513560Snikos.nikoleris@arm.com * All state is initialized (including unserialized state, if any, 16613560Snikos.nikoleris@arm.com * such as the curTick() value), so this is the appropriate place to 1674597Sbinkertn@umich.edu * schedule initial event(s) for objects that need them. 16813561Snikos.nikoleris@arm.com */ 16913561Snikos.nikoleris@arm.com virtual void startup(); 1704597Sbinkertn@umich.edu 17113562Snikos.nikoleris@arm.com /** 17213562Snikos.nikoleris@arm.com * Provide a default implementation of the drain interface that 1734597Sbinkertn@umich.edu * simply returns 0 (draining completed) and sets the drain state 17413563Snikos.nikoleris@arm.com * to Drained. 1754303SN/A */ 17610785Sgope@wisc.edu unsigned int drain(DrainManager *drainManger); 1779849Sandreas.hansson@arm.com 1789849Sandreas.hansson@arm.com /** 1798727Snilay@cs.wisc.edu * Serialize all SimObjects in the system. 1808727Snilay@cs.wisc.edu */ 1818887Sgeoffrey.blake@arm.com static void serializeAll(std::ostream &os); 1828887Sgeoffrey.blake@arm.com 1838887Sgeoffrey.blake@arm.com#ifdef DEBUG 18413665Sandreas.sandberg@arm.com public: 1858887Sgeoffrey.blake@arm.com bool doDebugBreak; 1868887Sgeoffrey.blake@arm.com static void debugObjectBreak(const std::string &objs); 1878887Sgeoffrey.blake@arm.com#endif 1888887Sgeoffrey.blake@arm.com 1898887Sgeoffrey.blake@arm.com /** 1908887Sgeoffrey.blake@arm.com * Find the SimObject with the given name and return a pointer to 1918887Sgeoffrey.blake@arm.com * it. Primarily used for interactive debugging. Argument is 1929132Satgutier@umich.edu * char* rather than std::string to make it callable from gdb. 1938887Sgeoffrey.blake@arm.com */ 1948887Sgeoffrey.blake@arm.com static SimObject *find(const char *name); 19512563Sgabeblack@google.com}; 1968887Sgeoffrey.blake@arm.com 197#ifdef DEBUG 198void debugObjectBreak(const char *objs); 199#endif 200 201#endif // __SIM_OBJECT_HH__ 202