History

Add a way to set the number of system threads the VM will use for disvm-exec. Update banner in disvm-exec to indicate DisVM version.

arr committed 10 years ago

Commit 093cfc11 parent 265a2bf3 files · +45 −12Browse files

Showing the changes to src/exec/main.cpp (1 of 3 files). Show all

Unified · Split

src/exec/main.cpp+39−6
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <debug.h>
1313 #include <exceptions.h>
1414 #include <vm_asm.h>
15+#include <vm_version.h>
1516 #include "exec.h"
1617
1718 using namespace disvm;
@@ -169,7 +170,7 @@ namespace · 151 unmodified lines
169170
170171 struct arg_exception_t : std::runtime_error
171172 {
172− arg_exception_t(const char *m, const char *arg)
173+ arg_exception_t(const char *m, const char *arg = nullptr)
173174 : std::runtime_error{ m }
174175 , arg{ arg }
175176 { }
@@ -179,8 +180,20 @@ struct arg_exception_t : std::runtime_error · 3 unmodified lines
179180
180181 struct exec_options
181182 {
183+ exec_options()
184+ : debugger{}
185+ , enabled_debugger{ false }
186+ , quiet_start{ false }
187+ , print_help{ false }
188+ , sys_thread_count{ vm_t::default_system_thread_count }
189+ , thread_quanta{ vm_t::default_thread_quanta }
190+ { }
191+
182192 std::vector<char *> vm_args;
183193
194+ uint32_t sys_thread_count;
195+ uint32_t thread_quanta;
196+
184197 bool print_help;
185198 bool quiet_start;
186199 bool enabled_debugger;
@@ -189,10 +202,15 @@ struct exec_options · 2 unmodified lines
189202
190203 void print_banner(const exec_options &options)
191204 {
205+ std::cout << "DisVM " << DISVM_VERSION_MAJOR << '.' << DISVM_VERSION_MINOR << '.' << DISVM_VERSION_PATCH;
206+
207+ if (DISVM_VERSION_LABEL != nullptr)
208+ std::cout << '-' << DISVM_VERSION_LABEL;
209+
192210 std::cout
193− << "DisVM\n"
194− << "----------------\n"
195− << "Debugger enabled: " << std::boolalpha << options.enabled_debugger << "\n";
211+ << "\n----------------\n"
212+ << "Debugger enabled: " << std::boolalpha << options.enabled_debugger << "\n"
213+ << "System thread usage: " << options.sys_thread_count << "\n";
196214
197215 if (options.enabled_debugger)
198216 std::cout << options.debugger << "\n";
@@ -203,12 +221,13 @@ void print_banner(const exec_options &options) · 4 unmodified lines
203221 void print_help()
204222 {
205223 std::cout
206− << "Usage: disvm-exec [-d[e|m|x]*] [-q] [-?] <entry module> <args>*\n"
224+ << "Usage: disvm-exec [-d[e|m|x]*] [-t <num>] [-q] [-?] <entry module> <args>*\n"
207225 << " d - Enable debugger\n"
208226 << " e - Break on entry\n"
209227 << " m - Break on module load\n"
210228 << " x - Break on exception (first chance)\n"
211229 << " q - Suppress banner and configuration\n"
230+ << " t - Specify the number of system threads to use (0 < x <= 4)\n"
212231 << " ? - Print help\n";
213232 }
214233
@@ -243,7 +262,21 @@ void process_arg(char* arg, std::function<char *()> next, exec_options &options) · 28 unmodified lines
243262 break;
244263 }
245264 }
265+ break;
266+
267+ case 't':
268+ {
269+ auto sys_threads_str = next();
270+ if (sys_threads_str == nullptr)
271+ throw arg_exception_t{ "System thread requires count" };
246272
273+ char *end;
274+ auto sys_threads = ::strtol(sys_threads_str, &end, 10);
275+ if (sys_threads <= 0 || 4 < sys_threads)
276+ throw arg_exception_t{ "Invalid system thread value", sys_threads_str };
277+
278+ options.sys_thread_count = sys_threads;
279+ }
247280 break;
248281
249282 case 'q':
@@ -293,7 +326,7 @@ int main(int argc, char* argv[]) · 43 unmodified lines
293326 return EXIT_SUCCESS;
294327 }
295328
296− vm_t vm;
329+ vm_t vm{ options.sys_thread_count, options.thread_quanta };
297330
298331 if (options.enabled_debugger)
299332 vm.load_tool(std::make_shared<debugger>(options.debugger));