What is gem5?
gem5 is a modular discrete event driven computer system simulator platform. That means that:
- gem5's components can be rearranged, parameterized, extended or replaced easily to suite your needs.
- It simulates the passing of time as a series of discrete events.
- It's intended use is to simulate one or more computer systems in various ways.
- It's more than just a simulator, it's a simulator platform that lets you use as many of its premade components as you want to build up your own simulation system.
gem5 is written primarily in C++ and python and most components are provided under a BSD style license. It can simulate a complete system with devices and an operating system in full system mode (FS mode), or user space only programs where system services are provided directly by the simulator in syscall emulation mode (SE mode). There are varying levels of support for executing Alpha, ARM, MIPS, Power, SPARC, and 64 bit x86 binaries on CPU models including two simple single CPI models, an out of order model, and an in order pipelined model. A memory system can be flexibly built out of caches and interconnects. Recently the Ruby simulator has been integrated with gem5 to provide even better, more flexible memory system modeling.
There are many components and features not mentioned here, but from just this partial list it should be obvious that M5 is a sophisticated and capable simulation platform. Even with all gem5 can do today, active development continues through the support of individuals and some companies, and new features are added and existing features improved on a regular basis. For the most up to date information you can check out the project's website at www.gem5.org.
How am I expected to use gem5?
gem5 is a framework to do computer architecture research. It has many features, but if you're trying to do something new and novel in the field it probably won't be able to evaluate your idea out-of-the-box. This is expected, because if it did have all the functionality required, that probably means that someone already evaluated a similar idea and has probably published about it.
To get the most out of gem5, you're going to have to get your hands dirty and add functionality. We hope we've made gem5 modular enough that you can do this with only the understanding of the portion of the simulator you're editing, but nothing is perfect.
Hopefully, you'll find gem easy to use, but if you run into gaps in this documentation please feel free to ask questions on the mailing lists after reading Reporting Problems. When you do solve your problem, please update the documentation as appropriate so that the next user can benefit from your experience. Additionally, please consider contributing your code back to the gem5 development repository. Only with contributions from the community can the simulator continue to grow.
Pointer to gem5 Capabilities/Recipes
Getting a copy
M5's source code is managed using the mercurial revision control system. There are several repositories you may be interested in:
- m5 – The main repository is where active development takes place.
- m5-stable – A repository which lags behind “m5” repository but has basically the same contents. It’s usually better to use “m5” instead of “m5-stable”
- encumbered – A repository for extensions to M5 that are under a different, more restrictive license. Currently this only includes support for SimpleScalar's EIO trace format.
- linux-patches – A repository for patches to the linux kernel that modify it so it can be simulated more efficiently. These patches are optional, but it's a good idea to use them if possible to cut down on simulation run time.
To check out a copy, first, make sure you have mercurial installed on your system and that you can run the hg command. Then use hg clone to create your own local copy using the URL http://repo.m5sim.org/XXX where XXX is replaced by the name of the repository your interested in. For example, to check out the main repository, you'd use the command:
hg clone http://repo.m5sim.org/m5
You can find out more about mercurial and its commands using its built in help by running:
or by visiting any of the following websites:
- hginit provides a good introduction to the basic Mercurial concept
- Mercurial Guide also provides a good basic introduction
- HGBook is the definitive guide to Mercurial
M5 uses the scons build system which is based on python. To build the simulator binary, run scons from the top of the source directory with a target of the form build/<config>/<binary> where <config> is replaced with one of the predefined set of build parameters and <binary> is replaced with one of the possible m5 binary names. The predefined set of parameters determine build wide configuration settings that affect the behavior, composition, and capabilities of the binary being built. These include whether the simulator will run in FS or SE mode, if Ruby support is included, which ISA will be supported, which CPU models to build, and what coherence protocol Ruby should use. Examples are ARM_FS, X86_SE, and ALPHA_SE_MOESI_CMP_token. All of the available options can be found in the build_opts directory, and it should be fairly easy to see what each is for. We'll talk about the build system in more detail later. Valid binary names are m5.debug, m5.opt, m5.fast, and m5.prof. These binaries all have different properties suggested by their extension. m5.debug has optimization turned off to make debugging easier in tools like gdb, m5.opt has optimizations turned on but debug output and asserts left in, m5.fast removes those debugging tools, and m5.prof is built to use with gprof. Normally you'll want to use m5.opt. To build the simulator in syscall emulation mode with Alpha support, optimizations turned on, and debugging left in, you would run:
In your source tree, you'd then find a new build/ALPHA_FS/ directory with the requested m5.opt in it. For the rest of this chapter we'll assume this is the binary you're using.
Now that you've built M5, it's time to try running it. An M5 command line is composed of four parts, the binary itself, options for M5, a configuration script to run, and then finally options for the configuration script. Several example configuration scripts are provided in the “configs/example” directory and are generally pretty powerful. You are encouraged to make your own scripts, but these are a good starting point. The example script we'll use in SE mode is called se.py and sets up a basic SE mode simulation for us. We'll tell it to run the hello world binary provided in the M5 source tree.
build/ALPHA_SE/m5.opt configs/example/se.py -c tests/test-progs/hello/bin/alpha/linux/hello
This builds up a simulated system, tells it to run the binary found at the location specified, and kicks off the simulation. As the binary runs, it's output is sent to the console by default and looks like this:
M5 Simulator System Copyright (c) 2001-2008 The Regents of The University of Michigan All Rights Reserved M5 compiled Feb 12 2011 20:43:55 M5 revision e00ef55a2c49 7933 default tip M5 started Feb 12 2011 20:45:47 M5 executing on fajita command line: build/ALPHA_SE/m5.opt configs/example/se.py -c tests/test-progs/hello/bin/alpha/linux/hello Global frequency set at 1000000000000 ticks per second 0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000 **** REAL SIMULATION **** info: Entering event queue @ 0. Starting simulation... info: Increasing stack size by one page. Hello world! hack: be nice to actually delete the event here Exiting @ tick 3240000 because target called exit()
You can see a lot of output from the simulator itself, but the line “Hello world!” came from the simulated program. In this example we didn't provide any options to M5 itself. If we had, they would have gone on the command line between m5.opt and se.py. If you'd like to see what command line options are supported, you can pass the --help option to either M5 or the configuration script. The two groups of options are different, so make sure you keep track of whether they go before or after the configuration script.
-- Either this section or another section needs to have a description about running FS mode and m5term..... --Saidi 22:39, 7 March 2011 (UTC)
Asking for help
gem5 has two main mailing lists where you can ask for help or advice. m5-dev is for developers who are working on the main version of M5. This is the version that's distributed from the website and most likely what you'll base your own work off of. m5-users is a larger mailing list and is for people working on their own projects which are not, at least initially, going to be distributed as part of the official version of M5. Most of the time m5-users is the right mailing list to use. Most of the people on m5-dev are also on m5-users including all the main developers, and in addition many other members of the M5 community will see your post. That helps you because they might be able to answer your question, and it also helps them because they'll be able to see the answers people send you. To find more information about the mailing lists, to sign up, or to look through archived posts visit Mailing Lists.
Cross-product status matrix
gem5 combines several different ISAs, system modes (SE or FS), CPU models and memory models under a single infrastructure. Every combination of of these may not be fully tested or completely work. The Status Matrix describes the current status of these combinations. Please send an e-mail to the mailing list if a supported combination no longer works, or if you find that a combination works that we're unsure of please update the page.