Development Tools Contributing

From gem5
Revision as of 11:42, 7 October 2012 by Nilayvaish (talk | contribs) (Removed the repeated heading)
Jump to: navigation, search

This section describes the methods available to extend gem5 while preserving the ability to update to new versions. If you intend to make any changes to gem5 we strongly advise you to follow one of the following methods. It will save you a great deal of time in the future and allow you to take advantage of new gem5 versions without the error prone process of manually diffing and patching versions.

There are two recommend ways to add your own functionality to M5 and retain the ability to revision control your own code. The first suggested method relies on the queues feature of Mercurial (the revision control tool used for gem5 development). The second relies on your own source control scheme (you could use mercurial or something else), and instead uses the Extras functionality in the build process to link extra objects into gem5. In some situations a hybrid approach may be the best one, where the features you're attempting to evaluate are handled via the extras functionality, and minor changes to interfaces are done with Mercurial queues.

If you are extending gem5 in a way that could be useful to the community, please consider pushing it back upstream. See Contributing Your Changes.

Using Mercurial Queues

The first method is using Mercurial Queues (MQ). MQ provides management commands inis to provide management commands to create and apply patches to an upstream source tree. When the underlying source tree is updated (see above), you can remove your patches, get the new changes and reapply your patches very quickly. The patches themselves can be an complete mercurial repository that is revision controlled. It's essential to read the above chapter in the Mercurial manual to understand this process, but briefly you would begin by creating a mercurial queues repository. You can then add patches to the mercurial queues repository and automatically update them based on the changes you've made. With this method it is good to segment changes into logical blocks rather than have one large patch for all your changes. When it comes time to update to a new version of M5 you remove all your patches from the repository, update to the latest version and add re-apply all of your patches. Normally this requires minimal effort. For example:

 hg qinit -c
 hg qnew my_new_feature.diff
 echo "// Not so much a new feature as an additional line in the source tree" >> src/sim/main.cc
 hg qrefresh # my_new_feature.diff now contains the the extra line in the source tree

 # Remove the patch by executing
 hg qpop
 # Reapply the patch by executing
 hg qpush
 # Commit the changes to the path
 hg qcommit

 #To update to the latest version of M5
 hg qpop -a
 hg fetch
 hg qpush -a

 # Again PLEASE read the manual

Using EXTRAS

The other method relies on the Extras functionality in the build process. This feature allows you to keep new M5 models in a directory of your choosing and have them compile and link code in with the M5 binary from arbitrary directories. Because the location of this directory is completely independent of the M5 mercurial repository, you can use any revision control system you like, and you can include code that you don't want to release (or that was released under a different license) without worrying about contaminating the M5 repository.

The drawback of the Extras technique is that it only allows the addition of new source code to M5, not the replacement or modification of any existing source code.

The EXTRAS functionality is used to support EIO traces. The trace reader for EIO is licensed under the SimpleScalar license and the code to read these traces is not included in the M5 distribution.

The next examples show how to compile the EIO code. By adding to or modifying the extras path, any other suitable extra could be compiled in. To compile in code using EXTRAS simply execute the following

scons EXTRAS=/path/to/m5_2.0_encumbered build/ALPHA/gem5.opt

In the root of this directory you should have a SConscript that uses the Source() and SimObject() scons functions that are used in the rest of M5 to compile the appropriate sources and add any SimObjects of interest.

Note that EXTRAS is a "sticky" parameter, so after a value is provided to scons once, the value will be reused for future scons invocations targeting the same build directory (build/ALPHA in this case) as long as it is not overridden. Thus you only need to specify EXTRAS the first time you build a particular configuration or if you want to override a previously specified value. For more information on sticky scons options, see the SCons build system page.

To run a regression with EXTRAS use a command line similar to the following:

./util/regress --scons-opts="EXTRAS=/tmp/m5_2.0b4_encumbered" -j 2 quick

Contributing Your Changes

If you make a changes to gem5 that others would find useful, please consider sharing that code with the community. First, please make sure that your patch applies to the latest development repository. After you're sure that it works please post it to our code review system. To do this create an account on our code review website. You can then either upload a diff directly to the website or use the hg post-review extension to send the patch directly to the website from your mercurial repository.

Mercurial repo browser

The source code of gem5 is available to browse online here.