Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 1 | /* |
Andreas Sandberg | d5f5fbb | 2015-07-07 09:51:04 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015 ARM Limited |
| 3 | * All rights reserved |
| 4 | * |
| 5 | * The license below extends only to copyright in the software and shall |
| 6 | * not be construed as granting a license to any other intellectual |
| 7 | * property including but not limited to intellectual property relating |
| 8 | * to a hardware implementation of the functionality of the software |
| 9 | * licensed hereunder. You may use the software subject to the license |
| 10 | * terms below provided that you ensure that this notice is replicated |
| 11 | * unmodified and in its entirety in all distributions of the software, |
| 12 | * modified or unmodified, in source code or in binary form. |
| 13 | * |
Steve Reinhardt | ad8b963 | 2005-06-05 05:16:00 -0400 | [diff] [blame] | 14 | * Copyright (c) 2001-2005 The Regents of The University of Michigan |
Steve Reinhardt | e0754c0 | 2010-08-17 05:49:05 -0700 | [diff] [blame] | 15 | * Copyright (c) 2010 Advanced Micro Devices, Inc. |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 16 | * All rights reserved. |
| 17 | * |
| 18 | * Redistribution and use in source and binary forms, with or without |
| 19 | * modification, are permitted provided that the following conditions are |
| 20 | * met: redistributions of source code must retain the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer; |
| 22 | * redistributions in binary form must reproduce the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer in the |
| 24 | * documentation and/or other materials provided with the distribution; |
| 25 | * neither the name of the copyright holders nor the names of its |
| 26 | * contributors may be used to endorse or promote products derived from |
| 27 | * this software without specific prior written permission. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ali Saidi | cb0cf2d | 2006-05-31 19:26:56 -0400 | [diff] [blame] | 40 | * |
| 41 | * Authors: Steve Reinhardt |
| 42 | * Nathan Binkert |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 43 | */ |
| 44 | |
| 45 | /* @file |
| 46 | * User Console Definitions |
| 47 | */ |
| 48 | |
| 49 | #ifndef __SIM_OBJECT_HH__ |
| 50 | #define __SIM_OBJECT_HH__ |
| 51 | |
Gabe Black | 18c83be | 2008-06-21 14:23:58 -0400 | [diff] [blame] | 52 | #include <string> |
| 53 | #include <vector> |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 54 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 55 | #include "params/SimObject.hh" |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 56 | #include "sim/drain.hh" |
Brandon Potter | a928a43 | 2016-11-09 14:27:40 -0600 | [diff] [blame] | 57 | #include "sim/eventq.hh" |
Nilay Vaish | 2d64709 | 2012-11-16 10:27:47 -0600 | [diff] [blame] | 58 | #include "sim/eventq_impl.hh" |
Steve Reinhardt | 25693e9 | 2003-10-10 11:09:00 -0700 | [diff] [blame] | 59 | #include "sim/serialize.hh" |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 60 | |
Brandon Potter | a928a43 | 2016-11-09 14:27:40 -0600 | [diff] [blame] | 61 | class EventManager; |
Matt Horsnell | 739c6df | 2014-01-24 15:29:30 -0600 | [diff] [blame] | 62 | class ProbeManager; |
Brandon Potter | a928a43 | 2016-11-09 14:27:40 -0600 | [diff] [blame] | 63 | |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 64 | /** |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 65 | * Abstract superclass for simulation objects. Represents things that |
| 66 | * correspond to physical components and can be specified via the |
| 67 | * config file (CPUs, caches, etc.). |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 68 | * |
| 69 | * SimObject initialization is controlled by the instantiate method in |
| 70 | * src/python/m5/simulate.py. There are slightly different |
| 71 | * initialization paths when starting the simulation afresh and when |
| 72 | * loading from a checkpoint. After instantiation and connecting |
| 73 | * ports, simulate.py initializes the object using the following call |
| 74 | * sequence: |
| 75 | * |
| 76 | * <ol> |
| 77 | * <li>SimObject::init() |
| 78 | * <li>SimObject::regStats() |
| 79 | * <li><ul> |
| 80 | * <li>SimObject::initState() if starting afresh. |
| 81 | * <li>SimObject::loadState() if restoring from a checkpoint. |
| 82 | * </ul> |
| 83 | * <li>SimObject::resetStats() |
| 84 | * <li>SimObject::startup() |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 85 | * <li>Drainable::drainResume() if resuming from a checkpoint. |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 86 | * </ol> |
| 87 | * |
| 88 | * @note Whenever a method is called on all objects in the simulator's |
| 89 | * object tree (e.g., init(), startup(), or loadState()), a pre-order |
| 90 | * depth-first traversal is performed (see descendants() in |
| 91 | * SimObject.py). This has the effect of calling the method on the |
| 92 | * parent node <i>before</i> its children. |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 93 | */ |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 94 | class SimObject : public EventManager, public Serializable, public Drainable |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 95 | { |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 96 | private: |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 97 | typedef std::vector<SimObject *> SimObjectList; |
| 98 | |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 99 | /** List of all instantiated simulation objects. */ |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 100 | static SimObjectList simObjectList; |
| 101 | |
Matt Horsnell | 739c6df | 2014-01-24 15:29:30 -0600 | [diff] [blame] | 102 | /** Manager coordinates hooking up probe points with listeners. */ |
| 103 | ProbeManager *probeManager; |
| 104 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 105 | protected: |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 106 | /** Cached copy of the object parameters. */ |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 107 | const SimObjectParams *_params; |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 108 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 109 | public: |
| 110 | typedef SimObjectParams Params; |
| 111 | const Params *params() const { return _params; } |
| 112 | SimObject(const Params *_params); |
Andreas Hansson | 6498ccd | 2014-10-01 08:05:54 -0400 | [diff] [blame] | 113 | virtual ~SimObject(); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 114 | |
Miles Kaufmann | 54cc005 | 2007-08-30 15:16:59 -0400 | [diff] [blame] | 115 | public: |
| 116 | |
Nathan Binkert | 0f8067f | 2005-03-15 17:11:54 -0500 | [diff] [blame] | 117 | virtual const std::string name() const { return params()->name; } |
Andrew Schultz | 2ab51fb | 2003-10-31 17:32:04 -0500 | [diff] [blame] | 118 | |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 119 | /** |
| 120 | * init() is called after all C++ SimObjects have been created and |
| 121 | * all ports are connected. Initializations that are independent |
| 122 | * of unserialization but rely on a fully instantiated and |
| 123 | * connected SimObject graph should be done here. |
| 124 | */ |
Nathan Binkert | 5d7224c | 2004-01-14 02:00:20 -0500 | [diff] [blame] | 125 | virtual void init(); |
Nathan Binkert | 5d7224c | 2004-01-14 02:00:20 -0500 | [diff] [blame] | 126 | |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 127 | /** |
| 128 | * loadState() is called on each SimObject when restoring from a |
| 129 | * checkpoint. The default implementation simply calls |
| 130 | * unserialize() if there is a corresponding section in the |
| 131 | * checkpoint. However, objects can override loadState() to get |
| 132 | * other behaviors, e.g., doing other programmed initializations |
| 133 | * after unserialize(), or complaining if no checkpoint section is |
| 134 | * found. |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 135 | * |
| 136 | * @param cp Checkpoint to restore the state from. |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 137 | */ |
Andreas Sandberg | 76cd439 | 2015-07-07 09:51:03 +0100 | [diff] [blame] | 138 | virtual void loadState(CheckpointIn &cp); |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * initState() is called on each SimObject when *not* restoring |
| 142 | * from a checkpoint. This provides a hook for state |
| 143 | * initializations that are only required for a "cold start". |
| 144 | */ |
| 145 | virtual void initState(); |
| 146 | |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 147 | /** |
| 148 | * Register statistics for this object. |
| 149 | */ |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 150 | virtual void regStats(); |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * Reset statistics associated with this object. |
| 154 | */ |
Nathan Binkert | b064b8a | 2003-11-05 18:21:18 -0500 | [diff] [blame] | 155 | virtual void resetStats(); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 156 | |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 157 | /** |
Matt Horsnell | 739c6df | 2014-01-24 15:29:30 -0600 | [diff] [blame] | 158 | * Register probe points for this object. |
| 159 | */ |
| 160 | virtual void regProbePoints(); |
| 161 | |
| 162 | /** |
| 163 | * Register probe listeners for this object. |
| 164 | */ |
| 165 | virtual void regProbeListeners(); |
| 166 | |
| 167 | /** |
| 168 | * Get the probe manager for this object. |
| 169 | */ |
| 170 | ProbeManager *getProbeManager(); |
| 171 | |
| 172 | /** |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 173 | * startup() is the final initialization call before simulation. |
| 174 | * All state is initialized (including unserialized state, if any, |
Steve Reinhardt | 6f11879 | 2011-01-07 21:50:29 -0800 | [diff] [blame] | 175 | * such as the curTick() value), so this is the appropriate place to |
Steve Reinhardt | f064aa3 | 2010-08-17 05:17:06 -0700 | [diff] [blame] | 176 | * schedule initial event(s) for objects that need them. |
| 177 | */ |
Steve Reinhardt | 30ce620 | 2010-07-05 21:39:38 -0700 | [diff] [blame] | 178 | virtual void startup(); |
Nathan Binkert | b064b8a | 2003-11-05 18:21:18 -0500 | [diff] [blame] | 179 | |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 180 | /** |
Andreas Sandberg | ed38e34 | 2015-07-07 09:51:05 +0100 | [diff] [blame] | 181 | * Provide a default implementation of the drain interface for |
| 182 | * objects that don't need draining. |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 183 | */ |
Andreas Hansson | 22c0419 | 2015-10-12 04:07:59 -0400 | [diff] [blame] | 184 | DrainState drain() override { return DrainState::Drained; } |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 185 | |
Andreas Sandberg | d5f5fbb | 2015-07-07 09:51:04 +0100 | [diff] [blame] | 186 | /** |
| 187 | * Write back dirty buffers to memory using functional writes. |
| 188 | * |
| 189 | * After returning, an object implementing this method should have |
| 190 | * written all its dirty data back to memory. This method is |
| 191 | * typically used to prepare a system with caches for |
| 192 | * checkpointing. |
| 193 | */ |
| 194 | virtual void memWriteback() {}; |
| 195 | |
| 196 | /** |
| 197 | * Invalidate the contents of memory buffers. |
| 198 | * |
| 199 | * When the switching to hardware virtualized CPU models, we need |
| 200 | * to make sure that we don't have any cached state in the system |
| 201 | * that might become stale when we return. This method is used to |
| 202 | * flush all such state back to main memory. |
| 203 | * |
| 204 | * @warn This does <i>not</i> cause any dirty state to be written |
| 205 | * back to memory. |
| 206 | */ |
| 207 | virtual void memInvalidate() {}; |
Andreas Sandberg | 76cd439 | 2015-07-07 09:51:03 +0100 | [diff] [blame] | 208 | |
Andreas Hansson | 22c0419 | 2015-10-12 04:07:59 -0400 | [diff] [blame] | 209 | void serialize(CheckpointOut &cp) const override {}; |
| 210 | void unserialize(CheckpointIn &cp) override {}; |
Andreas Sandberg | 76cd439 | 2015-07-07 09:51:03 +0100 | [diff] [blame] | 211 | |
Andreas Sandberg | b81a977 | 2012-11-02 11:32:01 -0500 | [diff] [blame] | 212 | /** |
Andreas Sandberg | d4a6d98 | 2012-09-07 14:20:53 -0500 | [diff] [blame] | 213 | * Serialize all SimObjects in the system. |
| 214 | */ |
Andreas Sandberg | 76cd439 | 2015-07-07 09:51:03 +0100 | [diff] [blame] | 215 | static void serializeAll(CheckpointOut &cp); |
Nathan Binkert | 838273a | 2004-06-28 16:49:35 -0400 | [diff] [blame] | 216 | |
Nathan Binkert | 3711ea7 | 2004-07-30 10:47:53 -0400 | [diff] [blame] | 217 | #ifdef DEBUG |
| 218 | public: |
| 219 | bool doDebugBreak; |
| 220 | static void debugObjectBreak(const std::string &objs); |
| 221 | #endif |
| 222 | |
Steve Reinhardt | 3952e41 | 2008-01-02 12:20:15 -0800 | [diff] [blame] | 223 | /** |
| 224 | * Find the SimObject with the given name and return a pointer to |
Steve Reinhardt | cde5a79 | 2008-01-02 13:46:22 -0800 | [diff] [blame] | 225 | * it. Primarily used for interactive debugging. Argument is |
Steve Reinhardt | 3952e41 | 2008-01-02 12:20:15 -0800 | [diff] [blame] | 226 | * char* rather than std::string to make it callable from gdb. |
| 227 | */ |
| 228 | static SimObject *find(const char *name); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 229 | }; |
| 230 | |
Andreas Sandberg | db465fd | 2015-09-01 13:40:05 +0100 | [diff] [blame] | 231 | /** |
| 232 | * Base class to wrap object resolving functionality. |
| 233 | * |
| 234 | * This can be provided to the serialization framework to allow it to |
| 235 | * map object names onto C++ objects. |
| 236 | */ |
| 237 | class SimObjectResolver |
| 238 | { |
| 239 | public: |
| 240 | virtual ~SimObjectResolver() { } |
| 241 | |
| 242 | // Find a SimObject given a full path name |
| 243 | virtual SimObject *resolveSimObject(const std::string &name) = 0; |
| 244 | }; |
| 245 | |
Andreas Hansson | 319443d | 2013-02-19 05:56:07 -0500 | [diff] [blame] | 246 | #ifdef DEBUG |
| 247 | void debugObjectBreak(const char *objs); |
| 248 | #endif |
| 249 | |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 250 | #endif // __SIM_OBJECT_HH__ |