
RISC-V BOOMプロセッサの試行をしていると、パイプライントレースの出力方法としてgem5というものを利用していた。

gem5というのは何なんだろう?調査してみる。
- The gem5 Simulator: A modular platform for computer-system architecture research
The gem5 simulator is a modular platform for computer-system architecture research, encompassing system-level architecture as well as processor microarchitecture.
パイプラインプロセッサの性能を研究するためのシミュレータで、サイクルカウントを解析するためのツールも内蔵されているツールのことだ。 RISC-VのBOOMは、このgem5のパイプラインアナライザのフォーマットに対応したトレースファイルを出力する。
出自の論文では、いくつかの企業と大学が共通で開発したパイプライントレースのような感じもする。
BOOMのエミュレーションでパイプライントレースを出力する
githubの解説にあるとおり、O3PIPEVIEW_PRINTFという変数をtrueに設定する。
val O3PIPEVIEW_PRINTF = true // dump trace for O3PipeView from gem5
これで一応、全体をビルドおよびシミュレーションするために再度./build.shを実行した。その結果、rocket-chip/emulator/output/にトレースファイルが格納された。
less rocket-chip/emulator/output/qsort.riscv.out using random seed 1477147949 0; O3PipeView:fetch: 0:0x0b47f74a04:0: 0:DASM(00000000) 0; O3PipeView:decode: 2000 0; O3PipeView:rename: 0 0; O3PipeView:dispatch: 0 1; O3PipeView:fetch: 25000:0x0000000000:0: 1:DASM(00000000) 2; O3PipeView:fetch: 25000:0x0000000004:0: 2:DASM(00000000) 1; O3PipeView:decode: 27000 1; O3PipeView:rename: 0 1; O3PipeView:dispatch: 0 2; O3PipeView:decode: 27000 2; O3PipeView:rename: 0 2; O3PipeView:dispatch: 0 3; O3PipeView:fetch: 50000:0x0000000800:0: 3:DASM(03c0006f) 3; O3PipeView:decode: 52000 3; O3PipeView:rename: 0
いくつか試行をしていて分かったのだが、最初に出てくるusing random seed ...の一文は削除する必要がある。stderrなどの情報も全てトレースファイルに追加された影響かな。
0; O3PipeView:fetch: 0:0x0b47f74a04:0: 0:DASM(00000000)
0; O3PipeView:decode: 2000
0; O3PipeView:rename: 0
0; O3PipeView:dispatch: 0
1; O3PipeView:fetch: 25000:0x0000000000:0: 1:DASM(00000000)
2; O3PipeView:fetch: 25000:0x0000000004:0: 2:DASM(00000000)
1; O3PipeView:decode: 27000
1; O3PipeView:rename: 0
1; O3PipeView:dispatch: 0
2; O3PipeView:decode: 27000
2; O3PipeView:rename: 0
2; O3PipeView:dispatch: 0
3; O3PipeView:fetch: 50000:0x0000000800:0: 3:DASM(03c0006f)
3; O3PipeView:decode: 52000
3; O3PipeView:rename: 0
これを以下の手順でトレースファイルに変換する。gem5は上記のサイトからダウンロードしておくこと。
./rocket-chip/boom/util/pipeview-helper.py -f rocket-chip/emulator/output/dhrystone.riscv.out > cleaned_trace.out ./gem5/util/o3-pipeview.py -o pipeview.out --color cleaned_trace.out
lessで参照してみると、パイプライントレースが出力されているのが分かる。これはlessの色付きのオプションが必要だ。
// f = fetch, d = decode, n = rename, p = dispatch, i = issue, c = complete, r = retire
timeline tick pc.upc disasm seq_num
[==d=============================================================================]-( 0) 0x8e146bd1f4.0 -----DASM(00000000) [ 0]
[=========================f=d====================================================]-( 0) 0x0000000000.0 -----DASM(00000000) [ 1]
[=========================f=d====================================================]-( 0) 0x0000000004.0 -----DASM(00000000) [ 2]
[..................................................f.di...cr.....................]-( 0) 0x0000000800.0 DASM(03c0006f) [ 3]
[....................................................f......di...cr..............]-( 0) 0x000000083c.0 DASM(7b241073) [ 4]
[=====================================================f==========================]-( 0) 0x0000000840.0 -----DASM(00000000) [ 5]
[=====================================================f==========================]-( 0) 0x0000000844.0 -----DASM(00000000) [ 6]
[=======================================================f========================]-( 0) 0x0000000840.0 -----DASM(00000000) [ 7]
[=======================================================f========================]-( 0) 0x0000000844.0 -----DASM(00000000) [ 8]
[=========================================================f======================]-( 0) 0x0000000840.0 -----DASM(00000000) [ 9]
[=========================================================f======================]-( 0) 0x0000000844.0 -----DASM(00000000) [ 10]
[===========================================================f====================]-( 0) 0x0000000840.0 -----DASM(00000000) [ 11]
[===========================================================f====================]-( 0) 0x0000000844.0 -----DASM(00000000) [ 12]
[.........f.di...cr..............................................................]-( 80000) 0x0000000840.0 DASM(7b002473) [ 13]
[=========f======================================================================]-( 80000) 0x0000000844.0 -----DASM(1c047413) [ 14]
[==========f=====================================================================]-( 80000) 0x0000000848.0 -----DASM(f4040413) [ 15]
[==========f=====================================================================]-( 80000) 0x000000084c.0 -----DASM(00041663) [ 16]
[===========f====================================================================]-( 80000) 0x0000000850.0 -----DASM(42903c23) [ 17]
[===========f====================================================================]-( 80000) 0x0000000854.0 -----DASM(40000067) [ 18]
[============f===================================================================]-( 80000) 0x0000000858.0 -----DASM(f1402473) [ 19]
[============f===================================================================]-( 80000) 0x000000085c.0 -----DASM(10802623) [ 20]
白黒じゃ分からないね。

たぶんこれは白地に黒のターミナルだと綺麗に表示されるかな。
