SimObject Initialization

From gem5
Jump to: navigation, search

The basic order of C++ SimObject construction and initialization is controlled by the instantiate() and simulate() Python functions in src/python/m5/

This process was revised in changeset 3f6413fc37a2. This page documents the process as of that changeset.

Once the Python SimObject hierarchy is created by the user's simulation script, that script calls instantiate() to create the C++ equivalent of that hierarchy. The primary steps in this process are:

  1. Resolve proxy parameters (those specified using Self or Parent).
  2. Dump the config.ini file to record the final resolved set of SimObjects and parameter values.
  3. Call the C++ constructors for all of the SimObjects. These constructors are called in an order that satisfies parameter dependencies, i.e., if object A is passed as a parameter to object B, then object A's constructor will be called before object B's constructor so that the C++ pointer to A can be passed to B's constructor. Note that this policy means that cyclic parameter dependencies cannot be supported.
  4. Instantiate the memory-system port connections.
  5. Call init() on each SimObject. This provides the first opportunity to perform initializations that depend on all SimObjects being fully constructed.
  6. Call regStats() on each SimObject.
  7. Call regFormulas() on each SimObject.
  8. Complete initialization of SimObject state from a checkpoint or from scratch.
    • If restoring from a checkpoint, call loadState(ckpt) on each SimObject. The default implementation simply calls unserialize() if there is a corresponding checkpoint section, so we get backward compatibility with earlier versions of the startup code for existing objects. However, objects can override loadState() to get other behaviors, e.g., doing other programmed initializations after unserialize(), or complaining if no checkpoint section is found.
    • If not restoring from a checkpoint, call initState() on each SimObject instead. This provides a hook for state initializations that are only required when not restoring from a checkpoint.
  9. Later, the first time that the user script calls simulate(), call startup() on each SimObject. This is the point where SimObjects that do self-initiated processing should schedule internal events, since the value of curTick could change during unserialization.