From patchwork Fri Nov 7 10:33:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 408054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B487914012A for ; Fri, 7 Nov 2014 21:42:20 +1100 (AEDT) Received: from localhost ([::1]:59403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmgzh-0001Tw-S9 for incoming@patchwork.ozlabs.org; Fri, 07 Nov 2014 05:42:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmgqz-0003Od-Pm for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:33:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xmgqt-0000R4-Vk for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:33:17 -0500 Received: from mail.ispras.ru ([83.149.199.45]:49215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmgqt-0000Qx-Kp for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:33:11 -0500 Received: from [10.10.150.171] (unknown [85.142.117.224]) by mail.ispras.ru (Postfix) with ESMTPSA id D2018540151; Fri, 7 Nov 2014 13:33:10 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Fri, 07 Nov 2014 13:33:15 +0300 Message-ID: <20141107103315.6136.46350.stgit@PASHA-ISP> In-Reply-To: <20141107103123.6136.18545.stgit@PASHA-ISP> References: <20141107103123.6136.18545.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.45 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, alex.bennee@linaro.org, mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru, maria.klimushenkova@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH v4 19/25] replay: checkpoints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch introduces checkpoints that synchronize cpu thread and iothread. When checkpoint is met in the code all asynchronous events from the queue are executed. Signed-off-by: Pavel Dovgalyuk --- block.c | 11 +++++++++++ cpus.c | 2 +- include/qemu/timer.h | 6 ++++-- qemu-timer.c | 41 +++++++++++++++++++++++++++++++++-------- replay/replay-internal.h | 3 +++ replay/replay.c | 28 ++++++++++++++++++++++++++++ replay/replay.h | 6 ++++++ stubs/replay.c | 11 +++++++++++ vl.c | 3 ++- 9 files changed, 99 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index 88f6d9b..cc84050 100644 --- a/block.c +++ b/block.c @@ -1919,6 +1919,11 @@ void bdrv_drain_all(void) BlockDriverState *bs; while (busy) { + if (!replay_checkpoint(8)) { + /* Do not wait anymore, we stopped at some place in + the middle of execution during replay */ + return; + } busy = false; QTAILQ_FOREACH(bs, &bdrv_states, device_list) { @@ -1935,6 +1940,12 @@ void bdrv_drain_all(void) busy |= bs_busy; } } + if (replay_mode == REPLAY_MODE_PLAY) { + /* Skip checkpoints from the log */ + while (replay_checkpoint(8)) { + /* Nothing */ + } + } } /* make a BlockDriverState anonymous by removing from bdrv_state and diff --git a/cpus.c b/cpus.c index b7a25fd..6adff2b 100644 --- a/cpus.c +++ b/cpus.c @@ -406,7 +406,7 @@ void qtest_clock_warp(int64_t dest) timers_state.qemu_icount_bias += warp; seqlock_write_unlock(&timers_state.vm_clock_seqlock); - qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); + qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL, false); clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } qemu_clock_notify(QEMU_CLOCK_VIRTUAL); diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 7b43331..5eaf77a 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -232,13 +232,14 @@ void qemu_clock_unregister_reset_notifier(QEMUClockType type, /** * qemu_clock_run_timers: * @type: clock on which to operate + * @run_all: true, when called from qemu_clock_run_all_timers * * Run all the timers associated with the default timer list * of a clock. * * Returns: true if any timer ran. */ -bool qemu_clock_run_timers(QEMUClockType type); +bool qemu_clock_run_timers(QEMUClockType type, bool run_all); /** * qemu_clock_run_all_timers: @@ -329,12 +330,13 @@ QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list); /** * timerlist_run_timers: * @timer_list: the timer list to use + * @run_all: true, when called from qemu_clock_run_all_timers * * Call all expired timers associated with the timer list. * * Returns: true if any timer expired */ -bool timerlist_run_timers(QEMUTimerList *timer_list); +bool timerlist_run_timers(QEMUTimerList *timer_list, bool run_all); /** * timerlist_notify: diff --git a/qemu-timer.c b/qemu-timer.c index 8307913..b06aa4a 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -458,7 +458,7 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time) return timer_expired_ns(timer_head, current_time * timer_head->scale); } -bool timerlist_run_timers(QEMUTimerList *timer_list) +bool timerlist_run_timers(QEMUTimerList *timer_list, bool run_all) { QEMUTimer *ts; int64_t current_time; @@ -466,6 +466,24 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) QEMUTimerCB *cb; void *opaque; + switch (timer_list->clock->type) { + case QEMU_CLOCK_REALTIME: + break; + default: + case QEMU_CLOCK_VIRTUAL: + if ((replay_mode != REPLAY_MODE_NONE && !runstate_is_running()) + || !replay_checkpoint(run_all ? 2 : 3)) { + return false; + } + break; + case QEMU_CLOCK_HOST: + if ((replay_mode != REPLAY_MODE_NONE && !runstate_is_running()) + || !replay_checkpoint(run_all ? 5 : 6)) { + return false; + } + break; + } + qemu_event_reset(&timer_list->timers_done_ev); if (!timer_list->clock->enabled) { goto out; @@ -498,9 +516,9 @@ out: return progress; } -bool qemu_clock_run_timers(QEMUClockType type) +bool qemu_clock_run_timers(QEMUClockType type, bool run_all) { - return timerlist_run_timers(main_loop_tlg.tl[type]); + return timerlist_run_timers(main_loop_tlg.tl[type], run_all); } void timerlistgroup_init(QEMUTimerListGroup *tlg, @@ -525,7 +543,7 @@ bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg) QEMUClockType type; bool progress = false; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - progress |= timerlist_run_timers(tlg->tl[type]); + progress |= timerlist_run_timers(tlg->tl[type], false); } return progress; } @@ -534,11 +552,18 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg) { int64_t deadline = -1; QEMUClockType type; + bool play = replay_mode == REPLAY_MODE_PLAY; for (type = 0; type < QEMU_CLOCK_MAX; type++) { if (qemu_clock_use_for_deadline(tlg->tl[type]->clock->type)) { - deadline = qemu_soonest_timeout(deadline, - timerlist_deadline_ns( - tlg->tl[type])); + if (!play || tlg->tl[type]->clock->type == QEMU_CLOCK_REALTIME) { + deadline = qemu_soonest_timeout(deadline, + timerlist_deadline_ns( + tlg->tl[type])); + } else { + /* Read clock from the replay file and + do not calculate the deadline, based on virtual clock. */ + qemu_clock_get_ns(tlg->tl[type]->clock->type); + } } } return deadline; @@ -606,7 +631,7 @@ bool qemu_clock_run_all_timers(void) QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - progress |= qemu_clock_run_timers(type); + progress |= qemu_clock_run_timers(type, true); } return progress; diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 94487fb..e73fa7a 100755 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -32,6 +32,9 @@ #define EVENT_CLOCK 64 /* some of grteater codes are reserved for clocks */ +/* for checkpoint event */ +#define EVENT_CHECKPOINT 96 + /* Asynchronous events IDs */ #define REPLAY_ASYNC_COUNT 0 diff --git a/replay/replay.c b/replay/replay.c index c118f62..54e1c4e 100755 --- a/replay/replay.c +++ b/replay/replay.c @@ -150,3 +150,31 @@ void replay_shutdown_request(void) replay_put_event(EVENT_SHUTDOWN); } } + +/* Used checkpoints: 2 3 5 6 7 8 9 */ +int replay_checkpoint(unsigned int checkpoint) +{ + replay_save_instructions(); + + if (replay_file) { + if (replay_mode == REPLAY_MODE_PLAY) { + if (!skip_async_events(EVENT_CHECKPOINT + checkpoint)) { + if (replay_data_kind == EVENT_ASYNC_OPT) { + replay_read_events(checkpoint); + replay_fetch_data_kind(); + return replay_data_kind != EVENT_ASYNC_OPT; + } + return 0; + } + replay_has_unread_data = 0; + replay_read_events(checkpoint); + replay_fetch_data_kind(); + return replay_data_kind != EVENT_ASYNC_OPT; + } else if (replay_mode == REPLAY_MODE_RECORD) { + replay_put_event(EVENT_CHECKPOINT + checkpoint); + replay_save_events(checkpoint); + } + } + + return 1; +} diff --git a/replay/replay.h b/replay/replay.h index 8963e4e..e76c541 100755 --- a/replay/replay.h +++ b/replay/replay.h @@ -80,6 +80,12 @@ void replay_read_tm(struct tm *tm); /*! Called when qemu shutdown is requested. */ void replay_shutdown_request(void); +/*! Should be called at check points in the execution. + These check points are skipped, if they were not met. + Saves checkpoint in the SAVE mode and validates in the PLAY mode. + Returns 0 in PLAY mode if checkpoint was not found. + Returns 1 in all other cases. */ +int replay_checkpoint(unsigned int checkpoint); /* Asynchronous events queue */ diff --git a/stubs/replay.c b/stubs/replay.c index f3f60fe..ab9ede9 100755 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -1,4 +1,5 @@ #include "replay/replay.h" +#include "sysemu/sysemu.h" ReplayMode replay_mode; @@ -15,3 +16,13 @@ int64_t replay_read_clock(unsigned int kind) { return 0; } + +int replay_checkpoint(unsigned int checkpoint) +{ + return 0; +} + +int runstate_is_running(void) +{ + return 0; +} diff --git a/vl.c b/vl.c index 4155342..717d67e 100644 --- a/vl.c +++ b/vl.c @@ -1847,7 +1847,8 @@ static bool main_loop_should_exit(void) return true; } } - if (qemu_reset_requested()) { + if (qemu_reset_requested_get() && replay_checkpoint(7)) { + qemu_reset_requested(); pause_all_vcpus(); cpu_synchronize_all_states(); qemu_system_reset(VMRESET_REPORT);