M5ops

This page explains the special opcodes that can be used in M5 to do checkpoints etc. The m5 utility program (on our disk image and in util/m5/*) provides some of this functionality on the command line. In many cases it is best to insert the operation directly in the source code of your application of interest. You should be able to link with the appropriate m5op_ARCH.o file and the m5op.h header file has prototypes for all the functions.

Building M5

In order to build m5 for your target ISA, run the following command in util/m5/ directory.

scons build/{TARGET_ISA}/out/m5

The list of target ISAs is shown below.

Note if you are using a x86 system for other ISAs you need to have the cross-compiler installed. The name of the cross-compiler is shown inside the parentheses in the list above.

The m5 Utility (FS mode)

he m5 utility (see util/m5/) can be used in FS mode to issue special instructions to trigger simulation specific functionality. It currently offers the following options:

Other M5 ops

These are other M5 ops that aren’t useful in command line form.

Using gem5 ops in Java code

These ops can also be used in Java code. These ops allow gem5 ops to be called from within java programs like the following:

import jni.gem5Op;

public  class HelloWorld {

   public static void main(String[] args) {
       gem5Op gem5 = new gem5Op();
       System.out.println("Rpns0:" + gem5.rpns());
       System.out.println("Rpns1:" + gem5.rpns());
   }

   static {
       System.loadLibrary("gem5OpJni");
   }
}

When building you need to make sure classpath include gem5OpJni.jar:

javac -classpath $CLASSPATH:/path/to/gem5OpJni.jar HelloWorld.java

and when running you need to make sure both the java and library path are set:

java -classpath $CLASSPATH:/path/to/gem5OpJni.jar -Djava.library.path=/path/to/libgem5OpJni.so HelloWorld

Using gem5 ops with Fortran code

gem5’s special opcodes (psuedo instructions) can be used with Fortran programs. In the Fortran code, one can add calls to C functions that invoke the special opcode. While creating the final binary, compile the object files for the Fortran program and the C program (for opcodes) together. I found the documentation provided here useful. Read the section -- Compiling a mixed C-Fortran program.

Linking M5 to your code

In order to link m5 to your code you have to add gem5/include/gem/asm/generic/m5ops.h and gem5/util/m5/src/m5_mmap.h to your include path and add gem5/util/m5/src/m5_mmap.c and gem5/util/m5/src/{TARGET_ISA}/m5op.S to your source path and add m5op_{TARGET_ISA} and m5_mmap as objects to your object list. For an example on how to do this with PARSEC benchmark look here