Skip to content

Commit

Permalink
improve performance by asserting async_event for debugger instead of …
Browse files Browse the repository at this point in the history
…checking for bx_dbg.debugger_active every instruction
  • Loading branch information
Stanislav Shwartsman committed Nov 23, 2024
1 parent dcf961d commit aa215ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
30 changes: 16 additions & 14 deletions bochs/cpu/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ void BX_CPU_C::cpu_loop_debugger(void)
BX_CPU_THIS_PTR prev_rip = RIP; // commit new EIP
BX_CPU_THIS_PTR speculative_rsp = false;

// stop tracing after every instruction to handle in internal debugger
BX_CPU_THIS_PTR async_event |= BX_ASYNC_EVENT_STOP_TRACE;

while (1) {

// 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) {
Bit32u handle_event = BX_CPU_THIS_PTR async_event & ~BX_ASYNC_EVENT_STOP_TRACE;
if (handle_event) {
if (handleAsyncEvent()) {
// If request to return to caller ASAP.
return;
Expand Down Expand Up @@ -116,10 +120,6 @@ void BX_CPU_C::cpu_loop_debugger(void)
last = i + (entry->tlen);
}
}

// clear stop trace magic indication that probably was set by repeat or branch32/64
BX_CPU_THIS_PTR async_event &= ~BX_ASYNC_EVENT_STOP_TRACE;

} // while (1)
}
#endif // BX_DEBUGGER
Expand Down Expand Up @@ -413,6 +413,8 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat(bxInstruction_c *i, BxRepIterationP
return;
}

BX_ASSERT(! bx_dbg.debugger_active || BX_CPU_THIS_PTR async_event);

BX_CPU_THIS_PTR clear_RF();

#if BX_SUPPORT_X86_64
Expand All @@ -425,7 +427,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat(bxInstruction_c *i, BxRepIterationP
}
if (RCX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -444,7 +446,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat(bxInstruction_c *i, BxRepIterationP
}
if (ECX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -462,7 +464,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat(bxInstruction_c *i, BxRepIterationP
}
if (CX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand Down Expand Up @@ -502,7 +504,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (! get_ZF() || RCX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -521,7 +523,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (! get_ZF() || ECX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -539,7 +541,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (! get_ZF() || CX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -559,7 +561,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (get_ZF() || RCX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -578,7 +580,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (get_ZF() || ECX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand All @@ -596,7 +598,7 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::repeat_ZF(bxInstruction_c *i, BxRepIterati
}
if (get_ZF() || CX == 0) return;

if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active)
if (BX_CPU_THIS_PTR async_event)
break; // exit always if debugger enabled

BX_CPU_THIS_PTR icount++;
Expand Down
2 changes: 1 addition & 1 deletion bochs/cpu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5871,7 +5871,7 @@ class bxInstruction_c;

#define BX_NEXT_INSTR(i) { \
BX_COMMIT_INSTRUCTION(i); \
if (BX_CPU_THIS_PTR async_event || bx_dbg.debugger_active) return; \
if (BX_CPU_THIS_PTR async_event) return; \
++i; \
BX_EXECUTE_INSTRUCTION(i); \
}
Expand Down
4 changes: 2 additions & 2 deletions bochs/cpu/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSW32_YwDX(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event)
{
Bit32u wordCount = ECX;
BX_ASSERT(wordCount > 0);
Expand Down Expand Up @@ -583,7 +583,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::OUTSW32_DXXw(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active) {
if (i->repUsedL() && !BX_CPU_THIS_PTR async_event) {
Bit32u wordCount = ECX;
wordCount = FastRepOUTSW(i->seg(), esi, DX, wordCount);
if (wordCount) {
Expand Down
14 changes: 7 additions & 7 deletions bochs/cpu/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOVSB32_YbXb(bxInstruction_c *i)
#if BX_SUPPORT_REPEAT_SPEEDUPS
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time */
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepMOVSB(i->seg(), ESI, BX_SEG_REG_ES, EDI, ECX, 1);
if (byteCount) {
Expand Down Expand Up @@ -174,7 +174,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOVSB64_YbXb(bxInstruction_c *i)
#if BX_SUPPORT_REPEAT_SPEEDUPS
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time */
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepMOVSB(get_laddr64(i->seg(), rsi), rdi, ECX, 1);
if (byteCount) {
Expand Down Expand Up @@ -309,7 +309,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOVSD32_YdXd(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepMOVSB(i->seg(), esi, BX_SEG_REG_ES, edi, ECX*4, 4);
if (byteCount) {
Expand Down Expand Up @@ -357,7 +357,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOVSD64_YdXd(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepMOVSB(get_laddr64(i->seg(), rsi), rdi, ECX*4, 4);
if (byteCount) {
Expand Down Expand Up @@ -425,7 +425,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOVSQ64_YqXq(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepMOVSB(get_laddr64(i->seg(), rsi), rdi, ECX*8, 8);
if (byteCount) {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::STOSB32_YbAL(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepSTOSB(BX_SEG_REG_ES, edi, AL, ECX);
if (byteCount) {
Expand Down Expand Up @@ -1349,7 +1349,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::STOSB64_YbAL(bxInstruction_c *i)
/* If conditions are right, we can transfer IO to physical memory
* in a batch, rather than one instruction at a time.
*/
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event && !bx_dbg.debugger_active)
if (i->repUsedL() && !BX_CPU_THIS_PTR get_DF() && !BX_CPU_THIS_PTR async_event)
{
Bit32u byteCount = FastRepSTOSB(rdi, AL, ECX);
if (byteCount) {
Expand Down

0 comments on commit aa215ce

Please sign in to comment.