Skip to main content

In Depth Example - Max Instructions

This is a command line option normally provided by the Options.addCommonOptions() function, however implementing it can showcase some of the necessary considerations you should use when making your own command line options.

First, we can create the option:

from common import SimpleOpts

SimpleOpts.add_option("-I", "--maxinsts",
action="store", type=int,
default=None,
help="Total number of instructions to simulate"
)

opts = SimpleOpts.parse_args()

Now that we can access the data supplied on the CLI, we can use it to set the required property of the simulation. In this case, we need to set the option for all processors we have in the system, so an acceptable way to ensure the argument does what we want is the following:

if opts.maxinsts:
for cpu in system.cpu:
cpu.max_insts_any_thread = opts.maxinsts

Now the system will register that the program termination came from the thread hitting the maxinsts number as requires.

The Goal

The goal of this exercise was to show you that the arguments need to interact with the system in order to be useful. gem5 has a lot of functionality, and mastering it all is impossible, but you should have a familiarity with the options allowed in the CPU. In order to get a handle on all of them, you might find it useful to grep in the $GEM_PATH/cpu/ directory. To get the full options listing for the CPU, BaseCPU.py provides everything.