-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_simulator.py
executable file
·108 lines (98 loc) · 4.78 KB
/
run_simulator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
import argparse
import os
import pathlib
import sys
import time
# Read input arguments
argParser = argparse.ArgumentParser()
argParser.add_argument("targetSW", help="Path to target ELF file")
argParser.add_argument("-boot", "--bootrom", help="Path to bootrom ELF file")
argParser.add_argument("-c", "--core", help="Simulated core. [cv32e40p | cva6]")
argParser.add_argument("-np", "--no_performance", action="store_true", help="Run without performance estimation")
argParser.add_argument("-tp", "--trace_performance", help="Path to dump traces generated by performance estimator")
argParser.add_argument("-ta", "--trace_asm", help="Path to dump ASM-trace")
argParser.add_argument("-ti", "--trace_instr", help="Path to dump instruction-trace")
argParser.add_argument("-gdb", "--debug", action="store_true", help="Run in ETISS-debug mode")
argParser.add_argument("-tgdb", "--target_debug", help="Run in target-SW-debug mode with specified debuger (<YOUR_PATH>/bin/riscv<32|64>-unknown-elf-gdb)")
argParser.add_argument("-p", "--profile", action="store_true", help="Run in profile mode (valgrind)")
args = argParser.parse_args()
# Check input arguments
if args.core is None:
sys.exit("FATAL: Called BareETISS run_helper.py without specifying a core")
# Resolve simulation dir and targetSW
simDir = str(pathlib.Path(__file__).resolve().parent) + "/simulator"
targetSW = str(pathlib.Path(args.targetSW).resolve())
# # Resolve debugger path
# if(args.target_debug):
# debugger = os.environ.get("PERF_EST_RISCV_ELF_GCC_PREFIX_" + args.core.upper())
# if(os.environ.get("PERF_EST_RISCV_ELF_GCC_RV32_" + args.core.upper()) == "ON"):
# debugger += "/bin/riscv32-unknown-elf-gdb"
# else:
# debugger += "/bin/riscv64-unknown-elf-gdb"
# Creating a dynamic ini file for run specific configurations
dynIni = pathlib.Path(simDir + "/dyn.ini").resolve()
with dynIni.open('w') as f:
# Specify target-SW
f.write("[StringConfigurations]\n")
f.write("vp.elf_file=" + targetSW + "\n")
if args.bootrom is not None:
f.write("vp.boot_file=" + str(pathlib.Path(args.bootrom).resolve()))
# Specify debug-plugin
if args.target_debug is not None:
f.write("[Plugin gdbserver]\n")
f.write("plugin.gdbserver.port=2222\n")
# Create plugin ini file
# TODO: Configuring the plugins here is not ideal! Find alternative!
pluginIni = pathlib.Path(simDir + "/plugin.ini").resolve()
with pluginIni.open('w') as f:
# Specify PerformanceEstimatorPlugin
if not args.no_performance:
f.write("[Plugin PerformanceEstimatorPlugin]\n")
f.write("plugin.perfEst.uArch=" + args.core.upper() + "\n")
if (perfTrace:=args.trace_performance) is not None:
f.write("plugin.perfEst.print=1\n")
f.write("plugin.perfEst.printDir=" + str(pathlib.Path(perfTrace).resolve()) + "\n")
# Specify Assembly-TracePrinterPlugin
if (asmTrace:=args.trace_asm) is not None:
f.write("[Plugin TracePrinterPlugin]\n")
f.write("plugin.tracePrinter.trace=AssemblyTrace\n")
f.write("plugin.tracePrinter.stream.toFile=1\n")
f.write("plugin.tracePrinter.stream.outDir=" + str(pathlib.Path(asmTrace).resolve()) + "\n")
f.write("plugin.tracePrinter.stream.fileName=asm_trace\n")
f.write("plugin.tracePrinter.stream.rotateSize=0x100000\n")
# Specify Instruction-TracePrinterPlugin
elif (instrTrace:=args.trace_instr) is not None:
f.write("[Plugin TracePrinterPlugin]\n")
if args.core.upper() == "CVA6":
f.write("plugin.tracePrinter.trace=InstructionTrace_RV64\n")
else:
raise RuntimeError("No supported instruction-trace for this core!")
f.write("plugin.tracePrinter.stream.toFile=1\n")
f.write("plugin.tracePrinter.stream.outDir=" + str(pathlib.Path(instrTrace).resolve()) + "\n")
f.write("plugin.tracePrinter.stream.fileName=instr_trace\n")
f.write("plugin.tracePrinter.stream.rotateSize=0x100000\n")
# Set exe and args pathes
vp_exe = simDir + "/build/main"
vp_args = " -i" + simDir + "/ini/common.ini"
vp_args += " -i" + simDir + "/ini/" + args.core + ".ini"
vp_args += " -i" + str(dynIni)
vp_args += " -i" + str(pluginIni)
run_sim = vp_exe + vp_args
# Run simulation
if(args.debug):
os.system("gdb --args " + run_sim)
elif args.target_debug is not None:
os.system("konsole --workdir $(pwd) -e \"bash -c \'" + args.target_debug + " -ex \\\"tar rem :2222\\\" " + targetSW + "\'\" &")
os.system(run_sim)
elif(args.profile):
os.system("valgrind --tool=callgrind " + run_sim)
else:
startTime = time.time()
os.system(run_sim)
endTime = time.time()
print("")
print("Total execution time: " + str(float(endTime - startTime)) + "s")
# Remove dynamic ini file
os.system("rm " + str(dynIni))
os.system("rm " + str(pluginIni))