Browse Source

Made plugin call configurable

Eyck Jentzsch 1 year ago
parent
commit
1102449d38

+ 1728
- 0
cycles.txt
File diff suppressed because it is too large
View File


+ 1
- 1
dbt-core

@@ -1 +1 @@
1
-Subproject commit 555bff0a20cfbf775994ed74b188b9af480df883
1
+Subproject commit 393c374cac4950e629036dda1615abedf866961f

+ 34
- 0
etc/dbt-riscv Debug hello w plugin.launch View File

@@ -0,0 +1,34 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
3
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB" value="true"/>
4
+<listAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB_LIST"/>
5
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="gdb"/>
6
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_ON_FORK" value="false"/>
7
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.GDB_INIT" value=".gdbinit"/>
8
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
9
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.REVERSE" value="false"/>
10
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.REVERSE_MODE" value="UseSoftTrace"/>
11
+<listAttribute key="org.eclipse.cdt.dsf.gdb.SOLIB_PATH"/>
12
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.TRACEPOINT_MODE" value="TP_NORMAL_ONLY"/>
13
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
14
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.internal.ui.launching.LocalApplicationCDebuggerTab.DEFAULTS_SET" value="true"/>
15
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
16
+<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
17
+<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="gdb"/>
18
+<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/>
19
+<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
20
+<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
21
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="-v4&#10;-p ic=${workspace_loc:DBT-RISE-RISCV}/cycles.txt&#10;${project_loc:hello}/hello"/>
22
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Debug/riscv/bin/riscv"/>
23
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="DBT-RISE-RISCV"/>
24
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
25
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.debug.1751741082"/>
26
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
27
+<listEntry value="/DBT-RISE-RISCV"/>
28
+</listAttribute>
29
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
30
+<listEntry value="4"/>
31
+</listAttribute>
32
+<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#10;"/>
33
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
34
+</launchConfiguration>

+ 2
- 2
etc/dbt-riscv dhrystone.launch View File

@@ -12,7 +12,7 @@
12 12
 <stringAttribute key="org.eclipse.cdt.dsf.gdb.TRACEPOINT_MODE" value="TP_NORMAL_ONLY"/>
13 13
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
14 14
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.internal.ui.launching.LocalApplicationCDebuggerTab.DEFAULTS_SET" value="true"/>
15
-<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
15
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="1"/>
16 16
 <stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
17 17
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="gdb"/>
18 18
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/>
@@ -22,7 +22,7 @@
22 22
 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Release/riscv/bin/riscv"/>
23 23
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="DBT-RISE-RISCV"/>
24 24
 <booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
25
-<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
25
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.release.1745230171"/>
26 26
 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
27 27
 <listEntry value="/DBT-RISE-RISCV"/>
28 28
 </listAttribute>

+ 1
- 1
riscv/incl/iss/arch/riscv_hart_msu_vp.h View File

