Use more precise timestamps for slowdown_timer (#377)

Should fix #228.

Co-authored-by: Volker Ruppert <Volker.Ruppert@t-online.de>
This commit is contained in:
Vort 2024-11-05 10:19:58 +02:00 committed by GitHub
parent 905293b6f2
commit 5daba7ed43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -59,6 +59,15 @@ bx_slowdown_timer_c::bx_slowdown_timer_c()
s.timer_handle=BX_NULL_TIMER_HANDLE; s.timer_handle=BX_NULL_TIMER_HANDLE;
} }
Bit64u bx_slowdown_timer_c::get_realtime_usec()
{
#if BX_HAVE_REALTIME_USEC
return bx_get_realtime64_usec();
#else
return sectousec(time(NULL));
#endif
}
void bx_slowdown_timer_c::init(void) void bx_slowdown_timer_c::init(void)
{ {
// Return early if slowdown timer not selected // Return early if slowdown timer not selected
@ -73,7 +82,7 @@ void bx_slowdown_timer_c::init(void)
if(s.MAXmultiplier<1) if(s.MAXmultiplier<1)
s.MAXmultiplier=1; s.MAXmultiplier=1;
s.start_time = sectousec(time(NULL)); s.start_time = get_realtime_usec();
s.start_emulated_time = bx_pc_system.time_usec(); s.start_emulated_time = bx_pc_system.time_usec();
s.lasttime=0; s.lasttime=0;
if (s.timer_handle == BX_NULL_TIMER_HANDLE) { if (s.timer_handle == BX_NULL_TIMER_HANDLE) {
@ -103,7 +112,7 @@ void bx_slowdown_timer_c::handle_timer()
{ {
Bit64u total_emu_time = (bx_pc_system.time_usec()) - s.start_emulated_time; Bit64u total_emu_time = (bx_pc_system.time_usec()) - s.start_emulated_time;
Bit64u wanttime = s.lasttime+s.Q; Bit64u wanttime = s.lasttime+s.Q;
Bit64u totaltime = sectousec(time(NULL)) - s.start_time; Bit64u totaltime = get_realtime_usec() - s.start_time;
Bit64u thistime=(wanttime>totaltime)?wanttime:totaltime; Bit64u thistime=(wanttime>totaltime)?wanttime:totaltime;
#if BX_SLOWDOWN_PRINTF_FEEDBACK #if BX_SLOWDOWN_PRINTF_FEEDBACK

View File

@ -35,6 +35,8 @@ private:
Bit64u Q; // sleep rate in usec Bit64u Q; // sleep rate in usec
} s; } s;
Bit64u get_realtime_usec();
public: public:
bx_slowdown_timer_c(); bx_slowdown_timer_c();