Learn gem5 #1 (Introduction~Building gem5)

今日からは gem5 を触ってみる。
https://en.wikipedia.org/wiki/Gem5
www.gem5.org

Wikipedia によると、gem5 は m5 (CPUシミュレーションフレームワーク)と GEMS (メモリタイミングシミュレータ) が合体したものであり、複数の実行モードを持つイベント駆動型のシミュレータのようだ。
gem5 - Wikipedia

今回この日記で gem5 を取り上げるモチベーションは、

  1. SystemC と同様に抽象度の高いレベルのシミュレーションができる。
  2. SystemCモジュールをgem5で動かしたり、逆にgem5モジュールをSystemCで動かすこともできる。

https://old.gem5.org/wiki/images/a/a5/Summit2017_systemc.pdf

SystemCは gem5 version 20.0 で正式に取り込まれているようだ。
https://arxiv.org/pdf/2007.03152.pdf

Github上では ext/systemc 以下にSystemC 2.3.1 が丸ごと取り込まれている。
BoostをC++11で置き換えるなどの修正が入っているらしい。
https://github.com/gem5/gem5/tree/stable/ext/systemc

Learn gem5を最初から見ていき、今日はインストールまでを行う。
長いので要所要所を訳していく。

Introduction

https://www.gem5.org/documentation/learning_gem5/introduction/

What is gem5

gem5はモジュール型離散イベント駆動コンピュータシステムシミュレーションプラットフォームである。すなわち、

  1. gem5コンポーネントの再配置・パラメータ化・拡張・置換が必要に応じて容易にできる。
  2. 一連のイベントの時間経過のシミュレーションができる。
  3. 一つもしくは複数のコンピュータシステムを様々な方法でシミュレーションするために使う
  4. 単なるシミュレータにとどまらない。既製のコンポーネントを使用して独自のシミュレーションシステムを構築できるシミュレータプラットフォームである。

gem5は主にC++Pythonで記述されており、ほとんどのコンポーネントBSDライセンスで提供されている。
コンピュータシステムをデバイスとOSを含んだフルシステムモード(FSモード)でシミュレーションしたり、ユーザスペースプログラムをsyscall エミュレーションモード(SEモード)でシステムサービスをシミュレータから提供してシミュレーションすることもできる。
様々なレベルでAlpha, ARM, MIPS, Power, SPARC, RISC-V, x86_64バイナリを2つの単純なCPIモデル、OoOモデル、in orderパイプラインモデルで実行できる。
メモリシステムは柔軟に構築でき、キャッシュ、クロスバー、あるいはさらなる柔軟なメモリシステムモデリングのためにRubyシミュレータも使うことができる。

Building gem5

https://www.gem5.org/documentation/learning_gem5/part1/building/

Requirements for gem5

どうやら pyenv 環境ではうまくインストールできないので、あらかじめ pyenv を削除する(.bashrcから pyenv init などを削除)。
その後、必要そうなものをapt installする。

$ sudo apt install build-essential git m4 scons zlib1g zlib1g-dev libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev python3 python3-dev
$ sudo apt install libboost-all-dev

Getting the code

$ git clone https://github.com/gem5/gem5
$ cd gem5
$ pip3 install -r requirements.txt
$ python3 `which scons` build/X86/gem5.opt -j9
scons: Reading SConscript files ...

You're missing the pre-commit/commit-msg hooks. These hook help to ensure your
code follows gem5's style rules on git commit and your commit messages follow
our commit message requirements. This script will now install these hooks in
your .git/hooks/ directory.
Press enter to continue, or ctrl-c to abort:

エンターを入力するとビルドが始まる。ビルドは途方もなく時間がかかる。。。
いくつかWarningが出ているが、いったん無視する。

scons: done building targets.
*** Summary of Warnings ***
Warning: Header file <capstone/capstone.h> not found.
         This host has no capstone library installed.
Warning: Can not enable KVM, host seems to lack KVM support
Warning: Couldn't find HDF5 C++ libraries. Disabling HDF5 support.

実行ができるかどうかだけ確認する。どうやらちゃんとビルドできているようだ。

$ build/X86/gem5.opt
gem5 Simulator System.  https://www.gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 version 23.1.0.0
gem5 compiled Mar 16 2024 23:40:41
gem5 started Mar 16 2024 23:44:44
gem5 executing on DESKTOP-1L01RQ8, pid 18613
command line: build/X86/gem5.opt

Usage
  gem5.opt [gem5 options] script.py [script options]

gem5 is copyrighted software; use the --copyright option for details.

Options
=======
--help, -h              show this help message and exit
--build-info, -B        Show build information
(snip)