Skip to content

Logging my attempts for running a gem5 full system simulation

Notifications You must be signed in to change notification settings

fshahinfar1/gem5-journey

Repository files navigation

Gem5 journey

Building gem5

  1. Follow the guide in the website.
scons build/ARM/gem5.opt -j4
  1. If protobuf_min_version error then edit SConstruct in the root of gem5 directory. At line 390, append to the list '-Wno-error=undef'.

Running a full system simulation

Run the default image and kernel

  1. Download the provided kernel and image from link.

  2. Extract the download archive and add a path to the directory. (export M5_PATH or edit the "<gem5 dir>/configs/common/SysPaths.py" -> line 53, append path to the list.)

  3. Create a dummy image named linux-bigswap2.img in the disks folder of the $M5_PATH.

dd if=/dev/zero of=./binaries/linux-bigswap2.img count=1 bs=16k

Check this link.

  1. Use the default fs.py config for running a simulation. Run gem5 simulator:
./build/X86/gem.opt ./configs/examples/fs.py --disk-image=x86Linux --kernel=x86_64-vmlinux-2.6.22.9

Also please note that with correct kernel config it is possible to use the base old image with the new kernel.

  1. Then connect to the simulator using telnet.
telnet 127.0.0.1 <port>

Run a custom kernel and image

These steps has been taken for running a full system simulation.

  1. Read the blog post here.

  2. Download kernel version 4.8.13

  3. Download config file linked to in the post.

  4. Build the kernel with that config file.

cp config ./kernel directory/.config
cd ./kernel directory/
make oldconfig
make -j9
  1. Copy vmlinux file (built kernel) to $M5_PATH/binaries

  2. Run simulation.

./build/X86/gem5.opt ./configs/examples/fs.py --disk-image=test.img --kernel=x86_64-vmlinux-4.8.13
  1. After some time, just after running init process of kerenl, the simulation ends. There is an error with TLB I guess. It might be because of system configuration. Check error logs at here.

  2. Read post here for creating a system configuration. After following the tutorial I get the following error:

AttributeError: object 'MySystem' has no attribute 'mmubus'
  (C++ object is not yet constructed, so wrapped C++ methods are unavailable.)
  1. The issue was solved there was some typing errors in the toturials code. (I opened an issue for them). System config is available here.
./build/X86/gem5.opt ./configs/my_config/run.py
  1. Follow this link to create an image file. Ubuntu Server version 18.04.2 was used. I have Tried to run simulation with ubuntu image and kernel 4.8.13 on my_config system but it was stoped by kernel panic. Logs for the error is available here. (Check create disk image section)

  2. Check this post for solving the issue. And this post.

  3. In my_config/simple_full_system.py, boot_options, change root=/dev/hda1 to root=/dev/hda2. A new kernel panic message. check here.

  4. Stuck, but this repository looks promising.

  5. This repository has some tips an tricks.

Useful tips

Create a disk image

This part is obtained from this post writen by Jason Lowe-Power.

Dependencies: qemu

  1. Create an empty disk image
qemu-img create ubuntu-test.img 8G
  1. Boot the installation image and install it on the disk image.
qemu-system-x86_64 -hda \<path to ubuntu-test.img\> -cdrom \<path to installation image\> -m 1024 -enable-kvm -boot d
  1. Boot from disk and add data, programs, ...
qemu-system-x86_64 -hda \<path to ubuntu-test.img\> -m 1024 -enable-kvm
  1. Setup init script:
  • build m5
cd util/m5
make -f Makefile.x86
  • mount image file system (check out mounting image file system)
  • copy m5 binary to /sbin
  • create a link from /sbin/gem5 to /sbin/m5
ln -s /sbin/m5 /sbin/gem5
  • create a file at /lib/systemd/system/gem5.service (file content is here)
  • create a file at /sbin/initgem5 (file content is here)
  • boot the image and enable the gem5.service
systemctl enable gem5.service

Mounting image file system

For copying files from host to guest file-system, you can mount the image. (Read this post.)

  1. First find the partition's offset with command below
fdisk -lu ubuntu-test.img
  1. Mount the partition (4096 start of file system offset, 512 block size)
sudo mount -o loop,offset=$[4096*512] ubuntu-test.img mnt/
  1. Copy files and ...

Config Ubuntu 18.04 for auto login

In the configuration the gem5 is connected to ttyS0.

Check the post here.

  1. Use command below
systemctl edit serial-getty@ttyS0
  1. Add lines below
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --keep-baud 115200,38400,9600 %I $TERM
  1. Check edited config
systemctl cat serial-getty@ttyS0 | grep Exec

How does gem5 pass scripts to guest

  1. Using system.readfile attribute defined at System.py a pointer to a script can be send to guest.

  2. guest can use m5 binary for accessing the file using command: m5 readfile

For automating the process, we are going to create a systemd service.

this part has been explained above, when creating a new ubuntu image

  1. Place this file in /lib/systemd/system/gem5.service
  2. Place this script in /sbin/gem5init
  3. Run command systemctl enable gem5.
  • Note: take a look at here.

  • Note: Implementation of this part of gem5 is at <gem5 root>/util/m5/m5.c.

  • Note: Check here for understanding about gem5.service.

About

Logging my attempts for running a gem5 full system simulation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published