One advantage of using a virtual platform or virtual prototype over real hardware for embedded software development and testing is the ability of some simulators to save snapshots of their state. If your processor model is detailed enough, it might take several minutes (or even hours) to simulate booting the OS. If you save a snapshot of your simulation just after you’ve finished booting, each time you want to run your embedded software you can simply restore the snapshot and go. Restarting a snapshot typically takes a few seconds. This can translate into a major productivity gain, especially if you’re running a thousand short software tests on the processor. Save and restore (or restart) has existed in HDL simulators for years, but things are trickier if SystemC is involved. For one thing, SystemC simulators use external tools for compilation and linking: i.e. gcc. They have more or less a “black box” understanding of global variables, local variables, file descriptors and heap values that make up the simulation state at any point in time. When you throw in multiple threads implemented with application-level threading packages and the fact that C++ heap objects are impractical to save programmatically, it’s easy to see why save and restore tools for HDL simulators can’t be easily extended for SystemC.
Beginning with version 6.2 of the Cadence Incisive Simulator (released in mid-2007), Incisive SystemC has supported the ability to save and restart simulation sessions for designs that include not only SystemC, but any combination of SystemC, VHDL, Verilog, and System Verilog. Currently the capability exists on Linux platforms.
Incisive implements save by storing a snapshot of the simulation state to a file. The state is restored when the saved snapshot file is used to start a new process. To save a snapshot from the command line, use the Tcl save command:ncsim> save saved_snap.
To save a snapshot from Simvision, choose "Save Checkpoint" from the simulation menu:
To restore, you can launch Incisive from the command line with the name of saved snapshot. For example:
georgef% ncsim -input sim.tcl saved_snap
You can also use the Tcl restart command to restore a snapshot if you are using the command line interface (restart is not supported in Simvision, you should use reinvoke instead):
ncsim> restart saved_snap
This saved state is separate from the state of the simulation environment, so you can launch a new session with the saved snapshot and vary simulation parameters by passing different arguments to ncsim. This is a great way to test different scenarios from a known “safe” point before a problem occurs.
There are a few things to keep in mind with SystemC save / restart. During restart, all internal variables inherit the same values from the process as it existed at the time of save (for example, C variables declared static). While this behavior helps assure that SystemC state information is properly saved and restored, it can also leave variables that reference the process environment (like file descriptor and sockets to other processes) in limbo. In my next post I'll show you how to handle these kinds of issues and point out some other things you should be aware of when using SystemC save / restart.