Skip to content

Commit 9ab2df9

Browse files
authored
make it easier to get started with perf-model (#3008)
Related to issue #3007
1 parent 2c881cb commit 9ab2df9

2 files changed

Lines changed: 53 additions & 18 deletions

File tree

perf-model/README.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,41 @@ To cite this model, please head to the end of this document.
99

1010
## Getting started
1111

12+
### Generate an RVFI trace
13+
14+
To generate an RVFI trace, follow the instructions in the CVA6 repository to run a simulation.
15+
The RVFI trace will be in `verif/sim/out_<date>/<simulator>/<test-name>.log`.
16+
17+
18+
### Running the model
19+
20+
```bash
21+
python3 model.py verif/sim/out_<date>/<simulator>/<test-name>.log
22+
```
23+
24+
The annotated trace is generated in an `annotated.log` file in the current directory.
25+
26+
It prints a lot of debug information so that you can see all the events (note: it slows down model execution).
27+
To disable these prints, modify the instantiation with `Model(debug=False)` in the `main` function.
28+
29+
At the end of the simulation, the model prints statistics with the `print_stats` call in the `main` function.
30+
These statistics can be performed on the timed part, which is filtered with the `filter_timed_part` function.
31+
Feel free to modify the `filter_timed_part` function to suit your needs.
32+
33+
34+
### Exploring design space
35+
36+
In `model.py`, the `main` function runs the model with arguments which override default values.
37+
Generic parameters are available in `Model.__init__`.
38+
You can add new parameters to explore here.
39+
40+
To perform exploration, run the model in a loop, like `issue_commit_graph` does.
41+
The `display_scores` function is meant to print a 3D plot if you have `matplotlib`.
42+
`issue_commit_graph` prints the scores so that you can store it and display the figure without re-running the model.
43+
44+
45+
## Comparing the model and the RTL
46+
1247
### Adapt RVFI trace generation
1348

1449
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
2459
```
2560

2661

27-
### Generate an RVFI trace
28-
29-
To generate an RVFI trace, follow the instructions in the CVA6 repository to run a simulation.
30-
The RVFI trace will be in `verif/sim/out_<date>/<simulator>/<test-name>.log`.
31-
62+
### Calculate instruction duration
3263

33-
### Running the model
64+
Run `cycle_diff.py` for each script.
3465

3566
```bash
36-
python3 model.py verif/sim/out_<date>/<simulator>/<test-name>.log
67+
python3 perf-model/cycle_diff.py annotated.log
68+
mv traceout.log model.log
69+
python3 perf-model/cycle_diff.py verif/sim/out_<date>/<simulator>/<test-name>.log
3770
```
3871

72+
Note: the `cycles_diff.py` script filters the "timed" part of the program.
73+
To do this, it tries to find `csrr minstret` instructions.
74+
Feel free to modify the script to suit your needs.
3975

40-
### Exploring design space
4176

42-
In `model.py`, the `main` function runs the model with arguments which override default values.
43-
Generic parameters are available in `Model.__init__`.
44-
You can add new parameters to explore here.
77+
### List the differences
4578

46-
To perform exploration, run the model in a loop, like `issue_commit_graph` does.
47-
The `display_scores` function is meant to print a 3D plot if you have `matplotlib`.
48-
`issue_commit_graph` prints the scores so that you can store it and display the figure without re-running the model.
79+
```bash
80+
diff -y traceout.log model.log | less
81+
```
4982

5083

5184
## Files

perf-model/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class Model:
347347
"""Models the scheduling of CVA6"""
348348

349349
re_instr = re.compile(
350-
r"([a-z]+)\s+0:\s*0x00000000([0-9a-f]+)\s*\(([0-9a-fx]+)\)\s*@\s*([0-9]+)\s*(.*)"
350+
r"([a-z]+)\s+0:\s*0x0*([0-9a-f]+)\s*\(([0-9a-fx]+)\)\s*(@\s*[0-9]+)?\s*(.*)"
351351
)
352352

353353
def __init__(
@@ -549,14 +549,14 @@ def run(self, cycles=None):
549549

550550
def write_trace(output_file, instructions):
551551
"""Write cycle-annotated trace"""
552-
pattern = re.compile(r"@\s*[0-9]+")
552+
pattern = re.compile(r"\)\s*(@\s*[0-9]+)? ")
553553

554554
lines = []
555555
for instr in instructions:
556556
commit_event = instr.events[-1]
557557
assert commit_event.kind == EventKind.commit
558558
cycle = commit_event.cycle
559-
annotated = re.sub(pattern, f"@ {cycle}", instr.line)
559+
annotated = re.sub(pattern, f") @ {cycle} ", instr.line)
560560
#if EventKind.STRUCT in [e.kind for e in instr.events]:
561561
# annotated += " #STRUCT"
562562
#if EventKind.RAW in [e.kind for e in instr.events]:
@@ -660,7 +660,9 @@ def main(input_file: str):
660660
model.run()
661661

662662
write_trace('annotated.log', model.retired)
663-
print_stats(filter_timed_part(model.retired))
663+
664+
#print_stats(filter_timed_part(model.retired))
665+
print_stats(model.retired)
664666

665667
if __name__ == "__main__":
666668
main(sys.argv[1])

0 commit comments

Comments
 (0)