gem5在fs模式运行spec2006

假定已经安装了gem5,并且编译了RISCV的gem5.opt

环境准备

编译m5term,这个是连接终端的

1
2
cd gem5/util/term
make CFLAGS=-O3

编译m5

1
2
cd gem5/util/m5
python3 `which scons` build/RISCV/out/m5

获取linux内核

获取riscv linux内核和img映像,获取方法

  1. 官网资源,使用riscv-disk-img,内核使用bootloader开头的
  2. 使用buildroot一键构建内核和img
  3. busybox构建img,然后自己编译linux内核

修改img文件

添加自己的文件

1
2
3
4
5
sudo mkdir -p /mnt/rootfs
sudo mount -o loop riscv-disk.img /mnt/rootfs
cp path/to/your_program /mnt/rootfs/root
sudo umount /mnt/rootfs

然后我们还要去设置img的/etc/inittab,将 ::respawn:/sbin/getty ...这一行修改为

1
::respawn:-/bin/sh /root/init.sh

也就是开机直接启动/root/init.sh

之后创建/root/init.sh

1
2
3
/root/m5 checkpoint
/root/m5 readfile |sh
/root/m5 exit

这个意思就是创建checkpoint,然后运行从readfile读入的脚本,运行完成退出,其中readfile的文件来自–script参数

生成checkpoint

首次运行需要生成checkpoint

1
2
3
build/RISCV/gem5.opt configs/example/riscv/fs_linux.py \
--kernel=path/to/your_kernel \
--disk-image=path/to/your_img

生成了checkpoint后,我们会在gem5的m5out文件夹下发现cpt前缀,数字后缀的文件夹,该文件夹就是生成的checkpoint,之后我们均从该checkpoint运行benckmark

恢复checkpoint

1
2
3
4
5
6
7
8
9
build/RISCV/gem5.opt \
configs/example/riscv/fs_linux.py \
--kernel=../bootloader-vmlinux-5.10 \
--disk-image=../riscv-disk.img \
--restore-with-cpu=O3CPU \
--bp-type=TAGE_SC_L_64KB \
--caches --l2cache \
--checkpoint-restore=1 \
--script=your.sh

但是在恢复运行时目前遇到这个问题(即使使用O3单独运行也会出现这个问题):

src/cpu/o3/fetch.cc:603: warn: Address 0xffffffe000004400 is outside of physical memory, stopping fetch

在issue找到了,但并没得到有效信息