patch by Luigu.B - significantly speedup multi-threaded guest simulation

This commit is contained in:
Stanislav Shwartsman 2019-08-09 19:57:13 +00:00
parent 2eb47f866f
commit 2ae332cce8
3 changed files with 16 additions and 10 deletions

View File

@ -26,6 +26,8 @@
#include "cpustats.h"
jmp_buf BX_CPU_C::jmp_buf_env;
void BX_CPU_C::cpu_loop(void)
{
#if BX_DEBUGGER
@ -134,12 +136,6 @@ void BX_CPU_C::cpu_loop(void)
void BX_CPU_C::cpu_run_trace(void)
{
if (setjmp(BX_CPU_THIS_PTR jmp_buf_env)) {
// can get here only from exception function or VMEXIT
BX_CPU_THIS_PTR icount++;
return;
}
// check on events which occurred for previous instructions (traps)
// and ones which are asynchronous to the CPU (hardware interrupts)
if (BX_CPU_THIS_PTR async_event) {

View File

@ -1216,7 +1216,7 @@ public: // for now...
#endif
// for exceptions
jmp_buf jmp_buf_env;
static jmp_buf jmp_buf_env;
unsigned last_exception_type;
// Boundaries of current code page, based on EIP

View File

@ -1060,14 +1060,22 @@ int bx_begin_simulation(int argc, char *argv[])
static int quantum = SIM->get_param_num(BXPN_SMP_QUANTUM)->get();
Bit32u executed = 0, processor = 0;
bool run = true;
if (setjmp(BX_CPU_C::jmp_buf_env)) {
// can get here only from exception function or VMEXIT
BX_CPU(processor)->icount++;
run = false;
}
while (1) {
// do some instructions in each processor
Bit64u icount = BX_CPU(processor)->icount_last_sync = BX_CPU(processor)->get_icount();
BX_CPU(processor)->cpu_run_trace();
if (run)
BX_CPU(processor)->cpu_run_trace();
else
run = true;
// see how many instruction it was able to run
Bit32u n = (Bit32u)(BX_CPU(processor)->get_icount() - icount);
Bit32u n = (Bit32u)(BX_CPU(processor)->get_icount() - BX_CPU(processor)->icount_last_sync);
if (n == 0) n = quantum; // the CPU was halted
executed += n;
@ -1077,6 +1085,8 @@ int bx_begin_simulation(int argc, char *argv[])
executed %= BX_SMP_PROCESSORS;
}
BX_CPU(processor)->icount_last_sync = BX_CPU(processor)->get_icount();
if (bx_pc_system.kill_bochs_request)
break;
}