Frequently Asked Questions

From gem5
Revision as of 03:35, 17 August 2006 by Ktlim (talk | contribs) (How do I use the sampler?)
Jump to: navigation, search

Contents

Device Related

How can I see the packets on the ethernet link?
  • By creating a Etherdump object, setting it's file parameter, and setting the dump parameter on the EtherLink to it. This is easily accomplished with our fs.py example configuration by adding the command line option --etherdump=<filename>. The resulting file will be named <file> and be in a standard pcap format.

OS/Linux Related

How do I create a disk image?
  • You can use the mkblankimage.sh script that is provided in our distribution of linux-dist to create a blank image of arbitrary size.
How do I add files to a disk image?
  • Using either sudo or the root account run /bin/mount -o loop,offset=32256 /z/foo.img /mount/point. You can then copy the desired files to the image. Remember to unmount it before running the simulator with /bin/umount /mount/point or you may get unexpected results.
How do I compile a kernel to run on M5 in full-system mode?
  • You need either a cross-compiler to compile Alpha binaries, or you can compile directly on an Alpha you may have. Since most people don't have Alphas, using a cross-compiler is the most common option. Then, in the top level of the Linux tree you want to build, just type 'make ARCH=alpha CROSS_COMPILE=/path/to/your/xcompiler/bin/alpha-unknown-linux-gnu-'. This tells the Makefile that you want to build an alpha binary, and where to find the cross compiler to do so.
How do I build a cross compiler?
  • Download cross-tool here. It is a script to simplify the creation of cross-compilers. There is a good howto on the website to get you started. You'll want to build cross-compiler for the Alpha ISA. Crosstool has also been found to work for MIPS (gcc 3.4.4 / glibc 2.3.5).
I can't compile the patched 2.6.13 kernel, what do I do?
  • Try using crosstool-0.42. Download it from http://kegel.com/crosstool, untar it, and check out the demo-alpha.sh script. This is what dictates what exact toolchain you'll build.
    • Read the Howto/readme on the kegel website - it's helpful to get an idea of what the scripts are doing.
    • Modify this demo-alpha.sh so that the toolchain file is gcc-3.4.3-glibc-2.3.5.dat.
    • Modify the gcc-3.4.3-glibc-2.3.5.dat so that the linux version it points to reflects the Linux headers you want to use in your toolchain. Currently in M5 we are using linux-2.6.13, so you should set it accordingly.
    • in the crosstool-0.42 directory, type "sh demo-alpha.sh". This should take at least an hour to build.
    • you should have a crosstool in /opt/crosstool/gcc-3.4.3-gcc-2.3.5/
    • to compile the patched linux 2.6.13 kernel, from the top directory in the linux tree, type: make ARCH=alpha CROSS_COMPILE=/opt/crosstool/gcc-3.4.3-gcc-2.3.5/alpha-unknown-linux-gnu/bin/alpha-unknown-linux-gnu-
      • the key is to have the CROSS_COMPILE parameter point to the bin where all the crosstools are like gcc, ar, ranlib, etc. and have the appropriate prefix.
    • voila, you should have a vmlinux that works with m5.
  • NOTE: thus far we have been unable to build a gcc-4.0.2 toolchain that builds a vmlinux that works...it will build, but then it won't run within our simulation, so if you are tempted to update gcc to 4.0.2 enjoy, and let us know what you did...but if you are looking for a toolchain that works off the bat, stick with gcc-3.4.3.
  • NOTE 2: Attempts to build a working toolchain with a native gcc 4.1 have reportedly failed. Using gcc 3.4.4 on your host machine to build the toolchain is known to work.
Can I use MIPS SDE Lite to cross-compile for M5?
  • The MIPS SDE Lite package is a very good tool but

unfortunately it will not work if you would like to cross-compile a MIPS/Linux binary and run it on M5. The MIPS SDE package contains some SDE-specific startup routines and glibc calls that M5 will not be able to support. The cross-compiler solution we found to work is crosstool. For MIPS, gcc 3.4.4 and glibc 2.3.5 seems to work.

