The preparation contains several parts.
This assignment requires Linux environment on your own computer. There are several ways to do that. We recommend the first and second way.
Ubuntu 9.04 is working out-of-the-box.
Fedora 10 is working out-of-the-box.
Ubuntu 9.10 may need small twists on the gcc problem. See "Known Issues" page for more detail.
Fedora 11 may need more twists on the gcc problem. See "Known Issues" page for more detail.
Other Linux distributions may or may not work.
Note: If you are doing a fresh installation of Linux, 32-bit Ubuntu 9.04 and Fedora 10 are highly recommended.
Compiling M5" wiki page.
The commands below will install these packages for rpm-based and deb-based package installers.
The names of these packages may differ from one Linux distribution to the other.
Sometimes the package for 64-bit version may differ from 32-bit version.
If you are not using 32-bit Fedora or Ubuntu, please search for the correct names of these packages.
For Fedora, issue the following 'yum' command (su is needed to get superuser privileges; so you will be asked to enter the superuser password):
For Ubuntu, issue the 'apt-get' command (also here we need 'sudo' to get superuser privileges):
You can check which version of gcc you are using by running this command:
If your gcc version is 4.4.x, a workaround is to install an older version of gcc and g++. An alternative method is to patch the source code of m5sim 2.0 beta 6. You can check the detail in the known issues page.
You need to solve the gcc version problem before compiling m5sim.
After getting the prerequisite packages and solving the gcc version program, if any, we can go to the downloaded directory. Later we will use scons to compile m5.
First, add a few lines to file "
Change above lines into:
There are 2 version of the simulator, called SE, syscall emulation, and FS, full system mode.
Compile both simulators: Syscall Emulation (SE) mode and Full System (FS) mode for ALPHA ISA, using scons, as shown below:
If you encounter errors, you can take a look at the known issues.
There are two simulation modes in m5sim, the Syscall Emulation (SE) mode and the Full System (FS) mode. The SE mode does not simulate operating systems. It emulates system calls on the host machine. The FS mode simulates the whole Linux system. To test whether our installation is working. We can first test the SE mode. Because the FS mode requires additional efforts, we will test the FS mode in the next section. To test the FS mode, you can issue this command below. It executes m5 with 'se.py' as input. This latter file contains a configuration of the architecture and specifies the input code file. This configuration is written in Python. The simulator calls Python to translate this file and generating the configuration file for m5.
You will see the "Hello World!".
Get system disk imageSince the FS mode simulates a Linux OS, we need to have a pre-compiled (for the Alpha, i.e. the simulated architecture) Linux for m5sim. We can fetch a pre-compiled system disk image version 2.0 beta 3 from the m5sim website:
In order to locate the disk image, change line 53 of the file "
Change it into:
In the first terminal, issue the command:
The first terminal will hang at some point. Please do NOT kill the process. It is only waiting for the second terminal.
While the first terminal is hanging. In the second terminal, issue the command:
You will see m5sim booting the Linux in the second terminal.
The figure below shows the first terminal (left) and the second terminal (right). You can click on the figure to enlarge.
The left terminal is a normal host terminal, displaying the information of m5sim running on the host. The right terminal is used as the terminal of the simulated Linux system on m5sim. In the right terminal, you can type commands to interact with it.
You can run (in the right terminal) a pre-compiled benchmark program by typing this command in m5term:
This program will display its result like this,
To quit the FS mode, you can issue the command from the right terminal:
Since the host machine is i386, while the target machine simulated by m5sim is Alpha, we need a cross-compiler that can generate Alpha binary on a i386 host.
If you use the default image "
We can test the crosscompiler with a simple program "hello.c". You can create the "hello.c" in any directory of the host machine.
We will first run it in SE mode. Since SE emulates linux system calls, we need to crosscompile it with the "
Now we can run this program in Syscall Emulation (SE) Mode.
It is handy to reuse the script "
Change it into:
Issue the following command to run the new hello in SE mode.
Then you can see the "hello crosscompiler!".
To run our cross-compiled programs in the FS mode, we need to add the binary of the program into the disk image. So that when the m5sim boots the Linux, the binary of the program can be found in the file systems of the simulated Linux OS.
Make a directory to mount the disk image.
Mount the disk image to the above directory.
Then you can add the crosscompiled hello binary into the disk image. Assume you add it to the benchmark directory.
You have to umount the disk image before booting it in the FS mode.
After umount, we can use m5term in FS mode to run the hello binary. We need to launch the FS mode and m5term again, as mentioned in the "Use m5term in FS mode" section. In the m5term, issue the command:
You can see the "hello crosscompiler!".
On the other hand, we only have tool chains targeting Linux, not tru64.
Therefore, in the SE mode, neither Linux pthread nor tru64 pthread can "compile-and-run".
The FS mode can run Linux pthread.
We have the tool chain targeting Linux.
Therefore, in the FS mode, Linux pthread can "compile-and-run".
Unless specifically indicated differently, we assume FS mode and Linux pthread is used in the remainder of this lab.
You can refer to a short tutorial on pthread to get started with your own pthread program.
We can compile it with the "
Adding files to disk image" section. Launch the FS mode and m5term, as mentioned in the "Use m5term in FS mode" section. Run the helloPthread binary from m5term, you will see the following output.
Assume we have a helloPthread binary located under the directory of "
Insert the following line to the line 104 of the file "
We can get the statistics of the helloPthread program by issue the command:
This command runs the "
The benchmark script will terminate m5sim after the benchmark binary is executed. The m5sim will display this message on its exit:
The statistics obtained in this way excludes the OS launch overhead. We will take a look at the statistics in the "Example" page.