sim_object.hh revision 10023
12SN/A/*
21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
37534Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
42SN/A * All rights reserved.
52SN/A *
62SN/A * Redistribution and use in source and binary forms, with or without
72SN/A * modification, are permitted provided that the following conditions are
82SN/A * met: redistributions of source code must retain the above copyright
92SN/A * notice, this list of conditions and the following disclaimer;
102SN/A * redistributions in binary form must reproduce the above copyright
112SN/A * notice, this list of conditions and the following disclaimer in the
122SN/A * documentation and/or other materials provided with the distribution;
132SN/A * neither the name of the copyright holders nor the names of its
142SN/A * contributors may be used to endorse or promote products derived from
152SN/A * this software without specific prior written permission.
162SN/A *
172SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312SN/A */
322SN/A
332SN/A/* @file
342SN/A * User Console Definitions
352SN/A */
362SN/A
372SN/A#ifndef __SIM_OBJECT_HH__
382SN/A#define __SIM_OBJECT_HH__
392SN/A
405491Sgblack@eecs.umich.edu#include <iostream>
415491Sgblack@eecs.umich.edu#include <list>
422SN/A#include <map>
435491Sgblack@eecs.umich.edu#include <string>
442SN/A#include <vector>
452SN/A
468737Skoansin.tan@gmail.com#include "enums/MemoryMode.hh"
474762Snate@binkert.org#include "params/SimObject.hh"
489342SAndreas.Sandberg@arm.com#include "sim/drain.hh"
499356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh"
5056SN/A#include "sim/serialize.hh"
512SN/A
522797Sktlim@umich.educlass BaseCPU;
532797Sktlim@umich.educlass Event;
5410023Smatt.horsnell@ARM.comclass ProbeManager;
559196SAndreas.Sandberg@arm.com/**
562SN/A * Abstract superclass for simulation objects.  Represents things that
572SN/A * correspond to physical components and can be specified via the
582SN/A * config file (CPUs, caches, etc.).
599196SAndreas.Sandberg@arm.com *
609196SAndreas.Sandberg@arm.com * SimObject initialization is controlled by the instantiate method in
619196SAndreas.Sandberg@arm.com * src/python/m5/simulate.py. There are slightly different
629196SAndreas.Sandberg@arm.com * initialization paths when starting the simulation afresh and when
639196SAndreas.Sandberg@arm.com * loading from a checkpoint.  After instantiation and connecting
649196SAndreas.Sandberg@arm.com * ports, simulate.py initializes the object using the following call
659196SAndreas.Sandberg@arm.com * sequence:
669196SAndreas.Sandberg@arm.com *
679196SAndreas.Sandberg@arm.com * <ol>
689196SAndreas.Sandberg@arm.com * <li>SimObject::init()
699196SAndreas.Sandberg@arm.com * <li>SimObject::regStats()
709196SAndreas.Sandberg@arm.com * <li><ul>
719196SAndreas.Sandberg@arm.com *     <li>SimObject::initState() if starting afresh.
729196SAndreas.Sandberg@arm.com *     <li>SimObject::loadState() if restoring from a checkpoint.
739196SAndreas.Sandberg@arm.com *     </ul>
749196SAndreas.Sandberg@arm.com * <li>SimObject::resetStats()
759196SAndreas.Sandberg@arm.com * <li>SimObject::startup()
769342SAndreas.Sandberg@arm.com * <li>Drainable::drainResume() if resuming from a checkpoint.
779196SAndreas.Sandberg@arm.com * </ol>
789196SAndreas.Sandberg@arm.com *
799196SAndreas.Sandberg@arm.com * @note Whenever a method is called on all objects in the simulator's
809196SAndreas.Sandberg@arm.com * object tree (e.g., init(), startup(), or loadState()), a pre-order
819196SAndreas.Sandberg@arm.com * depth-first traversal is performed (see descendants() in
829196SAndreas.Sandberg@arm.com * SimObject.py). This has the effect of calling the method on the
839196SAndreas.Sandberg@arm.com * parent node <i>before</i> its children.
842SN/A */
859342SAndreas.Sandberg@arm.comclass SimObject : public EventManager, public Serializable, public Drainable
862SN/A{
872SN/A  private:
882SN/A    typedef std::vector<SimObject *> SimObjectList;
892SN/A
909196SAndreas.Sandberg@arm.com    /** List of all instantiated simulation objects. */
912SN/A    static SimObjectList simObjectList;
922SN/A
9310023Smatt.horsnell@ARM.com    /** Manager coordinates hooking up probe points with listeners. */
9410023Smatt.horsnell@ARM.com    ProbeManager *probeManager;
9510023Smatt.horsnell@ARM.com
964762Snate@binkert.org  protected:
979196SAndreas.Sandberg@arm.com    /** Cached copy of the object parameters. */
984762Snate@binkert.org    const SimObjectParams *_params;
994762Snate@binkert.org
1002SN/A  public:
1014762Snate@binkert.org    typedef SimObjectParams Params;
1024762Snate@binkert.org    const Params *params() const { return _params; }
1034762Snate@binkert.org    SimObject(const Params *_params);
1042SN/A    virtual ~SimObject() {}
1052SN/A
1065034Smilesck@eecs.umich.edu  public:
1075034Smilesck@eecs.umich.edu
1081553SN/A    virtual const std::string name() const { return params()->name; }
109265SN/A
1107532Ssteve.reinhardt@amd.com    /**
1117532Ssteve.reinhardt@amd.com     * init() is called after all C++ SimObjects have been created and
1127532Ssteve.reinhardt@amd.com     * all ports are connected.  Initializations that are independent
1137532Ssteve.reinhardt@amd.com     * of unserialization but rely on a fully instantiated and
1147532Ssteve.reinhardt@amd.com     * connected SimObject graph should be done here.
1157532Ssteve.reinhardt@amd.com     */
116465SN/A    virtual void init();
117465SN/A
1187532Ssteve.reinhardt@amd.com    /**
1197532Ssteve.reinhardt@amd.com     * loadState() is called on each SimObject when restoring from a
1207532Ssteve.reinhardt@amd.com     * checkpoint.  The default implementation simply calls
1217532Ssteve.reinhardt@amd.com     * unserialize() if there is a corresponding section in the
1227532Ssteve.reinhardt@amd.com     * checkpoint.  However, objects can override loadState() to get
1237532Ssteve.reinhardt@amd.com     * other behaviors, e.g., doing other programmed initializations
1247532Ssteve.reinhardt@amd.com     * after unserialize(), or complaining if no checkpoint section is
1257532Ssteve.reinhardt@amd.com     * found.
1269196SAndreas.Sandberg@arm.com     *
1279196SAndreas.Sandberg@arm.com     * @param cp Checkpoint to restore the state from.
1287532Ssteve.reinhardt@amd.com     */
1297532Ssteve.reinhardt@amd.com    virtual void loadState(Checkpoint *cp);
1307532Ssteve.reinhardt@amd.com
1317532Ssteve.reinhardt@amd.com    /**
1327532Ssteve.reinhardt@amd.com     * initState() is called on each SimObject when *not* restoring
1337532Ssteve.reinhardt@amd.com     * from a checkpoint.  This provides a hook for state
1347532Ssteve.reinhardt@amd.com     * initializations that are only required for a "cold start".
1357532Ssteve.reinhardt@amd.com     */
1367532Ssteve.reinhardt@amd.com    virtual void initState();
1377532Ssteve.reinhardt@amd.com
1389196SAndreas.Sandberg@arm.com    /**
1399196SAndreas.Sandberg@arm.com     * Register statistics for this object.
1409196SAndreas.Sandberg@arm.com     */
1412SN/A    virtual void regStats();
1429196SAndreas.Sandberg@arm.com
1439196SAndreas.Sandberg@arm.com    /**
1449196SAndreas.Sandberg@arm.com     * Reset statistics associated with this object.
1459196SAndreas.Sandberg@arm.com     */
146330SN/A    virtual void resetStats();
1472SN/A
1487532Ssteve.reinhardt@amd.com    /**
14910023Smatt.horsnell@ARM.com     * Register probe points for this object.
15010023Smatt.horsnell@ARM.com     */
15110023Smatt.horsnell@ARM.com    virtual void regProbePoints();
15210023Smatt.horsnell@ARM.com
15310023Smatt.horsnell@ARM.com    /**
15410023Smatt.horsnell@ARM.com     * Register probe listeners for this object.
15510023Smatt.horsnell@ARM.com     */
15610023Smatt.horsnell@ARM.com    virtual void regProbeListeners();
15710023Smatt.horsnell@ARM.com
15810023Smatt.horsnell@ARM.com    /**
15910023Smatt.horsnell@ARM.com     * Get the probe manager for this object.
16010023Smatt.horsnell@ARM.com     */
16110023Smatt.horsnell@ARM.com    ProbeManager *getProbeManager();
16210023Smatt.horsnell@ARM.com
16310023Smatt.horsnell@ARM.com    /**
1647532Ssteve.reinhardt@amd.com     * startup() is the final initialization call before simulation.
1657532Ssteve.reinhardt@amd.com     * All state is initialized (including unserialized state, if any,
1667823Ssteve.reinhardt@amd.com     * such as the curTick() value), so this is the appropriate place to
1677532Ssteve.reinhardt@amd.com     * schedule initial event(s) for objects that need them.
1687532Ssteve.reinhardt@amd.com     */
1697492Ssteve.reinhardt@amd.com    virtual void startup();
170330SN/A
1719196SAndreas.Sandberg@arm.com    /**
1729342SAndreas.Sandberg@arm.com     * Provide a default implementation of the drain interface that
1739342SAndreas.Sandberg@arm.com     * simply returns 0 (draining completed) and sets the drain state
1749342SAndreas.Sandberg@arm.com     * to Drained.
1759342SAndreas.Sandberg@arm.com     */
1769342SAndreas.Sandberg@arm.com    unsigned int drain(DrainManager *drainManger);
1779342SAndreas.Sandberg@arm.com
1789342SAndreas.Sandberg@arm.com    /**
1799196SAndreas.Sandberg@arm.com     * Serialize all SimObjects in the system.
1809196SAndreas.Sandberg@arm.com     */
1819196SAndreas.Sandberg@arm.com    static void serializeAll(std::ostream &os);
182938SN/A
1831031SN/A#ifdef DEBUG
1841031SN/A  public:
1851031SN/A    bool doDebugBreak;
1861031SN/A    static void debugObjectBreak(const std::string &objs);
1871031SN/A#endif
1881031SN/A
1895314Sstever@gmail.com    /**
1905314Sstever@gmail.com     * Find the SimObject with the given name and return a pointer to
1915315Sstever@gmail.com     * it.  Primarily used for interactive debugging.  Argument is
1925314Sstever@gmail.com     * char* rather than std::string to make it callable from gdb.
1935314Sstever@gmail.com     */
1945314Sstever@gmail.com    static SimObject *find(const char *name);
1952SN/A};
1962SN/A
1979554Sandreas.hansson@arm.com#ifdef DEBUG
1989554Sandreas.hansson@arm.comvoid debugObjectBreak(const char *objs);
1999554Sandreas.hansson@arm.com#endif
2009554Sandreas.hansson@arm.com
2012SN/A#endif // __SIM_OBJECT_HH__
202