Running Related

I compiled an executable to run in syscall emulation mode but it doesn't work. M5 seems to initialize OK, but the CPU never fetches any instructions. What's wrong?
  • Did you statically link your executable? M5 does not support dynamic linking (shared libraries) in syscall emulation mode. You must recompile the executable and have it statically linked. With gcc, just add the "-static" flag to the command line.
How many CPUs can M5 run?
  • There is no strict limit however the Alpha platform we support (Tsunami) only has support for 4 processors. We made some additions to the platform both in the simulator and in Linux to support up to 64 processors. However simulating 64 processors will be quite slow, and the Linux scheduler doesn't seem particularly good at scheduling large amounts of processors.
How do I see what options I can set?
  • Using the '-h' flag will show what options M5 can take in general. Running m5.debug foo.py -h (or any m5 binary variant) will list all options that are available based on M5's internal options and the options defined in the .py file.
How do I run multiprogram workloads on M5?
How do I use the sampler?

The sampler from the previous version of M5 has been replaced with functionality via Python. In your script you can direct the simulator to switch between two sets of CPUs. To do this, in your script setup a list of tuples of (oldCPU, newCPU). If there are multiple CPUs you wish to switch simultaneously, they can all be added to that list. For example: run_cpu1 = SimpleCPU() switch_cpu1 = DetailedCPU() run_cpu2 = SimpleCPU() switch_cpu2 = FooCPU() switch_cpu_list = [(run_cpu1,switch_cpu1),(run_cpu2,switch_cpu2)]

After this list is setup, your script can direct M5 to switch the CPUs at the appropriate cycle. This is achieved by calling switchCpus(cpus_list). For example, assuming the code above, and a system that is setup running run_cpu1 and run_cpu2 initially: m5.simulate(500) # simulate for 500 cycles m5.switchCpus(switch_cpu_list) m5.simulate(500) # simulate another 500 cycles after switching

Note that M5 may have to simulate for a few cycles prior to switching CPUs due to any outstanding state that may be present in the CPUs being switched out.

Debugging and Error Related

When running my program I get an error "Error: syscall <syscall name here> unimplemented."
  • That means that one of the libraries that you are linking with uses a syscall that is not emulated. You can do a man on the syscall name to see what the syscall is supposed to do and then try to implement at least whatever functionality your application needs. Or you can try the quick & dirty approach, which is to change the function pointer for syscall in arch/<arch>/<os>/<os>.cc from unimplementedFunc to ignoreFunc, which will make it print a warning and keep going rather than terminate with an error. No guarantees that your program won't crash because of this though.
How do I access reference counted pointers in GDB?
  • Objects such as DynInsts are reference counted, making it slightly harder to obtain the data inside. In gdb you must access them through the pointer that is stored in the ref counted pointer, which is called data. Thus given a ref counted pointer ptr, in gdb you would say (gdb) ptr->data to get the pointer to the actual object.
I get an error "undefined reference to `void foo()'" when the compiler is doing the final linking.
  • This is due to having a function that is declared but never defined. Either you forgot to define it, or are not compiling in the file that defines it. In the case of templated code, you may be including the wrong file or you may not have manually instantiated a templated class that needs to be manually instantiated.
I've created a new SimObject but it doesn't seem to be recognized when I run M5.
  • You'll need to put the python object file in src/python/m5/objects/, and edit src/python/m5/objects/__init__.py to include your object.
What does this error mean warn: setsysinfo: ignoring ieee_set_fp_control() arg 0x11ff96f98?
  • That and similar errors are warning you that the system call that sets IEEE FP control register is being ignored. This register primarily enables/disables different kinds of FP traps (underflow, overflow, inexact, etc.). Since M5 doesn't implement those traps anyway there's no point in implementing the syscall. It's pretty unlikely your application relies on them, so as long as everything else seems to work you can ignore the warning.

