sim_object.hh revision 11800
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"
5956SN/A#include "sim/serialize.hh"
602SN/A
6111800Sbrandon.potter@amd.comclass EventManager;
6210023Smatt.horsnell@ARM.comclass ProbeManager;
6311800Sbrandon.potter@amd.com
649196SAndreas.Sandberg@arm.com/**
652SN/A * Abstract superclass for simulation objects.  Represents things that
662SN/A * correspond to physical components and can be specified via the
672SN/A * config file (CPUs, caches, etc.).
689196SAndreas.Sandberg@arm.com *
699196SAndreas.Sandberg@arm.com * SimObject initialization is controlled by the instantiate method in
709196SAndreas.Sandberg@arm.com * src/python/m5/simulate.py. There are slightly different
719196SAndreas.Sandberg@arm.com * initialization paths when starting the simulation afresh and when
729196SAndreas.Sandberg@arm.com * loading from a checkpoint.  After instantiation and connecting
739196SAndreas.Sandberg@arm.com * ports, simulate.py initializes the object using the following call
749196SAndreas.Sandberg@arm.com * sequence:
759196SAndreas.Sandberg@arm.com *
769196SAndreas.Sandberg@arm.com * <ol>
779196SAndreas.Sandberg@arm.com * <li>SimObject::init()
789196SAndreas.Sandberg@arm.com * <li>SimObject::regStats()
799196SAndreas.Sandberg@arm.com * <li><ul>
809196SAndreas.Sandberg@arm.com *     <li>SimObject::initState() if starting afresh.
819196SAndreas.Sandberg@arm.com *     <li>SimObject::loadState() if restoring from a checkpoint.
829196SAndreas.Sandberg@arm.com *     </ul>
839196SAndreas.Sandberg@arm.com * <li>SimObject::resetStats()
849196SAndreas.Sandberg@arm.com * <li>SimObject::startup()
859342SAndreas.Sandberg@arm.com * <li>Drainable::drainResume() if resuming from a checkpoint.
869196SAndreas.Sandberg@arm.com * </ol>
879196SAndreas.Sandberg@arm.com *
889196SAndreas.Sandberg@arm.com * @note Whenever a method is called on all objects in the simulator's
899196SAndreas.Sandberg@arm.com * object tree (e.g., init(), startup(), or loadState()), a pre-order
909196SAndreas.Sandberg@arm.com * depth-first traversal is performed (see descendants() in
919196SAndreas.Sandberg@arm.com * SimObject.py). This has the effect of calling the method on the
929196SAndreas.Sandberg@arm.com * parent node <i>before</i> its children.
932SN/A */
949342SAndreas.Sandberg@arm.comclass SimObject : public EventManager, public Serializable, public Drainable
952SN/A{
962SN/A  private:
972SN/A    typedef std::vector<SimObject *> SimObjectList;
982SN/A
999196SAndreas.Sandberg@arm.com    /** List of all instantiated simulation objects. */
1002SN/A    static SimObjectList simObjectList;
1012SN/A
10210023Smatt.horsnell@ARM.com    /** Manager coordinates hooking up probe points with listeners. */
10310023Smatt.horsnell@ARM.com    ProbeManager *probeManager;
10410023Smatt.horsnell@ARM.com
1054762Snate@binkert.org  protected:
1069196SAndreas.Sandberg@arm.com    /** Cached copy of the object parameters. */
1074762Snate@binkert.org    const SimObjectParams *_params;
1084762Snate@binkert.org
1092SN/A  public:
1104762Snate@binkert.org    typedef SimObjectParams Params;
1114762Snate@binkert.org    const Params *params() const { return _params; }
1124762Snate@binkert.org    SimObject(const Params *_params);
11310422Sandreas.hansson@arm.com    virtual ~SimObject();
1142SN/A
1155034Smilesck@eecs.umich.edu  public:
1165034Smilesck@eecs.umich.edu
1171553SN/A    virtual const std::string name() const { return params()->name; }
118265SN/A
1197532Ssteve.reinhardt@amd.com    /**
1207532Ssteve.reinhardt@amd.com     * init() is called after all C++ SimObjects have been created and
1217532Ssteve.reinhardt@amd.com     * all ports are connected.  Initializations that are independent
1227532Ssteve.reinhardt@amd.com     * of unserialization but rely on a fully instantiated and
1237532Ssteve.reinhardt@amd.com     * connected SimObject graph should be done here.
1247532Ssteve.reinhardt@amd.com     */
125465SN/A    virtual void init();
126465SN/A
1277532Ssteve.reinhardt@amd.com    /**
1287532Ssteve.reinhardt@amd.com     * loadState() is called on each SimObject when restoring from a
1297532Ssteve.reinhardt@amd.com     * checkpoint.  The default implementation simply calls
1307532Ssteve.reinhardt@amd.com     * unserialize() if there is a corresponding section in the
1317532Ssteve.reinhardt@amd.com     * checkpoint.  However, objects can override loadState() to get
1327532Ssteve.reinhardt@amd.com     * other behaviors, e.g., doing other programmed initializations
1337532Ssteve.reinhardt@amd.com     * after unserialize(), or complaining if no checkpoint section is
1347532Ssteve.reinhardt@amd.com     * found.
1359196SAndreas.Sandberg@arm.com     *
1369196SAndreas.Sandberg@arm.com     * @param cp Checkpoint to restore the state from.
1377532Ssteve.reinhardt@amd.com     */
13810905Sandreas.sandberg@arm.com    virtual void loadState(CheckpointIn &cp);
1397532Ssteve.reinhardt@amd.com
1407532Ssteve.reinhardt@amd.com    /**
1417532Ssteve.reinhardt@amd.com     * initState() is called on each SimObject when *not* restoring
1427532Ssteve.reinhardt@amd.com     * from a checkpoint.  This provides a hook for state
1437532Ssteve.reinhardt@amd.com     * initializations that are only required for a "cold start".
1447532Ssteve.reinhardt@amd.com     */
1457532Ssteve.reinhardt@amd.com    virtual void initState();
1467532Ssteve.reinhardt@amd.com
1479196SAndreas.Sandberg@arm.com    /**
1489196SAndreas.Sandberg@arm.com     * Register statistics for this object.
1499196SAndreas.Sandberg@arm.com     */
1502SN/A    virtual void regStats();
1519196SAndreas.Sandberg@arm.com
1529196SAndreas.Sandberg@arm.com    /**
1539196SAndreas.Sandberg@arm.com     * Reset statistics associated with this object.
1549196SAndreas.Sandberg@arm.com     */
155330SN/A    virtual void resetStats();
1562SN/A
1577532Ssteve.reinhardt@amd.com    /**
15810023Smatt.horsnell@ARM.com     * Register probe points for this object.
15910023Smatt.horsnell@ARM.com     */
16010023Smatt.horsnell@ARM.com    virtual void regProbePoints();
16110023Smatt.horsnell@ARM.com
16210023Smatt.horsnell@ARM.com    /**
16310023Smatt.horsnell@ARM.com     * Register probe listeners for this object.
16410023Smatt.horsnell@ARM.com     */
16510023Smatt.horsnell@ARM.com    virtual void regProbeListeners();
16610023Smatt.horsnell@ARM.com
16710023Smatt.horsnell@ARM.com    /**
16810023Smatt.horsnell@ARM.com     * Get the probe manager for this object.
16910023Smatt.horsnell@ARM.com     */
17010023Smatt.horsnell@ARM.com    ProbeManager *getProbeManager();
17110023Smatt.horsnell@ARM.com
17210023Smatt.horsnell@ARM.com    /**
1737532Ssteve.reinhardt@amd.com     * startup() is the final initialization call before simulation.
1747532Ssteve.reinhardt@amd.com     * All state is initialized (including unserialized state, if any,
1757823Ssteve.reinhardt@amd.com     * such as the curTick() value), so this is the appropriate place to
1767532Ssteve.reinhardt@amd.com     * schedule initial event(s) for objects that need them.
1777532Ssteve.reinhardt@amd.com     */
1787492Ssteve.reinhardt@amd.com    virtual void startup();
179330SN/A
1809196SAndreas.Sandberg@arm.com    /**
18110913Sandreas.sandberg@arm.com     * Provide a default implementation of the drain interface for
18210913Sandreas.sandberg@arm.com     * objects that don't need draining.
1839342SAndreas.Sandberg@arm.com     */
18411168Sandreas.hansson@arm.com    DrainState drain() override { return DrainState::Drained; }
1859342SAndreas.Sandberg@arm.com
18610911Sandreas.sandberg@arm.com    /**
18710911Sandreas.sandberg@arm.com     * Write back dirty buffers to memory using functional writes.
18810911Sandreas.sandberg@arm.com     *
18910911Sandreas.sandberg@arm.com     * After returning, an object implementing this method should have
19010911Sandreas.sandberg@arm.com     * written all its dirty data back to memory. This method is
19110911Sandreas.sandberg@arm.com     * typically used to prepare a system with caches for
19210911Sandreas.sandberg@arm.com     * checkpointing.
19310911Sandreas.sandberg@arm.com     */
19410911Sandreas.sandberg@arm.com    virtual void memWriteback() {};
19510911Sandreas.sandberg@arm.com
19610911Sandreas.sandberg@arm.com    /**
19710911Sandreas.sandberg@arm.com     * Invalidate the contents of memory buffers.
19810911Sandreas.sandberg@arm.com     *
19910911Sandreas.sandberg@arm.com     * When the switching to hardware virtualized CPU models, we need
20010911Sandreas.sandberg@arm.com     * to make sure that we don't have any cached state in the system
20110911Sandreas.sandberg@arm.com     * that might become stale when we return. This method is used to
20210911Sandreas.sandberg@arm.com     * flush all such state back to main memory.
20310911Sandreas.sandberg@arm.com     *
20410911Sandreas.sandberg@arm.com     * @warn This does <i>not</i> cause any dirty state to be written
20510911Sandreas.sandberg@arm.com     * back to memory.
20610911Sandreas.sandberg@arm.com     */
20710911Sandreas.sandberg@arm.com    virtual void memInvalidate() {};
20810905Sandreas.sandberg@arm.com
20911168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override {};
21011168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override {};
21110905Sandreas.sandberg@arm.com
2129342SAndreas.Sandberg@arm.com    /**
2139196SAndreas.Sandberg@arm.com     * Serialize all SimObjects in the system.
2149196SAndreas.Sandberg@arm.com     */
21510905Sandreas.sandberg@arm.com    static void serializeAll(CheckpointOut &cp);
216938SN/A
2171031SN/A#ifdef DEBUG
2181031SN/A  public:
2191031SN/A    bool doDebugBreak;
2201031SN/A    static void debugObjectBreak(const std::string &objs);
2211031SN/A#endif
2221031SN/A
2235314Sstever@gmail.com    /**
2245314Sstever@gmail.com     * Find the SimObject with the given name and return a pointer to
2255315Sstever@gmail.com     * it.  Primarily used for interactive debugging.  Argument is
2265314Sstever@gmail.com     * char* rather than std::string to make it callable from gdb.
2275314Sstever@gmail.com     */
2285314Sstever@gmail.com    static SimObject *find(const char *name);
2292SN/A};
2302SN/A
23111067Sandreas.sandberg@arm.com/**
23211067Sandreas.sandberg@arm.com * Base class to wrap object resolving functionality.
23311067Sandreas.sandberg@arm.com *
23411067Sandreas.sandberg@arm.com * This can be provided to the serialization framework to allow it to
23511067Sandreas.sandberg@arm.com * map object names onto C++ objects.
23611067Sandreas.sandberg@arm.com */
23711067Sandreas.sandberg@arm.comclass SimObjectResolver
23811067Sandreas.sandberg@arm.com{
23911067Sandreas.sandberg@arm.com  public:
24011067Sandreas.sandberg@arm.com    virtual ~SimObjectResolver() { }
24111067Sandreas.sandberg@arm.com
24211067Sandreas.sandberg@arm.com    // Find a SimObject given a full path name
24311067Sandreas.sandberg@arm.com    virtual SimObject *resolveSimObject(const std::string &name) = 0;
24411067Sandreas.sandberg@arm.com};
24511067Sandreas.sandberg@arm.com
2469554Sandreas.hansson@arm.com#ifdef DEBUG
2479554Sandreas.hansson@arm.comvoid debugObjectBreak(const char *objs);
2489554Sandreas.hansson@arm.com#endif
2499554Sandreas.hansson@arm.com
2502SN/A#endif // __SIM_OBJECT_HH__
251