@@ -55,7 +55,7 @@ namespace arch {
55 55
 
56 56
 enum { tohost_dflt = 0xF0001000, fromhost_dflt = 0xF0001040 };
57 57
 
58
-enum csr_name {
58
+enum riscv_csr {
59 59
     /* user-level CSR */
60 60
     // User Trap Setup
61 61
     ustatus = 0x000,

+ 47
- 16
riscv/src/main.cpp View File

@@ -66,7 +66,8 @@ int main(int argc, char *argv[]) {
66 66
         ("dump-ir", "dump the intermediate representation")
67 67
         ("elf", po::value<std::vector<std::string>>(), "ELF file(s) to load")
68 68
         ("mem,m", po::value<std::string>(), "the memory input file")
69
-        ("isa", po::value<std::string>()->default_value("rv32imac"), "isa to use for simulation");
69
+        ("plugin,p", po::value<std::vector<std::string>>(), "plugin to activate")
70
+        ("isa", po::value<std::string>()->default_value("rv32gc"), "isa to use for simulation");
70 71
     // clang-format on
71 72
     auto parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
72 73
     try {
@@ -97,30 +98,55 @@ int main(int argc, char *argv[]) {
97 98
         LOG_OUTPUT(connection)::stream() = f;
98 99
     }
99 100
 
101
+    std::vector<iss::vm_plugin*> plugin_list;
102
+    auto res=0;
100 103
     try {
101 104
         // application code comes here //
102 105
         iss::init_jit(argc, argv);
103 106
         bool dump = clim.count("dump-ir");
104 107
         // instantiate the simulator
105 108
         std::unique_ptr<iss::vm_if> vm{nullptr};
109
+        std::unique_ptr<iss::arch_if> cpu{nullptr};
106 110
         std::string isa_opt(clim["isa"].as<std::string>());
107
-//        iss::plugin::instruction_count ic_plugin("riscv/gen_input/src-gen/rv32imac_cyles.txt");
108
-//        iss::plugin::cycle_estimate ce_plugin("riscv/gen_input/src-gen/rv32imac_cyles.txt");
109
-        if (isa_opt.substr(0, 4)=="rv64") {
110
-            iss::arch::rv64ia* cpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv64ia>();
111
-            vm = iss::create(cpu, clim["gdb-port"].as<unsigned>());
112
-        } else if (isa_opt.substr(0, 5)=="rv32i") {
113
-            iss::arch::rv32imac* cpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv32imac>();
114
-            vm = iss::create(cpu, clim["gdb-port"].as<unsigned>());
115
-            //vm->register_plugin(ce_plugin);
116
-        } else if (isa_opt.substr(0, 5)=="rv32g") {
117
-            iss::arch::rv32gc* cpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv32gc>();
118
-            vm = iss::create(cpu, clim["gdb-port"].as<unsigned>());
119
-            //vm->register_plugin(ce_plugin);
111
+        if (isa_opt=="rv64ia") {
112
+            iss::arch::rv64ia* lcpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv64ia>();
113
+            vm = iss::create(lcpu, clim["gdb-port"].as<unsigned>());
114
+            cpu.reset(lcpu);
115
+        } else if (isa_opt=="rv32imac") {
116
+            iss::arch::rv32imac* lcpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv32imac>();
117
+            vm = iss::create(lcpu, clim["gdb-port"].as<unsigned>());
118
+            cpu.reset(lcpu);
119
+        } else if (isa_opt=="rv32gc") {
120
+            iss::arch::rv32gc* lcpu = new iss::arch::riscv_hart_msu_vp<iss::arch::rv32gc>();
121
+            vm = iss::create(lcpu, clim["gdb-port"].as<unsigned>());
122
+            cpu.reset(lcpu);
120 123
         } else {
121 124
             LOG(ERROR) << "Illegal argument value for '--isa': " << clim["isa"].as<std::string>() << std::endl;
122 125
             return 127;
123 126
         }
127
+        if (clim.count("plugin")) {
128
+           for (std::string opt_val : clim["plugin"].as<std::vector<std::string>>()){
129
+               auto plugin_name{opt_val};
130
+               std::string filename{"cycles.txt"};
131
+               std::size_t found = opt_val.find('=');
132
+               if (found!=std::string::npos){
133
+                   plugin_name=opt_val.substr(0, found);
134
+                   filename=opt_val.substr(found+1, opt_val.size());
135
+               }
136
+                if(plugin_name=="ic"){
137
+                    auto* ic_plugin= new iss::plugin::instruction_count(filename);
138
+                    vm->register_plugin(*ic_plugin);
139
+                    plugin_list.push_back(ic_plugin);
140
+                } else if(plugin_name=="ce"){
141
+                    auto* ce_plugin= new iss::plugin::cycle_estimate(filename);
142
+                    vm->register_plugin(*ce_plugin);
143
+                    plugin_list.push_back(ce_plugin);
144
+                } else {
145
+                    LOG(ERROR) << "Unknown plugin name: " << plugin_name << ", valid names are 'ce', 'ic'"<<std::endl;
146
+                    return 127;
147
+                }
148
+            }
149
+        }
124 150
         if (clim.count("disass")) {
125 151
             vm->setDisassEnabled(true);
126 152
             LOGGER(disass)::reporting_level() = logging::INFO;
@@ -151,9 +177,14 @@ int main(int argc, char *argv[]) {
151 177
         }
152 178
 		vm->reset(start_address);
153 179
         auto cycles = clim["instructions"].as<int64_t>();
154
-        return vm->start(cycles, dump);
180
+        res = vm->start(cycles, dump);
155 181
     } catch (std::exception &e) {
156 182
         LOG(ERROR) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit" << std::endl;
157
-        return 2;
183
+        res=2;
184
+    }
185
+    // cleanup to let plugins report of needed
186
+    for(auto* p:plugin_list){
187
+        delete p;
158 188
     }
189
+    return res;
159 190
 }

+ 5
- 5
riscv/src/plugin/cycle_estimate.cpp View File

@@ -63,7 +63,7 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if&
63 63
 	if(!arch_instr) return false;
64 64
 	const std::string  core_name = arch_instr->core_type_name();
65 65
     Json::Value &val = root[core_name];
66
-    if(val.isArray()){
66
+    if(!val.isNull() && val.isArray()){
67 67
     	delays.reserve(val.size());
68 68
     	for(auto it:val){
69 69
     		auto name = it["name"];
@@ -76,6 +76,8 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if&
76 76
 				delays.push_back(instr_desc{size.asUInt(), delay[0].asUInt(), delay[1].asUInt()});
77 77
     		}
78 78
     	}
79
+    } else {
80
+        LOG(ERROR)<<"plugin cycle_estimate: could not find an entry for "<<core_name<<" in JSON file"<<std::endl;
79 81
     }
80 82
 	return true;
81 83
 
@@ -85,8 +87,6 @@ void iss::plugin::cycle_estimate::callback(instr_info_t instr_info) {
85 87
     assert(arch_instr && "No instrumentation interface available but callback executed");
86 88
 	auto entry = delays[instr_info.instr_id];
87 89
 	bool taken = (arch_instr->get_next_pc()-arch_instr->get_pc()) != (entry.size/8);
88
-	if(taken && entry.taken > 1 ) // 1 is the default increment per instruction
89
-		arch_instr->set_curr_instr_cycles(entry.taken);
90
-	if(!taken && entry.not_taken > 1) // 1 is the default increment per instruction
91
-		arch_instr->set_curr_instr_cycles(entry.not_taken);
90
+    uint32_t delay = taken ? entry.taken : entry.not_taken;
91
+    if(delay>1) arch_instr->set_curr_instr_cycles(delay);
92 92
 }

+ 3
- 1
riscv/src/plugin/instruction_count.cpp View File

@@ -68,7 +68,7 @@ bool iss::plugin::instruction_count::registration(const char* const version, vm_
68 68
     if(!instr_if) return false;
69 69
 	const std::string  core_name = instr_if->core_type_name();
70 70
     Json::Value &val = root[core_name];
71
-    if(val.isArray()){
71
+    if(!val.isNull() && val.isArray()){
72 72
     	delays.reserve(val.size());
73 73
     	for(auto it:val){
74 74
     		auto name = it["name"];
@@ -84,6 +84,8 @@ bool iss::plugin::instruction_count::registration(const char* const version, vm_
84 84
     		}
85 85
     	}
86 86
     	rep_counts.resize(delays.size());
87
+    } else {
88
+        LOG(ERROR)<<"plugin instruction_count: could not find an entry for "<<core_name<<" in JSON file"<<std::endl;
87 89
     }
88 90
 	return true;
89 91
 }