sim_object.hh revision 13781
12SN/A/* 210911Sandreas.sandberg@arm.com * Copyright (c) 2015 ARM Limited 310911Sandreas.sandberg@arm.com * All rights reserved 410911Sandreas.sandberg@arm.com * 510911Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall 610911Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual 710911Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating 810911Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software 910911Sandreas.sandberg@arm.com * licensed hereunder. You may use the software subject to the license 1010911Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated 1110911Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software, 1210911Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form. 1310911Sandreas.sandberg@arm.com * 141762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 157534Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 162SN/A * All rights reserved. 172SN/A * 182SN/A * Redistribution and use in source and binary forms, with or without 192SN/A * modification, are permitted provided that the following conditions are 202SN/A * met: redistributions of source code must retain the above copyright 212SN/A * notice, this list of conditions and the following disclaimer; 222SN/A * redistributions in binary form must reproduce the above copyright 232SN/A * notice, this list of conditions and the following disclaimer in the 242SN/A * documentation and/or other materials provided with the distribution; 252SN/A * neither the name of the copyright holders nor the names of its 262SN/A * contributors may be used to endorse or promote products derived from 272SN/A * this software without specific prior written permission. 282SN/A * 292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 422665Ssaidi@eecs.umich.edu * Nathan Binkert 432SN/A */ 442SN/A 452SN/A/* @file 462SN/A * User Console Definitions 472SN/A */ 482SN/A 492SN/A#ifndef __SIM_OBJECT_HH__ 502SN/A#define __SIM_OBJECT_HH__ 512SN/A 525491Sgblack@eecs.umich.edu#include <string> 532SN/A#include <vector> 542SN/A 554762Snate@binkert.org#include "params/SimObject.hh" 569342SAndreas.Sandberg@arm.com#include "sim/drain.hh" 5711800Sbrandon.potter@amd.com#include "sim/eventq.hh" 589356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh" 5913781Sgabeblack@google.com#include "sim/port.hh" 6056SN/A#include "sim/serialize.hh" 612SN/A 6211800Sbrandon.potter@amd.comclass EventManager; 6310023Smatt.horsnell@ARM.comclass ProbeManager; 6411800Sbrandon.potter@amd.com 659196SAndreas.Sandberg@arm.com/** 662SN/A * Abstract superclass for simulation objects. Represents things that 672SN/A * correspond to physical components and can be specified via the 682SN/A * config file (CPUs, caches, etc.). 699196SAndreas.Sandberg@arm.com * 709196SAndreas.Sandberg@arm.com * SimObject initialization is controlled by the instantiate method in 719196SAndreas.Sandberg@arm.com * src/python/m5/simulate.py. There are slightly different 729196SAndreas.Sandberg@arm.com * initialization paths when starting the simulation afresh and when 739196SAndreas.Sandberg@arm.com * loading from a checkpoint. After instantiation and connecting 749196SAndreas.Sandberg@arm.com * ports, simulate.py initializes the object using the following call 759196SAndreas.Sandberg@arm.com * sequence: 769196SAndreas.Sandberg@arm.com * 779196SAndreas.Sandberg@arm.com * <ol> 789196SAndreas.Sandberg@arm.com * <li>SimObject::init() 799196SAndreas.Sandberg@arm.com * <li>SimObject::regStats() 809196SAndreas.Sandberg@arm.com * <li><ul> 819196SAndreas.Sandberg@arm.com * <li>SimObject::initState() if starting afresh. 829196SAndreas.Sandberg@arm.com * <li>SimObject::loadState() if restoring from a checkpoint. 839196SAndreas.Sandberg@arm.com * </ul> 849196SAndreas.Sandberg@arm.com * <li>SimObject::resetStats() 859196SAndreas.Sandberg@arm.com * <li>SimObject::startup() 869342SAndreas.Sandberg@arm.com * <li>Drainable::drainResume() if resuming from a checkpoint. 879196SAndreas.Sandberg@arm.com * </ol> 889196SAndreas.Sandberg@arm.com * 899196SAndreas.Sandberg@arm.com * @note Whenever a method is called on all objects in the simulator's 909196SAndreas.Sandberg@arm.com * object tree (e.g., init(), startup(), or loadState()), a pre-order 919196SAndreas.Sandberg@arm.com * depth-first traversal is performed (see descendants() in 929196SAndreas.Sandberg@arm.com * SimObject.py). This has the effect of calling the method on the 939196SAndreas.Sandberg@arm.com * parent node <i>before</i> its children. 942SN/A */ 959342SAndreas.Sandberg@arm.comclass SimObject : public EventManager, public Serializable, public Drainable 962SN/A{ 972SN/A private: 982SN/A typedef std::vector<SimObject *> SimObjectList; 992SN/A 1009196SAndreas.Sandberg@arm.com /** List of all instantiated simulation objects. */ 1012SN/A static SimObjectList simObjectList; 1022SN/A 10310023Smatt.horsnell@ARM.com /** Manager coordinates hooking up probe points with listeners. */ 10410023Smatt.horsnell@ARM.com ProbeManager *probeManager; 10510023Smatt.horsnell@ARM.com 1064762Snate@binkert.org protected: 1079196SAndreas.Sandberg@arm.com /** Cached copy of the object parameters. */ 1084762Snate@binkert.org const SimObjectParams *_params; 1094762Snate@binkert.org 1102SN/A public: 1114762Snate@binkert.org typedef SimObjectParams Params; 1124762Snate@binkert.org const Params *params() const { return _params; } 1134762Snate@binkert.org SimObject(const Params *_params); 11410422Sandreas.hansson@arm.com virtual ~SimObject(); 1152SN/A 1165034Smilesck@eecs.umich.edu public: 1175034Smilesck@eecs.umich.edu 1181553SN/A virtual const std::string name() const { return params()->name; } 119265SN/A 1207532Ssteve.reinhardt@amd.com /** 1217532Ssteve.reinhardt@amd.com * init() is called after all C++ SimObjects have been created and 1227532Ssteve.reinhardt@amd.com * all ports are connected. Initializations that are independent 1237532Ssteve.reinhardt@amd.com * of unserialization but rely on a fully instantiated and 1247532Ssteve.reinhardt@amd.com * connected SimObject graph should be done here. 1257532Ssteve.reinhardt@amd.com */ 126465SN/A virtual void init(); 127465SN/A 1287532Ssteve.reinhardt@amd.com /** 1297532Ssteve.reinhardt@amd.com * loadState() is called on each SimObject when restoring from a 1307532Ssteve.reinhardt@amd.com * checkpoint. The default implementation simply calls 1317532Ssteve.reinhardt@amd.com * unserialize() if there is a corresponding section in the 1327532Ssteve.reinhardt@amd.com * checkpoint. However, objects can override loadState() to get 1337532Ssteve.reinhardt@amd.com * other behaviors, e.g., doing other programmed initializations 1347532Ssteve.reinhardt@amd.com * after unserialize(), or complaining if no checkpoint section is 1357532Ssteve.reinhardt@amd.com * found. 1369196SAndreas.Sandberg@arm.com * 1379196SAndreas.Sandberg@arm.com * @param cp Checkpoint to restore the state from. 1387532Ssteve.reinhardt@amd.com */ 13910905Sandreas.sandberg@arm.com virtual void loadState(CheckpointIn &cp); 1407532Ssteve.reinhardt@amd.com 1417532Ssteve.reinhardt@amd.com /** 1427532Ssteve.reinhardt@amd.com * initState() is called on each SimObject when *not* restoring 1437532Ssteve.reinhardt@amd.com * from a checkpoint. This provides a hook for state 1447532Ssteve.reinhardt@amd.com * initializations that are only required for a "cold start". 1457532Ssteve.reinhardt@amd.com */ 1467532Ssteve.reinhardt@amd.com virtual void initState(); 1477532Ssteve.reinhardt@amd.com 1489196SAndreas.Sandberg@arm.com /** 1499196SAndreas.Sandberg@arm.com * Register statistics for this object. 1509196SAndreas.Sandberg@arm.com */ 1512SN/A virtual void regStats(); 1529196SAndreas.Sandberg@arm.com 1539196SAndreas.Sandberg@arm.com /** 1549196SAndreas.Sandberg@arm.com * Reset statistics associated with this object. 1559196SAndreas.Sandberg@arm.com */ 156330SN/A virtual void resetStats(); 1572SN/A 1587532Ssteve.reinhardt@amd.com /** 15910023Smatt.horsnell@ARM.com * Register probe points for this object. 16010023Smatt.horsnell@ARM.com */ 16110023Smatt.horsnell@ARM.com virtual void regProbePoints(); 16210023Smatt.horsnell@ARM.com 16310023Smatt.horsnell@ARM.com /** 16410023Smatt.horsnell@ARM.com * Register probe listeners for this object. 16510023Smatt.horsnell@ARM.com */ 16610023Smatt.horsnell@ARM.com virtual void regProbeListeners(); 16710023Smatt.horsnell@ARM.com 16810023Smatt.horsnell@ARM.com /** 16910023Smatt.horsnell@ARM.com * Get the probe manager for this object. 17010023Smatt.horsnell@ARM.com */ 17110023Smatt.horsnell@ARM.com ProbeManager *getProbeManager(); 17210023Smatt.horsnell@ARM.com 17310023Smatt.horsnell@ARM.com /** 17413781Sgabeblack@google.com * Get a port with a given name and index. This is used at binding time 17513781Sgabeblack@google.com * and returns a reference to a protocol-agnostic port. 17613781Sgabeblack@google.com * 17713781Sgabeblack@google.com * @param if_name Port name 17813781Sgabeblack@google.com * @param idx Index in the case of a VectorPort 17913781Sgabeblack@google.com * 18013781Sgabeblack@google.com * @return A reference to the given port 18113781Sgabeblack@google.com */ 18213781Sgabeblack@google.com virtual Port &getPort(const std::string &if_name, 18313781Sgabeblack@google.com PortID idx=InvalidPortID); 18413781Sgabeblack@google.com 18513781Sgabeblack@google.com /** 1867532Ssteve.reinhardt@amd.com * startup() is the final initialization call before simulation. 1877532Ssteve.reinhardt@amd.com * All state is initialized (including unserialized state, if any, 1887823Ssteve.reinhardt@amd.com * such as the curTick() value), so this is the appropriate place to 1897532Ssteve.reinhardt@amd.com * schedule initial event(s) for objects that need them. 1907532Ssteve.reinhardt@amd.com */ 1917492Ssteve.reinhardt@amd.com virtual void startup(); 192330SN/A 1939196SAndreas.Sandberg@arm.com /** 19410913Sandreas.sandberg@arm.com * Provide a default implementation of the drain interface for 19510913Sandreas.sandberg@arm.com * objects that don't need draining. 1969342SAndreas.Sandberg@arm.com */ 19711168Sandreas.hansson@arm.com DrainState drain() override { return DrainState::Drained; } 1989342SAndreas.Sandberg@arm.com 19910911Sandreas.sandberg@arm.com /** 20010911Sandreas.sandberg@arm.com * Write back dirty buffers to memory using functional writes. 20110911Sandreas.sandberg@arm.com * 20210911Sandreas.sandberg@arm.com * After returning, an object implementing this method should have 20310911Sandreas.sandberg@arm.com * written all its dirty data back to memory. This method is 20410911Sandreas.sandberg@arm.com * typically used to prepare a system with caches for 20510911Sandreas.sandberg@arm.com * checkpointing. 20610911Sandreas.sandberg@arm.com */ 20710911Sandreas.sandberg@arm.com virtual void memWriteback() {}; 20810911Sandreas.sandberg@arm.com 20910911Sandreas.sandberg@arm.com /** 21010911Sandreas.sandberg@arm.com * Invalidate the contents of memory buffers. 21110911Sandreas.sandberg@arm.com * 21210911Sandreas.sandberg@arm.com * When the switching to hardware virtualized CPU models, we need 21310911Sandreas.sandberg@arm.com * to make sure that we don't have any cached state in the system 21410911Sandreas.sandberg@arm.com * that might become stale when we return. This method is used to 21510911Sandreas.sandberg@arm.com * flush all such state back to main memory. 21610911Sandreas.sandberg@arm.com * 21710911Sandreas.sandberg@arm.com * @warn This does <i>not</i> cause any dirty state to be written 21810911Sandreas.sandberg@arm.com * back to memory. 21910911Sandreas.sandberg@arm.com */ 22010911Sandreas.sandberg@arm.com virtual void memInvalidate() {}; 22110905Sandreas.sandberg@arm.com 22211168Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override {}; 22311168Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override {}; 22410905Sandreas.sandberg@arm.com 2259342SAndreas.Sandberg@arm.com /** 2269196SAndreas.Sandberg@arm.com * Serialize all SimObjects in the system. 2279196SAndreas.Sandberg@arm.com */ 22810905Sandreas.sandberg@arm.com static void serializeAll(CheckpointOut &cp); 229938SN/A 2301031SN/A#ifdef DEBUG 2311031SN/A public: 2321031SN/A bool doDebugBreak; 2331031SN/A static void debugObjectBreak(const std::string &objs); 2341031SN/A#endif 2351031SN/A 2365314Sstever@gmail.com /** 2375314Sstever@gmail.com * Find the SimObject with the given name and return a pointer to 2385315Sstever@gmail.com * it. Primarily used for interactive debugging. Argument is 2395314Sstever@gmail.com * char* rather than std::string to make it callable from gdb. 2405314Sstever@gmail.com */ 2415314Sstever@gmail.com static SimObject *find(const char *name); 2422SN/A}; 2432SN/A 24411067Sandreas.sandberg@arm.com/** 24511067Sandreas.sandberg@arm.com * Base class to wrap object resolving functionality. 24611067Sandreas.sandberg@arm.com * 24711067Sandreas.sandberg@arm.com * This can be provided to the serialization framework to allow it to 24811067Sandreas.sandberg@arm.com * map object names onto C++ objects. 24911067Sandreas.sandberg@arm.com */ 25011067Sandreas.sandberg@arm.comclass SimObjectResolver 25111067Sandreas.sandberg@arm.com{ 25211067Sandreas.sandberg@arm.com public: 25311067Sandreas.sandberg@arm.com virtual ~SimObjectResolver() { } 25411067Sandreas.sandberg@arm.com 25511067Sandreas.sandberg@arm.com // Find a SimObject given a full path name 25611067Sandreas.sandberg@arm.com virtual SimObject *resolveSimObject(const std::string &name) = 0; 25711067Sandreas.sandberg@arm.com}; 25811067Sandreas.sandberg@arm.com 2599554Sandreas.hansson@arm.com#ifdef DEBUG 2609554Sandreas.hansson@arm.comvoid debugObjectBreak(const char *objs); 2619554Sandreas.hansson@arm.com#endif 2629554Sandreas.hansson@arm.com 2632SN/A#endif // __SIM_OBJECT_HH__ 264