SPEC CPU2006のベンチマークをSniperでシミュレーションするために、Sniperのダウンロードからビルドまでのフローをspec2006_work/Makefileに追加した。
Makefileに以下のターゲットを追加した。
# Download and build Sniper
build_sniper: .build_sniper
.build_sniper:
@echo "=== Downloading Sniper ==="
@if [ ! -d "$(SNIPER_ROOT)" ]; then \
echo "Cloning Sniper from $(SNIPER_GIT_URL)..."; \
cd $(CURDIR)/.. && \
git clone $(SNIPER_GIT_URL) $(SNIPER_ROOT) --branch msyksphinz/riscv || exit 1; \
fi
cd $(SNIPER_ROOT) && \
PIN_ROOT=/home/kimura/sniper_tools/pin-3.18-98332-gaebd7b1e6-gcc-linux \
CPU2006_ROOT=$(SPEC_ROOT) \
bash $(CURDIR)/snipersim/riscv/build-riscv.sh || exit 1; \
echo "=== Sniper build completed ==="
touch $@
SNIPER_ROOTが存在しない場合はGitHubからmsyksphinz/riscvブランチをクローンし、PIN_ROOTとCPU2006_ROOTを環境変数として設定してからsnipersim/riscv/build-riscv.shを実行する。
Makefileの先頭で以下の変数を定義している。
SNIPER_GIT_URL := https://github.com/msyksphinz/snipersim.git SNIPER_ROOT := $(CURDIR)/snipersim
build-riscv.shは依存関係のチェック、QEMU 9.2.4のダウンロードとビルド、RISC-Vツールチェーンのビルド、Sniper本体のビルドを実行する。
make build_sniperを実行したところ、checkdependencies-riscv.shで構文エラーが発生した。
./tools/checkdependencies-riscv.sh: 17: Syntax error: "(" unexpected
原因は、checkdependencies-riscv.shがbashの算術式(( $? > 0 ))を使用していたが、スクリプトにシェバンがなくshで実行されていたためである。checkdependencies-riscv.shに#!/bin/bashを追加し、算術式を[ $? -gt 0 ]に変更した。また、build-riscv.shからbashで明示的に実行するように修正した。
build-riscv.shはPIN_ROOTとCPU2006_ROOTの環境変数が必要である。Makefileでは、これらの環境変数をbuild-riscv.shの実行前に設定している。
PIN_ROOT=/home/kimura/sniper_tools/pin-3.18-98332-gaebd7b1e6-gcc-linux \ CPU2006_ROOT=$(SPEC_ROOT) \ bash $(CURDIR)/snipersim/riscv/build-riscv.sh
これでmake build_sniperコマンド一つでSniperをビルドできるようになった。既にビルド済みの場合は再ビルドをスキップする。再ビルドが必要な場合は、.build_sniperファイルを削除するか、SNIPER_ROOTディレクトリを削除してから実行する。