Extending M5 Related

How would I define a new CPU Model for M5?

The easiest way is to derive a new C++ class of your CPU Model from M5 CPU Models that are already defined and the easiest model to start with is probably the 'AtomicSimpleCPU' located in the 'm5/cpu/simple' directory.


After you create a separate directory for your code (e.g. 'm5/cpu/my_cpu'), there are a couple files that need to be updated:

  • m5/SConstruct: Add the name of your CPU model to the 'ALL_CPU_MODELS' list
  • m5/cpu/SConscript: Add your CPU model and the relevant files that need to be built in here
  • m5/cpu/static_inst.hh: Put a forward class declaration of your model in here
  • m5/cpu/cpu_models.py: Add in CPU Model-specific information for the ISA Parser ( check out the ISA Description Language documentation page for more details)
  • m5/python/objects/my_cpu.py: Create a python file (e.g. MyCPU.py) your model. A good example to follow is the file 'AlphaO3CPU.py'.
  • m5/python/objects/__init__.py: Add the base name of your python file into the 'file_bases' list.


Now build your model:

  • scons build/ALPHA_SE/m5.debug CPU_MODELS=MY_CPU


Create and edit configuration files for your model:

  • m5/configs/test/MyCPUConfig.py: Define a configuration class w/corresponding parameters for your model. Look to 'FullO3Config.py' in the same directory for an example of how to do this.
  • m5/configs/test/test.py: Import your model's configuration at the top of the file (i.e. 'import MyCPUConfig') and add in a parser option for your CPU model (e.g. '--my_cpu').


Test your model:

  • build/ALPHA_SE/m5.debug configs/test/test.py --my_cpu
How would I define a new ISA for M5?

Miscellaneous

Where are the classes for each ISA instruction? Where are the execute() methods for the StaticInst class?
  • Both the classes and the execute() methods are generated through Python upon building any version of M5. For example, After building ALPHA_SE, they will be located in the build/ALPHA_SE/arch/alpha/ folder. The key files are decoder.hh, decoder.cc (which describe the ISA instructions), and *_exec.cc (which describe the execute() methods). The definitions for both exist in the .isa files found in src/arch/*/isa/, which are processed by src/arch/isa_parser.py to generate the previously mentioned .hh/.cc files.
Is fast-forwarding supported in SMT mode?
  • It is not currently supported. The SimpleCPU doesn't support SMT, so it doesn't support fast-forwarding in SMT mode. However it should be feasible given some hacking on the SimpleCPU or the Sampler.
I've created a new file, how do I get SCons to compile it.
  • Add the file to the SConscript in the current directory or if it doesn't exist the SConscript in closest parent directory.
I've got a new object compiled but I can't use it.
  • You need to both have the building macros in your C++ file (Take a look at any of the other objects for examples) and a corresponding python file (take a look at src/python/m5/objects/* for examples).
How do I use a normal variable in a statistic formula?
  • This is not supported. Just create a Scalar<> statistic that does the same thing as your normal variable and use that in the formula instead.
What are all these *_impl.hh files?
  • There is a lot of templated code used within M5, and these *_impl.hh are used to make it a little easier to organize things. Normally template functions must be entirely included in the header file in order to not require the programmer to manually instantiate the copies of the template functions. However, when you have an entire class that's templated, the header files quickly become bloated and too big, except for small helper classes. Thus we put the declarations in the header file as normal, the definitions in the *_impl.hh file, and the manual instantiations in the *.cc file. This makes it easier to sort out the instantiations from the definitions. Also if there are only a few templated functions inside a non-templated class, it may be possible to include the functions in the *_impl.hh file and not have to manually instantiate the functions. You just need to include the *_impl.hh file in any .cc files that use the templated function. See mem/packet{.hh|_impl.hh|.cc} for an example.
What if SCons complains that it can't find a file I just deleted?
  • Delete the scons.dblite file in the m5 directory.
Which config files are used for syscall emulation? Full system mode?