sim_object.hh revision 11800:54436a1784dc
16184SN/A/* 210330Smitch.hayenga@arm.com * Copyright (c) 2015 ARM Limited 38842Smrinmoy.ghosh@arm.com * All rights reserved 48842Smrinmoy.ghosh@arm.com * 58842Smrinmoy.ghosh@arm.com * The license below extends only to copyright in the software and shall 68842Smrinmoy.ghosh@arm.com * not be construed as granting a license to any other intellectual 78842Smrinmoy.ghosh@arm.com * property including but not limited to intellectual property relating 88842Smrinmoy.ghosh@arm.com * to a hardware implementation of the functionality of the software 98842Smrinmoy.ghosh@arm.com * licensed hereunder. You may use the software subject to the license 108842Smrinmoy.ghosh@arm.com * terms below provided that you ensure that this notice is replicated 118842Smrinmoy.ghosh@arm.com * unmodified and in its entirety in all distributions of the software, 128842Smrinmoy.ghosh@arm.com * modified or unmodified, in source code or in binary form. 138842Smrinmoy.ghosh@arm.com * 146184SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 156184SN/A * Copyright (c) 2010 Advanced Micro Devices, Inc. 166184SN/A * All rights reserved. 176184SN/A * 186184SN/A * Redistribution and use in source and binary forms, with or without 196184SN/A * modification, are permitted provided that the following conditions are 206184SN/A * met: redistributions of source code must retain the above copyright 216184SN/A * notice, this list of conditions and the following disclaimer; 226184SN/A * redistributions in binary form must reproduce the above copyright 236184SN/A * notice, this list of conditions and the following disclaimer in the 246184SN/A * documentation and/or other materials provided with the distribution; 256184SN/A * neither the name of the copyright holders nor the names of its 266184SN/A * contributors may be used to endorse or promote products derived from 276184SN/A * this software without specific prior written permission. 286184SN/A * 296184SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 306184SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 316184SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326184SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336184SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 346184SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 356184SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 366184SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 376184SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 386184SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 396184SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 406184SN/A * 416184SN/A * Authors: Steve Reinhardt 426184SN/A * Nathan Binkert 439360SE.Tomusk@sms.ed.ac.uk */ 446184SN/A 456226Snate@binkert.org/* @file 466184SN/A * User Console Definitions 479480Snilay@cs.wisc.edu */ 489480Snilay@cs.wisc.edu 499691Satgutier@umich.edu#ifndef __SIM_OBJECT_HH__ 509480Snilay@cs.wisc.edu#define __SIM_OBJECT_HH__ 519480Snilay@cs.wisc.edu 529691Satgutier@umich.edu#include <string> 539480Snilay@cs.wisc.edu#include <vector> 549480Snilay@cs.wisc.edu 559691Satgutier@umich.edu#include "params/SimObject.hh" 569691Satgutier@umich.edu#include "sim/drain.hh" 579691Satgutier@umich.edu#include "sim/eventq.hh" 589691Satgutier@umich.edu#include "sim/eventq_impl.hh" 599691Satgutier@umich.edu#include "sim/serialize.hh" 609480Snilay@cs.wisc.edu 619480Snilay@cs.wisc.educlass EventManager; 629480Snilay@cs.wisc.educlass ProbeManager; 636184SN/A 649691Satgutier@umich.edu/** 659691Satgutier@umich.edu * Abstract superclass for simulation objects. Represents things that 669691Satgutier@umich.edu * correspond to physical components and can be specified via the 679691Satgutier@umich.edu * config file (CPUs, caches, etc.). 689691Satgutier@umich.edu * 699691Satgutier@umich.edu * SimObject initialization is controlled by the instantiate method in 709691Satgutier@umich.edu * src/python/m5/simulate.py. There are slightly different 716184SN/A * initialization paths when starting the simulation afresh and when 729360SE.Tomusk@sms.ed.ac.uk * loading from a checkpoint. After instantiation and connecting 736184SN/A * ports, simulate.py initializes the object using the following call 746184SN/A * sequence: 756184SN/A * 766184SN/A * <ol> 776184SN/A * <li>SimObject::init() 789360SE.Tomusk@sms.ed.ac.uk * <li>SimObject::regStats() 796184SN/A * <li><ul> 806184SN/A * <li>SimObject::initState() if starting afresh. 816184SN/A * <li>SimObject::loadState() if restoring from a checkpoint. 826184SN/A * </ul> 836184SN/A * <li>SimObject::resetStats() 846184SN/A * <li>SimObject::startup() 856184SN/A * <li>Drainable::drainResume() if resuming from a checkpoint. 866184SN/A * </ol> 876184SN/A * 886184SN/A * @note Whenever a method is called on all objects in the simulator's 896184SN/A * object tree (e.g., init(), startup(), or loadState()), a pre-order 906184SN/A * depth-first traversal is performed (see descendants() in 916184SN/A * SimObject.py). This has the effect of calling the method on the 926184SN/A * parent node <i>before</i> its children. 936184SN/A */ 946184SN/Aclass SimObject : public EventManager, public Serializable, public Drainable 956184SN/A{ 966184SN/A private: 976184SN/A typedef std::vector<SimObject *> SimObjectList; 989360SE.Tomusk@sms.ed.ac.uk 999360SE.Tomusk@sms.ed.ac.uk /** List of all instantiated simulation objects. */ 1009360SE.Tomusk@sms.ed.ac.uk static SimObjectList simObjectList; 1016184SN/A 1026184SN/A /** Manager coordinates hooking up probe points with listeners. */ 1036184SN/A ProbeManager *probeManager; 1046184SN/A 1056184SN/A protected: 1069360SE.Tomusk@sms.ed.ac.uk /** Cached copy of the object parameters. */ 1079360SE.Tomusk@sms.ed.ac.uk const SimObjectParams *_params; 1089360SE.Tomusk@sms.ed.ac.uk 1099360SE.Tomusk@sms.ed.ac.uk public: 1106184SN/A typedef SimObjectParams Params; 1116184SN/A const Params *params() const { return _params; } 1126184SN/A SimObject(const Params *_params); 1136184SN/A virtual ~SimObject(); 1146184SN/A 1156184SN/A public: 1169360SE.Tomusk@sms.ed.ac.uk 1179360SE.Tomusk@sms.ed.ac.uk virtual const std::string name() const { return params()->name; } 1189360SE.Tomusk@sms.ed.ac.uk 1199360SE.Tomusk@sms.ed.ac.uk /** 1209360SE.Tomusk@sms.ed.ac.uk * init() is called after all C++ SimObjects have been created and 1219360SE.Tomusk@sms.ed.ac.uk * all ports are connected. Initializations that are independent 1229360SE.Tomusk@sms.ed.ac.uk * of unserialization but rely on a fully instantiated and 1239360SE.Tomusk@sms.ed.ac.uk * connected SimObject graph should be done here. 1249360SE.Tomusk@sms.ed.ac.uk */ 1259360SE.Tomusk@sms.ed.ac.uk virtual void init(); 1269360SE.Tomusk@sms.ed.ac.uk 1279360SE.Tomusk@sms.ed.ac.uk /** 1289360SE.Tomusk@sms.ed.ac.uk * loadState() is called on each SimObject when restoring from a 1299360SE.Tomusk@sms.ed.ac.uk * checkpoint. The default implementation simply calls 1309360SE.Tomusk@sms.ed.ac.uk * unserialize() if there is a corresponding section in the 1319360SE.Tomusk@sms.ed.ac.uk * checkpoint. However, objects can override loadState() to get 1329360SE.Tomusk@sms.ed.ac.uk * other behaviors, e.g., doing other programmed initializations 1339360SE.Tomusk@sms.ed.ac.uk * after unserialize(), or complaining if no checkpoint section is 1349360SE.Tomusk@sms.ed.ac.uk * found. 1359360SE.Tomusk@sms.ed.ac.uk * 1369360SE.Tomusk@sms.ed.ac.uk * @param cp Checkpoint to restore the state from. 1376184SN/A */ 1386184SN/A virtual void loadState(CheckpointIn &cp); 1396184SN/A 1406184SN/A /** 1416184SN/A * initState() is called on each SimObject when *not* restoring 1426184SN/A * from a checkpoint. This provides a hook for state 1436184SN/A * initializations that are only required for a "cold start". 1446184SN/A */ 1456184SN/A virtual void initState(); 1466184SN/A 1476184SN/A /** 1486184SN/A * Register statistics for this object. 1496184SN/A */ 1506184SN/A virtual void regStats(); 1516184SN/A 1529360SE.Tomusk@sms.ed.ac.uk /** 1536184SN/A * Reset statistics associated with this object. 1546184SN/A */ 1556184SN/A virtual void resetStats(); 1566184SN/A 1576184SN/A /** 1586184SN/A * Register probe points for this object. 1596184SN/A */ 1609360SE.Tomusk@sms.ed.ac.uk virtual void regProbePoints(); 1616184SN/A 1626184SN/A /** 1636184SN/A * Register probe listeners for this object. 1646184SN/A */ 1656184SN/A virtual void regProbeListeners(); 1666184SN/A 1676184SN/A /** 1686184SN/A * Get the probe manager for this object. 1696184SN/A */ 1706184SN/A ProbeManager *getProbeManager(); 1716184SN/A 1726184SN/A /** 1736184SN/A * startup() is the final initialization call before simulation. 1746184SN/A * All state is initialized (including unserialized state, if any, 1756184SN/A * such as the curTick() value), so this is the appropriate place to 1766184SN/A * schedule initial event(s) for objects that need them. 1776184SN/A */ 1786184SN/A virtual void startup(); 1798842Smrinmoy.ghosh@arm.com 1808842Smrinmoy.ghosh@arm.com /** 1819480Snilay@cs.wisc.edu * Provide a default implementation of the drain interface for 1828842Smrinmoy.ghosh@arm.com * objects that don't need draining. 1838842Smrinmoy.ghosh@arm.com */ 1849360SE.Tomusk@sms.ed.ac.uk DrainState drain() override { return DrainState::Drained; } 1859360SE.Tomusk@sms.ed.ac.uk 1868842Smrinmoy.ghosh@arm.com /** 1878842Smrinmoy.ghosh@arm.com * Write back dirty buffers to memory using functional writes. 1889327Smrinmoy.ghosh@arm.com * 1898842Smrinmoy.ghosh@arm.com * After returning, an object implementing this method should have 1908842Smrinmoy.ghosh@arm.com * written all its dirty data back to memory. This method is 1916184SN/A * typically used to prepare a system with caches for 1929480Snilay@cs.wisc.edu * checkpointing. 1936184SN/A */ 1946184SN/A virtual void memWriteback() {}; 1956184SN/A 1966184SN/A /** 1976184SN/A * Invalidate the contents of memory buffers. 1986184SN/A * 1996184SN/A * When the switching to hardware virtualized CPU models, we need 2006184SN/A * to make sure that we don't have any cached state in the system 2016184SN/A * that might become stale when we return. This method is used to 2026184SN/A * flush all such state back to main memory. 2036184SN/A * 2046184SN/A * @warn This does <i>not</i> cause any dirty state to be written 2059360SE.Tomusk@sms.ed.ac.uk * back to memory. 2066184SN/A */ 2076184SN/A virtual void memInvalidate() {}; 2089360SE.Tomusk@sms.ed.ac.uk 2099360SE.Tomusk@sms.ed.ac.uk void serialize(CheckpointOut &cp) const override {}; 2106184SN/A void unserialize(CheckpointIn &cp) override {}; 2116184SN/A 2129360SE.Tomusk@sms.ed.ac.uk /** 2139360SE.Tomusk@sms.ed.ac.uk * Serialize all SimObjects in the system. 2146184SN/A */ 2156184SN/A static void serializeAll(CheckpointOut &cp); 2166184SN/A 2176184SN/A#ifdef DEBUG 2186184SN/A public: 2196184SN/A bool doDebugBreak; 2206184SN/A static void debugObjectBreak(const std::string &objs); 2218842Smrinmoy.ghosh@arm.com#endif 2226184SN/A 2236184SN/A /** 2249360SE.Tomusk@sms.ed.ac.uk * Find the SimObject with the given name and return a pointer to 2256184SN/A * it. Primarily used for interactive debugging. Argument is 2266184SN/A * char* rather than std::string to make it callable from gdb. 2276184SN/A */ 2286184SN/A static SimObject *find(const char *name); 2296184SN/A}; 2306184SN/A 2318842Smrinmoy.ghosh@arm.com/** 2326184SN/A * Base class to wrap object resolving functionality. 2336184SN/A * 2346184SN/A * This can be provided to the serialization framework to allow it to 2358842Smrinmoy.ghosh@arm.com * map object names onto C++ objects. 2366184SN/A */ 2376184SN/Aclass SimObjectResolver 2386184SN/A{ 2396184SN/A public: 2406184SN/A virtual ~SimObjectResolver() { } 2418842Smrinmoy.ghosh@arm.com 2426184SN/A // Find a SimObject given a full path name 2436184SN/A virtual SimObject *resolveSimObject(const std::string &name) = 0; 2446184SN/A}; 2458842Smrinmoy.ghosh@arm.com 2466184SN/A#ifdef DEBUG 2476184SN/Avoid debugObjectBreak(const char *objs); 2486184SN/A#endif 2496184SN/A 2506184SN/A#endif // __SIM_OBJECT_HH__ 2516184SN/A