make it easier to get started with perf-model (#3008)
Some checks failed
bender-up-to-date / bender-up-to-date (push) Has been cancelled
ci / build-riscv-tests (push) Has been cancelled
ci / execute-riscv64-tests (push) Has been cancelled
ci / execute-riscv32-tests (push) Has been cancelled

Related to issue #3007
This commit is contained in:
Côme 2025-06-13 18:30:05 +02:00 committed by GitHub
parent 2c881cba05
commit 9ab2df9112
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 18 deletions

View file

@ -9,6 +9,41 @@ To cite this model, please head to the end of this document.
## Getting started ## Getting started
### Generate an RVFI trace
To generate an RVFI trace, follow the instructions in the CVA6 repository to run a simulation.
The RVFI trace will be in `verif/sim/out_<date>/<simulator>/<test-name>.log`.
### Running the model
```bash
python3 model.py verif/sim/out_<date>/<simulator>/<test-name>.log
```
The annotated trace is generated in an `annotated.log` file in the current directory.
It prints a lot of debug information so that you can see all the events (note: it slows down model execution).
To disable these prints, modify the instantiation with `Model(debug=False)` in the `main` function.
At the end of the simulation, the model prints statistics with the `print_stats` call in the `main` function.
These statistics can be performed on the timed part, which is filtered with the `filter_timed_part` function.
Feel free to modify the `filter_timed_part` function to suit your needs.
### Exploring design space
In `model.py`, the `main` function runs the model with arguments which override default values.
Generic parameters are available in `Model.__init__`.
You can add new parameters to explore here.
To perform exploration, run the model in a loop, like `issue_commit_graph` does.
The `display_scores` function is meant to print a 3D plot if you have `matplotlib`.
`issue_commit_graph` prints the scores so that you can store it and display the figure without re-running the model.
## Comparing the model and the RTL
### Adapt RVFI trace generation ### Adapt RVFI trace generation
The regular expression expects the cycle number to be in the RVFI trace. The regular expression expects the cycle number to be in the RVFI trace.
@ -24,28 +59,26 @@ To emit cycle number in RVFI trace, modify `corev_apu/tb/rvfi_tracer.sv` in CVA6
``` ```
### Generate an RVFI trace ### Calculate instruction duration
To generate an RVFI trace, follow the instructions in the CVA6 repository to run a simulation. Run `cycle_diff.py` for each script.
The RVFI trace will be in `verif/sim/out_<date>/<simulator>/<test-name>.log`.
### Running the model
```bash ```bash
python3 model.py verif/sim/out_<date>/<simulator>/<test-name>.log python3 perf-model/cycle_diff.py annotated.log
mv traceout.log model.log
python3 perf-model/cycle_diff.py verif/sim/out_<date>/<simulator>/<test-name>.log
``` ```
Note: the `cycles_diff.py` script filters the "timed" part of the program.
To do this, it tries to find `csrr minstret` instructions.
Feel free to modify the script to suit your needs.
### Exploring design space
In `model.py`, the `main` function runs the model with arguments which override default values. ### List the differences
Generic parameters are available in `Model.__init__`.
You can add new parameters to explore here.
To perform exploration, run the model in a loop, like `issue_commit_graph` does. ```bash
The `display_scores` function is meant to print a 3D plot if you have `matplotlib`. diff -y traceout.log model.log | less
`issue_commit_graph` prints the scores so that you can store it and display the figure without re-running the model. ```
## Files ## Files

View file

@ -347,7 +347,7 @@ class Model:
"""Models the scheduling of CVA6""" """Models the scheduling of CVA6"""
re_instr = re.compile( re_instr = re.compile(
r"([a-z]+)\s+0:\s*0x00000000([0-9a-f]+)\s*\(([0-9a-fx]+)\)\s*@\s*([0-9]+)\s*(.*)" r"([a-z]+)\s+0:\s*0x0*([0-9a-f]+)\s*\(([0-9a-fx]+)\)\s*(@\s*[0-9]+)?\s*(.*)"
) )
def __init__( def __init__(
@ -549,14 +549,14 @@ class Model:
def write_trace(output_file, instructions): def write_trace(output_file, instructions):
"""Write cycle-annotated trace""" """Write cycle-annotated trace"""
pattern = re.compile(r"@\s*[0-9]+") pattern = re.compile(r"\)\s*(@\s*[0-9]+)? ")
lines = [] lines = []
for instr in instructions: for instr in instructions:
commit_event = instr.events[-1] commit_event = instr.events[-1]
assert commit_event.kind == EventKind.commit assert commit_event.kind == EventKind.commit
cycle = commit_event.cycle cycle = commit_event.cycle
annotated = re.sub(pattern, f"@ {cycle}", instr.line) annotated = re.sub(pattern, f") @ {cycle} ", instr.line)
#if EventKind.STRUCT in [e.kind for e in instr.events]: #if EventKind.STRUCT in [e.kind for e in instr.events]:
# annotated += " #STRUCT" # annotated += " #STRUCT"
#if EventKind.RAW in [e.kind for e in instr.events]: #if EventKind.RAW in [e.kind for e in instr.events]:
@ -660,7 +660,9 @@ def main(input_file: str):
model.run() model.run()
write_trace('annotated.log', model.retired) write_trace('annotated.log', model.retired)
print_stats(filter_timed_part(model.retired))
#print_stats(filter_timed_part(model.retired))
print_stats(model.retired)
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1]) main(sys.argv[1])