Skip to content

Commit

Permalink
icount: improve counting for record/replay
Browse files Browse the repository at this point in the history
icount_warp_rt function is called by qemu_clock_warp and as
callback of icount_warp timer. This patch adds call to qemu_clock_warp
into main_loop_wait function, because icount warp may be missed
in record/replay mode, when CPU is sleeping.
This patch also disables of calling this function by timer, because
it is not needed after making modifications of main_loop_wait.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20150917162439.8676.38290.stgit@PASHA-ISP.def.inno>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
  • Loading branch information
Dovgalyuk authored and bonzini committed Nov 6, 2015
1 parent b60c48a commit efab87c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static int64_t qemu_icount_round(int64_t count)
return (count + (1 << icount_time_shift) - 1) >> icount_time_shift;
}

static void icount_warp_rt(void *opaque)
static void icount_warp_rt(void)
{
/* The icount_warp_timer is rescheduled soon after vm_clock_warp_start
* changes from -1 to another value, so the race here is okay.
Expand Down Expand Up @@ -370,6 +370,11 @@ static void icount_warp_rt(void *opaque)
}
}

static void icount_dummy_timer(void *opaque)
{
(void)opaque;
}

void qtest_clock_warp(int64_t dest)
{
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
Expand Down Expand Up @@ -414,7 +419,7 @@ void qemu_clock_warp(QEMUClockType type)
* the CPU starts running, in case the CPU is woken by an event other
* than the earliest QEMU_CLOCK_VIRTUAL timer.
*/
icount_warp_rt(NULL);
icount_warp_rt();
timer_del(icount_warp_timer);
}
if (!all_cpu_threads_idle()) {
Expand Down Expand Up @@ -607,7 +612,7 @@ void configure_icount(QemuOpts *opts, Error **errp)
icount_sleep = qemu_opt_get_bool(opts, "sleep", true);
if (icount_sleep) {
icount_warp_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
icount_warp_rt, NULL);
icount_dummy_timer, NULL);
}

icount_align_option = qemu_opt_get_bool(opts, "align", false);
Expand Down
3 changes: 3 additions & 0 deletions main-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ int main_loop_wait(int nonblocking)
slirp_pollfds_poll(gpollfds, (ret < 0));
#endif

/* CPU thread can infinitely wait for event after
missing the warp */
qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
qemu_clock_run_all_timers();

return ret;
Expand Down

0 comments on commit efab87c

Please sign in to comment.