Skip to content

Commit 89c9d1c

Browse files
trace gen doc update and announce Spike-STF (#258)
For olympia this is a documentation update for trace generation. Also this PR announces public release of a Spike fork that supports STF and BBV generation (called Spike-STF). Spike-STF was forked from the main Spike and the STV/BBV/regression support was developed by me and others at Condor. There are a number of other features included. BTW: this version of spike supports the RVA23 profile, which includes vector. The public repo is here https://github.com/jeffnye-gh/cpm.riscv-isa-sim.git. In the PR I have updated the trace/README.md with details on how to generate traces under linux and baremetal and use them with olympia. The trace README.md documents how to use the Spike-STF repo, cloning it within the olympia tree, d/loading a baremetal and linux cross-compiler, d/loading the kernel, buildroot and opensbi. There is a fair bit of automation to support linux and build these packages. There are bash scripts that illustrate how to use the constructed collateral to create traces for olympia. I have kept the Dromajo instructions, but I think long term this will replace Dromajo because Spike's ISA support is current. I have also added three dhrystone traces generated with Spike-STF. These three dhrystone align with the accepted practice of 3 levels of optimization, ground rules, in-lining, and LTO. --------- Co-authored-by: jeffnye-gh <habanaro@gmail.com>
1 parent 1da40c2 commit 89c9d1c

File tree

4 files changed

+309
-6
lines changed

4 files changed

+309
-6
lines changed

traces/README.md

Lines changed: 309 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Generating Input for Olympia
22

3+
## Table of Contents
4+
5+
1. [Introduction](#introduction)
6+
1. [JSON Inputs](#json-inputs)
7+
1. [STF Inputs](#stf-inputs)
8+
1. [Instrumenting Source for Tracing](#instrumenting-source-for-tracing)
9+
1. [Generating Baremetal Traces](#generating-baremetal-traces)
10+
1. [Build Spike-STF](#build-spike-stf)
11+
1. [Generating the Baremetal Dhrystone Traces](#generating-the-baremetal-dhrystone-traces)
12+
1. [Generating Linux Traces](#generating-linux-traces)
13+
1. [Building the Linux Dhrystone Elfs](#building-the-linux-dhrystone-elfs)
14+
1. [Building the Linux Collateral](#building-the-linux-collateral)
15+
1. [Booting Linux on Spike-STF](#booting-linux-on-spike-stf)
16+
1. [Updating the Root File System](#updating-the-root-file-system)
17+
1. [Invoke Linux and Generate the Traces](#invoke-linux-and-generate-the-traces)
18+
1. [Sample Session](#sample-session)
19+
1. [Generating an STF Trace with Dromajo](#generating-an-stf-trace-with-dromajo)
20+
1. [Build an STF Capable Dromajo](#build-an-stf-capable-dromajo)
21+
1. [Instrument a Workload for Tracing](#instrument-a-workload-for-tracing)
22+
23+
## Introduction
24+
325
Olympia can take input in two formats: JSON and
426
[STF](https://github.com/sparcians/stf_spec).
527

@@ -11,6 +33,16 @@ STF format is the preferred format to represent a workload to run on
1133
Olympia. STFs are typically created by a RISC-V functional model that
1234
has been instrumented to generate one.
1335

36+
Two functional models which generate STFs are documented.
37+
[Spike-STF](https://github.com/jeffnye-gh/cpm.riscv-isa-sim)
38+
is the latest model,
39+
[Dromajo](https://github.com/chipsalliance/dromajo) also generates
40+
STFs.
41+
42+
Spike-STF ISA suport is more recent. Spike-STF adds other features such as BBV generation.
43+
44+
Documentation for trace generation is provided for both functional models.
45+
1446
## JSON Inputs
1547

1648
JSON inputs are typically generated by hand. There are no automated
@@ -93,18 +125,290 @@ cd build
93125

94126
Using the [stf_lib]() in the [Sparcians](https://github.com/sparcians)
95127
repo, Olympia is capable of reading a RISC-V STF trace generated from
96-
a functional simulator. Included in Olympia (in this directory) is a
97-
trace of the "hot spot" of Dhrystone generated from the Dromajo
98-
simulator. This directory also contains a trace of Coremark generated
99-
similarly.
128+
a functional simulator. Included in Olympia (in this directory) are several trace files
129+
130+
```
131+
- traces/dhrystone_opt1.zstf 1000 iterations of a baremetal Dhrystone
132+
run with optimization set for 'Ground Rules'.
133+
- traces/dhrystone_opt2.zstf 1000 iterations of a baremetal Dhrystone
134+
run with optimization allowing in-lining.
135+
- traces/dhrystone_opt3.zstf 1000 iterations of baremetal Dhrystone
136+
run with optimization allowing in-lining
137+
and LT. Baremetal
138+
139+
- traces/core_riscv.zstf Hot spot of Coremark generated by Dromajo
140+
- traces/dhrystone.zstf Hot spot of Dhrystone generated by Dromajo
141+
- traces/core_riscv.zstf Hot spot of Coremark generated by Dromajo
142+
```
100143

101-
To run the STF file, just provide it to olympia:
144+
To run an STF file, provide the path to olympia:
102145
```
103146
cd build
147+
./olympia ../traces/dhrystone_opt1.zstf
148+
./olympia ../traces/dhrystone_opt2.zstf
149+
./olympia ../traces/dhrystone_opt3.zstf
104150
./olympia ../traces/dhrystone.zstf
105151
./olympia ../traces/core_riscv.zstf
106152
```
107153

154+
## Instrumenting Source for Tracing
155+
156+
There are multiple ways to trigger tracing. The macro tracing scheme
157+
instruments source code with trace boundary macros. These
158+
macros are nops with known operand encodings comprehended by
159+
the functional models. The macro tracing scheme supports baremetal and
160+
linux application tracing.
161+
162+
The source code is instrumented by insertion of `START_TRACE` and `STOP_TRACE`.
163+
164+
For example:
165+
``` main() {
166+
// ... init code
167+
168+
START_TRACE;
169+
// Dhrystone benchmark code
170+
STOP_TRACE;
171+
172+
// ... teardown
173+
}
174+
175+
```
176+
The `START_TRACE` and `STOP_TRACE` macros are defined in `traces/stf_trace_gen/trace_macros.h`.
177+
178+
Instructions between the macros will be recorded in the trace output.
179+
180+
Spike-STF supports other tracing modes. Both Dromajo and Spike-STF support
181+
the macro tracing mode.
182+
183+
---------------------------------------------------------
184+
## Generating Baremetal Traces
185+
186+
### Build Spike-STF
187+
The first step to generating an STF with Spike-STF is to clone and build
188+
the Spike-STF [repo](https://github.com/jeffnye-gh/cpm.riscv-isa-sim.git).
189+
190+
This example uses the `riscv-perf-model/traces` directory as a working
191+
directory.
192+
193+
The steps are: clone the repo, download and add the baremetal compiler to your
194+
path, and build/regress/install Spike-STF.
195+
196+
The compiler steps are optional if you have `riscv64-unknown-elf-gcc` in
197+
your path.
198+
199+
```bash
200+
cd riscv-perf-model/traces
201+
git clone https://github.com/jeffnye-gh/cpm.riscv-isa-sim.git --recursive
202+
203+
cd cpm.riscv-isa-sim
204+
bash scripts/download-bm-compiler.sh
205+
export PATH=`pwd`/riscv-embecosm-embedded-ubuntu2204-20250309/bin:$PATH
206+
```
207+
Exit the conda environment, if enabled, before compiling Spike-STF.
208+
```
209+
conda deactivate
210+
conda deactivate
211+
212+
mkdir -p build install && cd build
213+
../configure --prefix=`pwd`/../install
214+
make -j$(nproc)
215+
make regress
216+
make install
217+
```
218+
219+
The regress target executes the [riscv-tests](https://github.com/riscv-software-src/riscv-tests) test suite. Pass/fail is reported.
220+
221+
The compiler is a prebuilt RISC-V cross compiler from [Embecosm](https://embecosm.com/).
222+
223+
There is detailed information in the Spike-STF repo,
224+
[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).
225+
226+
### Generating the Baremetal Dhrystone Traces
227+
228+
When Spike-STF is initially configured the dhrystone ELFs are created. If they need to be re-created:
229+
230+
```bash
231+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
232+
make -C dhrystone
233+
```
234+
235+
This creates 3 versions of the dhrystone elf with 3 different levels of
236+
optimization running 1000 iterations. The source code has been modified to
237+
add the trace macros and to allow simplified execution under baremetal with
238+
limited syscall support.
239+
240+
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).
241+
242+
Once the ELFs are built, traces are generated by:
243+
244+
```
245+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
246+
247+
bash scripts/run-spike-stf.sh dhrystone/bin/dhrystone_opt1.1000.gcc.bare.riscv \
248+
dhrystone_opt1.zstf
249+
bash scripts/run-spike-stf.sh dhrystone/bin/dhrystone_opt2.1000.gcc.bare.riscv \
250+
dhrystone_opt2.zstf
251+
bash scripts/run-spike-stf.sh dhrystone/bin/dhrystone_opt3.1000.gcc.bare.riscv \
252+
dhrystone_opt3.zstf
253+
```
254+
255+
The compressed trace outputs can then be run on olympia by
256+
257+
```
258+
<cd to the directory containing olympia>
259+
260+
./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt1.zstf
261+
./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt2.zstf
262+
./olympia ../traces/cpm.riscv-isa-sim/trace_out/dhrystone_opt3.zstf
263+
```
264+
## Generating Linux Traces
265+
266+
### Building the Linux Dhrystone Elfs
267+
268+
In order to compile applications for linux, you must have riscv64-unknown-linux-gnu-gcc in your path.
269+
270+
```
271+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
272+
bash scripts/download-lnx-compiler.sh
273+
export PATH=`pwd`/riscv64-embecosm-linux-gcc-ubuntu2204-20240407/bin:$PATH
274+
```
275+
276+
To build the linux version of the Dhrystone benchmarks:
277+
```
278+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
279+
make -C dhrystone bin-linux
280+
```
281+
282+
Directory dhrystone/bin will contain:
283+
```
284+
dhrystone/bin/dhrystone_opt1.1000.gcc.linux.riscv
285+
dhrystone/bin/dhrystone_opt2.1000.gcc.linux.riscv
286+
dhrystone/bin/dhrystone_opt3.1000.gcc.linux.riscv
287+
```
288+
289+
### Building the Linux Collateral
290+
291+
In order to generate linux based traces a linux environment is required as well as a linux cross compiler in your path. See above for the compiler.
292+
293+
A linux environment consists of a bootloader, the linux kernel and a
294+
root file system.
295+
296+
The process to clone and build these components is contained in a script.
297+
This is a lengthy process.
298+
299+
```bash
300+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
301+
bash scripts/build-linux-collateral.sh
302+
```
303+
304+
Once complete, the directory `riscv-perf-model/traces/cpm.riscv-isa-sim/riscv-linux` will contain the files necessary to boot linux.
305+
```
306+
fw_jump.elf
307+
rootfs.cpio
308+
Image
309+
```
310+
311+
### Booting Linux on Spike-STF
312+
With the linux components built, boot linux using the helper script:
313+
```
314+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
315+
bash scripts/boot-linux.sh
316+
```
317+
The credentials are root/root.
318+
319+
Hitting control-c a few times will exit the simulator. Depending on what is
320+
running under linux it is sometimes necessary to kill the spike PID.
321+
322+
### Updating the Root File System
323+
To trace applications under linux it is necessary to add them to the root
324+
file system. This makes them available from the spike/linux console.
325+
326+
In this example the 3 versions of dhrystone linux are built into the root
327+
file system.
328+
329+
This script builds the `dhrystone_optN.1000.gcc.linux.riscv` elfs, adds them to
330+
the buildroot source tree, rebuilds rootfs, and copies the image to riscv-linux
331+
for use in the next section.
332+
333+
```
334+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
335+
bash scripts/build-trace-rootfs.sh
336+
```
337+
338+
This script performs basic checking, and copies the dhrystone linux ELFS to
339+
a location in the buildroot tree.
340+
341+
```
342+
${BUILDROOT}/output/target/root/trace_elfs
343+
```
344+
345+
This location ensures access to the elfs once the root file system has been recompiled and linux has been booted.
346+
347+
### Invoke Linux and Generate the Traces
348+
349+
350+
Once the new rootfs is built we boot linux on spike with tracing enabled from the
351+
command line. We use the boot-linux.sh script with two additional
352+
arguments. The first specifes the new rootfs and the second specifies the path
353+
for the STF trace output.
354+
355+
```
356+
cd riscv-perf-model/traces/cpm.riscv-isa-sim
357+
bash scripts/boot-linux.sh --rootfs ./riscv-linux/trace_rootfs.cpio \
358+
--trace ./trace_out/linux_trace.zstf
359+
```
360+
Once linux boots, enter the root/root credentials, then from the ash shell
361+
cd to `trace_elfs and run the dhrystone_opt3.1000.gcc.bare.riscv.zstf
362+
363+
### Sample Session
364+
365+
A sample session:
366+
367+
```
368+
Welcome to Buildroot
369+
buildroot login: root
370+
root
371+
Password: root
372+
373+
# cd trace_elfs
374+
cd trace_elfs
375+
# ls
376+
ls
377+
dhrystone_opt1.1000.gcc.linux.riscv dhrystone_opt3.1000.gcc.linux.riscv
378+
dhrystone_opt2.1000.gcc.linux.riscv
379+
# ./dhrystone_opt3.1000.gcc.linux.riscv
380+
381+
...snip...
382+
-I: traced 241546 instructions
383+
...snip...
384+
Str_2_Loc: DHRYSTONE PROGRAM, 2'ND STRING
385+
should be: DHRYSTONE PROGRAM, 2'ND STRING
386+
387+
Measured time too small to obtain meaningful results
388+
Please increase number of runs
389+
390+
# <control-c>
391+
# ^C(spike) quit
392+
```
393+
394+
Once you have exited spike and are returned to the main o/s, the trace_out
395+
directory will hold the trace file.
396+
```
397+
-rw-r--r-- 1 random agroup 12097 Jan 1 00:00 linux_trace.zstf
398+
```
399+
400+
Note _any_ trace-enabled ELF you run while in spike linux will be added to the
401+
same trace file.
402+
403+
This is useful in cases.
404+
405+
For other use cases, check the USAGE.md file in the Spike-STF repo for
406+
instructions on how to use initd to automate linux based trace generation.
407+
408+
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)
409+
410+
411+
-----------------------------------------------------
108412
### Generating an STF Trace with Dromajo
109413

110414
#### Build an STF-Capable Dromajo
@@ -251,6 +555,5 @@ Now, run that trace on olympia:
251555
% ./olympia ../traces/stf_trace_gen/dromajo/run/dhry_riscv.zstf
252556
Running...
253557
olympia: STF file input detected
254-
255558
...
256559
```

traces/dhrystone_opt1.zstf

3.29 KB
Binary file not shown.

traces/dhrystone_opt2.zstf

2.76 KB
Binary file not shown.

traces/dhrystone_opt3.zstf

2.76 KB
Binary file not shown.

0 commit comments

Comments
 (0)