From 7bbfee58a20b051e4e30d8ccd37fa1fd77c4257e Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Mon, 15 Aug 2011 10:37:41 +0000 Subject: [PATCH] - usually the realtime synchronization keeps the PIT-based system clock in sync with the host time. After using a runtime config dialog or save and restore simulation, this behaviour makes the PIT clock and the VGA update timer running way too fast until it's back in sync. Now the elapsed time is stored in the variable 'real_time_delay' and it is used to let the PIT clock run at realtime speed, even if it is out of sync. --- bochs/gui/siminterface.cc | 2 ++ bochs/iodev/devices.cc | 1 + bochs/iodev/virt_timer.cc | 19 +++++++++++-------- bochs/iodev/virt_timer.h | 5 +++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index ccc6d32be..32b6f00b5 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -26,6 +26,7 @@ #include "param_names.h" #include "iodev.h" +#include "virt_timer.h" bx_simulator_interface_c *SIM = NULL; logfunctions *siminterface_log = NULL; @@ -835,6 +836,7 @@ void bx_real_sim_c::update_runtime_options() temp = temp->next; } bx_gui->update_drive_status_buttons(); + bx_virt_timer.set_realtime_delay(); } bx_bool bx_real_sim_c::is_sim_thread() diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index d7d2f679c..f3cac16f5 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -427,6 +427,7 @@ void bx_devices_c::register_state() void bx_devices_c::after_restore_state() { bx_slowdown_timer.after_restore_state(); + bx_virt_timer.set_realtime_delay(); #if BX_SUPPORT_PCI if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) { pluginPciBridge->after_restore_state(); diff --git a/bochs/iodev/virt_timer.cc b/bochs/iodev/virt_timer.cc index 5055027a4..5aafbc68c 100644 --- a/bochs/iodev/virt_timer.cc +++ b/bochs/iodev/virt_timer.cc @@ -93,13 +93,8 @@ //Debug with printf options. #define DEBUG_REALTIME_WITH_PRINTF 0 -//Use to test execution at multiples of real time. -#define TIME_DIVIDER (1) -#define TIME_MULTIPLIER (1) -#define TIME_HEADSTART (0) - -#define GET_VIRT_REALTIME64_USEC() (((bx_get_realtime64_usec()*(Bit64u)TIME_MULTIPLIER/(Bit64u)TIME_DIVIDER))) +#define GET_VIRT_REALTIME64_USEC() (bx_get_realtime64_usec()) //Set up Logging. #define LOG_THIS bx_virt_timer. @@ -398,10 +393,11 @@ void bx_virt_timer_c::init(void) //Real time variables: #if BX_HAVE_REALTIME_USEC - last_real_time = GET_VIRT_REALTIME64_USEC()+(Bit64u)TIME_HEADSTART*(Bit64u)USEC_PER_SECOND; + last_real_time = GET_VIRT_REALTIME64_USEC(); #endif total_real_usec = 0; last_realtime_delta = 0; + real_time_delay = 0; //System time variables: last_usec = 0; usec_per_second = USEC_PER_SECOND; @@ -474,7 +470,7 @@ void bx_virt_timer_c::timer_handler(void) if (usec_delta) { #if BX_HAVE_REALTIME_USEC Bit64u ticks_delta = 0; - Bit64u real_time_delta = GET_VIRT_REALTIME64_USEC() - last_real_time; + Bit64u real_time_delta = GET_VIRT_REALTIME64_USEC() - last_real_time - real_time_delay; Bit64u real_time_total = real_time_delta + total_real_usec; Bit64u system_time_delta = (Bit64u)usec_delta + (Bit64u)stored_delta; if(real_time_delta) { @@ -563,3 +559,10 @@ void bx_virt_timer_c::pc_system_timer_handler(void* this_ptr) { ((bx_virt_timer_c *)this_ptr)->timer_handler(); } + +void bx_virt_timer_c::set_realtime_delay() +{ + if (virtual_timers_realtime) { + real_time_delay = GET_VIRT_REALTIME64_USEC() - last_real_time; + } +} diff --git a/bochs/iodev/virt_timer.h b/bochs/iodev/virt_timer.h index 936ddd693..cdbe841ca 100644 --- a/bochs/iodev/virt_timer.h +++ b/bochs/iodev/virt_timer.h @@ -62,6 +62,7 @@ private: Bit64u last_real_time; Bit64u total_real_usec; Bit64u last_realtime_delta; + Bit64u real_time_delay; //System time variables: Bit64u last_usec; Bit64u usec_per_second; @@ -147,6 +148,10 @@ public: void init(void); void register_state(void); + + //Determine the real time elapsed during runtime config or between save and + //restore. + void set_realtime_delay(void); }; BOCHSAPI extern bx_virt_timer_c bx_virt_timer;