Skip to main content

Setup

After importing, we can now make sure that the environment is prepared to deal with all the necessary gem5 specifics

Environment variables

I make use of the os.environ to add those environment variables we told you to make in the installation tutorial to the current python script, so we can test that they are installed:

try:
os.environ['GEM_TESTS']
os.environ['GEM_PATH']
os.environ['GEM_CONFIGS']
except e:
fatal("This script requires the GEM_TESTS, GEM_PATH and GEM_CONFIGS environment variables")

Adding the gem5 Configs

We can now, using these environment variables, easily access the gem5 utilities and configurations required to run the rest of the script using sys.path.append(os.environ['GEM_CONFIGS'])

Once we have added the configs directory from gem5, we can import anything in the gem5/configs directory. This includes some utilities for adding command line options to your script, different types of objects and even using other pre-made scripts. I won't cover all of that yet, but you can look forward to the rest of the tutorials where I make increasing use of those utilities.

The Code So Far

# import the m5 (gem5) library created when gem5 is built
import m5
import os
import sys

# import all of the SimObjects
from m5.objects import *
from m5.util import fatal

#### CONSTANTS ####
try:
os.environ['GEM_TESTS']
os.environ['GEM_PATH']
os.environ['GEM_CONFIGS']
except e:
fatal("This script requires the GEM_TESTS, GEM_PATH and GEM_CONFIGS environment variables")

# Add the common scripts to our path
# m5.util.addToPath(os.environ['GEM_CONFIGS'])
sys.path.append(os.environ['GEM_CONFIGS'])

This tutorial is heavily based on learning gem5 with some modifications for the University of Alberta CMPUT 429 course made by Ayrton Chilibeck in Summer 2024.