Skip to content

Add Spike-STF Support, Update Dockerfile, and Fix README Links #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions traces/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Olympia. STFs are typically created by a RISC-V functional model that
has been instrumented to generate one.

Two functional models which generate STFs are documented.
[Spike-STF](https://github.com/jeffnye-gh/cpm.riscv-isa-sim)
[Spike-STF](https://github.com/condorcomputing/condor.riscv-isa-sim)
is the latest model,
[Dromajo](https://github.com/chipsalliance/dromajo) also generates
STFs.
Expand Down Expand Up @@ -123,7 +123,7 @@ cd build

## STF Inputs

Using the [stf_lib]() in the [Sparcians](https://github.com/sparcians)
Using the [stf_lib](https://github.com/sparcians/stf_lib) in the [Sparcians](https://github.com/sparcians)
repo, Olympia is capable of reading a RISC-V STF trace generated from
a functional simulator. Included in Olympia (in this directory) are several trace files

Expand Down Expand Up @@ -185,7 +185,7 @@ the macro tracing mode.

### Build Spike-STF
The first step to generating an STF with Spike-STF is to clone and build
the Spike-STF [repo](https://github.com/jeffnye-gh/cpm.riscv-isa-sim.git).
the Spike-STF [repo](https://github.com/condorcomputing/condor.riscv-isa-sim).

This example uses the `riscv-perf-model/traces` directory as a working
directory.
Expand All @@ -198,11 +198,12 @@ your path.

```bash
cd riscv-perf-model/traces
git clone https://github.com/jeffnye-gh/cpm.riscv-isa-sim.git --recursive
git clone https://github.com/condorcomputing/condor.riscv-isa-sim.git --recurse-submodules

cd cpm.riscv-isa-sim
cd condor.riscv-isa-sim
bash scripts/download-bm-compiler.sh
export PATH=`pwd`/riscv-embecosm-embedded-ubuntu2204-20250309/bin:$PATH
which riscv64-unknown-elf-gcc #verify compiler is in your path
```
Exit the conda environment, if enabled, before compiling Spike-STF.
```
Expand All @@ -221,14 +222,14 @@ The regress target executes the [riscv-tests](https://github.com/riscv-software-
The compiler is a prebuilt RISC-V cross compiler from [Embecosm](https://embecosm.com/).

There is detailed information in the Spike-STF repo,
[README_FORK.mk](https://github.com/jeffnye-gh/cpm.riscv-isa-sim/blob/spike_stf/README_FORK.md) and [USAGE.md](https://github.com/jeffnye-gh/cpm.riscv-isa-sim/blob/spike_stf/USAGE.md).
[README_FORK.mk](https://github.com/condorcomputing/condor.riscv-isa-sim/blob/spike_stf/README_FORK.md) and [USAGE.md](https://github.com/condorcomputing/condor.riscv-isa-sim/blob/spike_stf/USAGE.md).

### Generating the Baremetal Dhrystone Traces

When Spike-STF is initially configured the dhrystone ELFs are created. If they need to be re-created:

```bash
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
make -C dhrystone
```

Expand All @@ -237,12 +238,12 @@ optimization running 1000 iterations. The source code has been modified to
add the trace macros and to allow simplified execution under baremetal with
limited syscall support.

A discussion of the 3 optimization levels is available in [USAGE.md](https://github.com/jeffnye-gh/cpm.riscv-isa-sim/blob/spike_stf/USAGE.md#dhrystone-optimization-discussion).
A discussion of the 3 optimization levels is available in [USAGE.md](https://github.com/condorcomputing/condor.riscv-isa-sim/blob/spike_stf/USAGE.md#dhrystone-optimization-discussion).

Once the ELFs are built, traces are generated by:

```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim

bash scripts/run-spike-stf.sh dhrystone/bin/dhrystone_opt1.1000.gcc.bare.riscv \
dhrystone_opt1.zstf
Expand All @@ -257,9 +258,9 @@ The compressed trace outputs can then be run on olympia by
```
<cd to the directory containing olympia>

./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt1.zstf
./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt2.zstf
./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt3.zstf
./olympia ../traces/condor.riscv-isa-sim/trace_out/dhrystone_opt1.zstf
./olympia ../traces/condor.riscv-isa-sim/trace_out/dhrystone_opt2.zstf
./olympia ../traces/condor.riscv-isa-sim/trace_out/dhrystone_opt3.zstf
```
## Generating Linux Traces

Expand All @@ -268,14 +269,14 @@ The compressed trace outputs can then be run on olympia by
In order to compile applications for linux, you must have riscv64-unknown-linux-gnu-gcc in your path.

```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
bash scripts/download-lnx-compiler.sh
export PATH=`pwd`/riscv64-embecosm-linux-gcc-ubuntu2204-20240407/bin:$PATH
```

To build the linux version of the Dhrystone benchmarks:
```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
make -C dhrystone bin-linux
```

Expand All @@ -297,11 +298,11 @@ The process to clone and build these components is contained in a script.
This is a lengthy process.

```bash
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
bash scripts/build-linux-collateral.sh
```

Once complete, the directory `riscv-perf-model/traces/cpm.riscv-isa-sim/riscv-linux` will contain the files necessary to boot linux.
Once complete, the directory `riscv-perf-model/traces/condor.riscv-isa-sim/riscv-linux` will contain the files necessary to boot linux.
```
fw_jump.elf
rootfs.cpio
Expand All @@ -311,7 +312,7 @@ Image
### Booting Linux on Spike-STF
With the linux components built, boot linux using the helper script:
```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
bash scripts/boot-linux.sh
```
The credentials are root/root.
Expand All @@ -331,7 +332,7 @@ the buildroot source tree, rebuilds rootfs, and copies the image to riscv-linux
for use in the next section.

```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
bash scripts/build-trace-rootfs.sh
```

Expand All @@ -353,7 +354,7 @@ arguments. The first specifes the new rootfs and the second specifies the path
for the STF trace output.

```
cd riscv-perf-model/traces/cpm.riscv-isa-sim
cd riscv-perf-model/traces/condor.riscv-isa-sim
bash scripts/boot-linux.sh --rootfs ./riscv-linux/trace_rootfs.cpio \
--trace ./trace_out/linux_trace.zstf
```
Expand Down Expand Up @@ -405,7 +406,7 @@ This is useful in cases.
For other use cases, check the USAGE.md file in the Spike-STF repo for
instructions on how to use initd to automate linux based trace generation.

See [Automating Linux Tracing with INIT.d](https://github.com/jeffnye-gh/cpm.riscv-isa-sim/blob/spike_stf/USAGE.md#Automating-linux-tracing-with-initd)
See [Automating Linux Tracing with INIT.d](https://github.com/condorcomputing/condor.riscv-isa-sim/blob/spike_stf/USAGE.md#automating-linux-tracing-with-initd)


-----------------------------------------------------
Expand Down Expand Up @@ -557,3 +558,4 @@ Running...
olympia: STF file input detected
...
```

97 changes: 97 additions & 0 deletions traces/docker_stf_trace_gen/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
FROM ubuntu:24.04

# Combine apt-get commands and clean up to reduce image size
RUN apt-get update && apt-get install -y \
device-tree-compiler \
libboost-regex-dev \
libboost-system-dev \
libboost-program-options-dev \
libboost-json-dev \
rapidjson-dev \
libhdf5-dev \
liblzma-dev \
libbz2-dev \
cython3 \
git \
binutils \
build-essential \
cmake \
gcc-riscv64-linux-gnu \
zstd \
libzstd-dev \
autoconf \
automake \
autotools-dev \
curl \
python3 \
python3-pip \
python3-tomli \
libmpc-dev \
libmpfr-dev \
libgmp-dev \
gawk \
bison \
flex \
texinfo \
gperf \
libtool \
patchutils \
bc \
zlib1g-dev \
libexpat-dev \
ninja-build \
libglib2.0-dev \
libslirp-dev \
wget \
&& rm -rf /var/lib/apt/lists/*

# Set up RISCV environment
ENV RISCV=/riscv
ENV PATH=$RISCV/bin:/opt/riscv/bin:$PATH
RUN mkdir -p $RISCV

# Using HTTP instead of SSH to avoid setting git credentials
RUN git config --global url."https://github.com/".insteadOf "git@github.com:"

# Generic config details required during the cloning (git am, apply,patch done during the toolchain build process)
RUN git config --global user.email "builder@example.com" && \
git config --global user.name "Docker Builder"


# Clone repositories
WORKDIR $RISCV
RUN git clone https://github.com/condorcomputing/condor.riscv-isa-sim.git --recurse-submodules || exit 1
RUN git clone https://github.com/sparcians/stf_tools || exit 1
RUN git clone https://github.com/riscv-software-src/riscv-pk.git || exit 1
RUN git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git || exit 1

# Build riscv-gnu-toolchain
WORKDIR $RISCV/riscv-gnu-toolchain
RUN ./configure --prefix=/opt/riscv && make -j$(nproc) && make install

# Build riscv-pk
WORKDIR $RISCV/riscv-pk/build
RUN ../configure --prefix=$RISCV --host=riscv64-unknown-elf && make -j$(nproc) && make install

# Build stf_tools
WORKDIR $RISCV/stf_tools
RUN git submodule update --init --recursive || exit 1
WORKDIR $RISCV/stf_tools/release
RUN cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(nproc)

# Build condor.riscv-isa-sim
WORKDIR $RISCV/condor.riscv-isa-sim
RUN bash scripts/download-bm-compiler.sh && \
COMPILER_DIR=$(find . -maxdepth 1 -type d -name "riscv-embecosm-*" | head -n 1) && \
[ -n "$COMPILER_DIR" ] || (echo "Error: riscv-embecosm-* directory not found!" && exit 1) && \
export PATH=$(pwd)/$COMPILER_DIR/bin:$PATH && \
echo "export PATH=/riscv/condor.riscv-isa-sim/$COMPILER_DIR/bin:\$PATH" >> /root/.bashrc && \
mkdir -p build && cd build && \
../configure --prefix=$RISCV/condor.riscv-isa-sim/install && \
make -j$(nproc) && \
make regress && \
make install

# shell
CMD ["/bin/bash"]

59 changes: 59 additions & 0 deletions traces/docker_stf_trace_gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Spike-STF trace generation

> This workflow is still under development. For the most up-to-date instructions, refer to the [Generating Input for Olympia](https://github.com/riscv-software-src/riscv-perf-model/blob/master/traces/README.md) README

## Table of Contents

1. [Introduction](#introduction)
1. [Dependencies](#dependencies)
1. [Project Structure](#project-structure)
1. [Usage](#usage)
1. [Build the Docker Image](#build-the-docker-image)
1. [Run STF Trace Generation](#run-stf-trace-generation)

## Introduction

This setup provides a containerized workflow to generate STF traces using Spike-STF. It sets up a complete environment with the RISC-V GNU toolchain, pk (proxy kernel), and Spike-STF.

## Dependencies

- **Docker** – See the [official installation guide](https://docs.docker.com/engine/install).
This workflow was tested with Docker version 28.3.0, build 38b7060, but it should also work with the latest available version.

## Project Structure

```bash
qemu-simpoint-dhrystone/
├── Dockerfile # Creates a Docker image with the RISC-V GNU toolchain, pk, stf_tools and Spike-STF
├── run_in_docker.sh # Runs an STF trace generation example inside the container
├── build_docker.sh # Builds the Docker image
├── build_and_run.sh # Executes both build_docker and run_in_docker scripts
```

## Usage

This workflow can be split into two sequential tasks:

- Build the Docker image
- Generate STF traces using the Docker container

Alternatively, you may run the [`build_and_run.sh`](./build_and_run.sh) script to see an example of the trace generation process.

### Build the Docker Image

```bash
docker build -t spike-stf .
```

### Run STF Trace Generation

```bash
mkdir -p trace_output

docker run --rm \
-v "$OUTPUT_DIR":/riscv/condor.riscv-isa-sim/trace_out \
"$IMAGE_NAME" \
bash -c "
bash scripts/run-spike-stf.sh $BINARY_NAME $TRACEOUT_NAME
"
```
13 changes: 13 additions & 0 deletions traces/docker_stf_trace_gen/build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

# === Configuration ===
BUILD_SCRIPT="./build_docker.sh"
RUN_SCRIPT="./run_in_docker.sh"

echo "[STEP 1] Building Docker image..."
bash "$BUILD_SCRIPT"

echo "[STEP 2] Running trace generation..."
bash "$RUN_SCRIPT"
6 changes: 6 additions & 0 deletions traces/docker_stf_trace_gen/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

IMAGE_NAME="spike-stf"
docker build -t "$IMAGE_NAME" .
19 changes: 19 additions & 0 deletions traces/docker_stf_trace_gen/run_in_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

IMAGE_NAME="spike-stf"
OUTPUT_DIR="$(pwd)/trace_output"

# The binary to run on spike (bare-metal)
BINARY_NAME="dhrystone/bin/dhrystone_opt1.1000.gcc.bare.riscv"
TRACEOUT_NAME="trace_output.zstf"

mkdir -p "$OUTPUT_DIR"

docker run --rm \
-v "$OUTPUT_DIR":/riscv/condor.riscv-isa-sim/trace_out \
"$IMAGE_NAME" \
bash -c "
bash scripts/run-spike-stf.sh $BINARY_NAME $TRACEOUT_NAME
"