From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org,
igor.rubinov@gmail.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, hines@cert.org, fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH v17 14/21] replay: checkpoints
Date: Mon, 07 Sep 2015 11:41:28 +0300 [thread overview]
Message-ID: <20150907084127.1664.46493.stgit@PASHA-ISP> (raw)
In-Reply-To: <20150907084005.1664.19540.stgit@PASHA-ISP>
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 <pavel.dovgaluk@ispras.ru>
---
cpus.c | 5 +++++
qemu-timer.c | 40 ++++++++++++++++++++++++++++++++++++----
replay/replay-internal.h | 4 ++++
replay/replay.c | 34 ++++++++++++++++++++++++++++++++++
replay/replay.h | 20 ++++++++++++++++++++
stubs/replay.c | 11 +++++++++++
vl.c | 23 +++++++++++++++++++----
7 files changed, 129 insertions(+), 8 deletions(-)
diff --git a/cpus.c b/cpus.c
index 00d50f1..4f0bcce 100644
--- a/cpus.c
+++ b/cpus.c
@@ -402,6 +402,11 @@ void qemu_clock_warp(QEMUClockType type)
return;
}
+ /* warp clock deterministically in record/replay mode */
+ if (!replay_checkpoint(CHECKPOINT_CLOCK_WARP)) {
+ return;
+ }
+
if (icount_sleep) {
/*
* If the CPUs have been sleeping, advance QEMU_CLOCK_VIRTUAL timer now.
diff --git a/qemu-timer.c b/qemu-timer.c
index c7bd643..e7a5c96 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -25,6 +25,7 @@
#include "qemu/main-loop.h"
#include "qemu/timer.h"
#include "replay/replay.h"
+#include "sysemu/sysemu.h"
#ifdef CONFIG_POSIX
#include <pthread.h>
@@ -478,10 +479,34 @@ bool timerlist_run_timers(QEMUTimerList *timer_list)
void *opaque;
qemu_event_reset(&timer_list->timers_done_ev);
- if (!timer_list->clock->enabled) {
+ if (!timer_list->clock->enabled || !timer_list->active_timers) {
goto out;
}
+ 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(CHECKPOINT_CLOCK_VIRTUAL)) {
+ goto out;
+ }
+ break;
+ case QEMU_CLOCK_HOST:
+ if ((replay_mode != REPLAY_MODE_NONE && !runstate_is_running())
+ || !replay_checkpoint(CHECKPOINT_CLOCK_HOST)) {
+ goto out;
+ }
+ break;
+ case QEMU_CLOCK_VIRTUAL_RT:
+ if ((replay_mode != REPLAY_MODE_NONE && !runstate_is_running())
+ || !replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) {
+ goto out;
+ }
+ break;
+ }
+
current_time = qemu_clock_get_ns(timer_list->clock->type);
for(;;) {
qemu_mutex_lock(&timer_list->active_timers_lock);
@@ -545,11 +570,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;
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index 4414695..bf64be5 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -29,6 +29,10 @@ enum ReplayEvents {
/* some of greater codes are reserved for clocks */
EVENT_CLOCK,
EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
+ /* for checkpoint event */
+ /* some of greater codes are reserved for checkpoints */
+ EVENT_CHECKPOINT,
+ EVENT_CHECKPOINT_LAST = EVENT_CHECKPOINT + CHECKPOINT_COUNT - 1,
EVENT_COUNT
};
diff --git a/replay/replay.c b/replay/replay.c
index 83b0f8c..ca9996e 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -160,3 +160,37 @@ void replay_shutdown_request(void)
replay_mutex_unlock();
}
}
+
+bool replay_checkpoint(ReplayCheckpoint checkpoint)
+{
+ bool res = false;
+ assert(EVENT_CHECKPOINT + checkpoint <= EVENT_CHECKPOINT_LAST);
+ replay_save_instructions();
+
+ if (!replay_file) {
+ return true;
+ }
+
+ replay_mutex_lock();
+
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ if (replay_next_event_is(EVENT_CHECKPOINT + checkpoint)) {
+ replay_finish_event();
+ } else if (replay_data_kind != EVENT_ASYNC) {
+ res = false;
+ goto out;
+ }
+ replay_read_events(checkpoint);
+ /* replay_read_events may leave some unread events.
+ Return false if not all of the events associated with
+ checkpoint were processed */
+ res = replay_data_kind != EVENT_ASYNC;
+ } else if (replay_mode == REPLAY_MODE_RECORD) {
+ replay_put_event(EVENT_CHECKPOINT + checkpoint);
+ replay_save_events(checkpoint);
+ res = true;
+ }
+out:
+ replay_mutex_unlock();
+ return res;
+}
diff --git a/replay/replay.h b/replay/replay.h
index fcc93d1..e2696fe 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -26,6 +26,20 @@ enum ReplayClockKind {
};
typedef enum ReplayClockKind ReplayClockKind;
+/* IDs of the checkpoints */
+enum ReplayCheckpoint {
+ CHECKPOINT_CLOCK_WARP,
+ CHECKPOINT_RESET_REQUESTED,
+ CHECKPOINT_SUSPEND_REQUESTED,
+ CHECKPOINT_CLOCK_VIRTUAL,
+ CHECKPOINT_CLOCK_HOST,
+ CHECKPOINT_CLOCK_VIRTUAL_RT,
+ CHECKPOINT_INIT,
+ CHECKPOINT_RESET,
+ CHECKPOINT_COUNT
+};
+typedef enum ReplayCheckpoint ReplayCheckpoint;
+
extern ReplayMode replay_mode;
/* Processing the instructions */
@@ -70,6 +84,12 @@ int64_t replay_read_clock(ReplayClockKind kind);
/*! 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. */
+bool replay_checkpoint(ReplayCheckpoint checkpoint);
/* Asynchronous events queue */
diff --git a/stubs/replay.c b/stubs/replay.c
index 3e7c3fe..e737dad 100755
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -1,5 +1,6 @@
#include "replay/replay.h"
#include <stdlib.h>
+#include "sysemu/sysemu.h"
ReplayMode replay_mode;
@@ -14,3 +15,13 @@ int64_t replay_read_clock(unsigned int kind)
abort();
return 0;
}
+
+bool replay_checkpoint(ReplayCheckpoint checkpoint)
+{
+ return 0;
+}
+
+int runstate_is_running(void)
+{
+ return 0;
+}
diff --git a/vl.c b/vl.c
index 9ff801d..c461a98 100644
--- a/vl.c
+++ b/vl.c
@@ -122,6 +122,7 @@ int main(int argc, char **argv)
#include "qapi-event.h"
#include "exec/semihost.h"
#include "crypto/init.h"
+#include "replay/replay.h"
#define MAX_VIRTIO_CONSOLES 1
#define MAX_SCLP_CONSOLES 1
@@ -1661,15 +1662,21 @@ static void qemu_kill_report(void)
static int qemu_reset_requested(void)
{
int r = reset_requested;
- reset_requested = 0;
- return r;
+ if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) {
+ reset_requested = 0;
+ return r;
+ }
+ return false;
}
static int qemu_suspend_requested(void)
{
int r = suspend_requested;
- suspend_requested = 0;
- return r;
+ if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) {
+ suspend_requested = 0;
+ return r;
+ }
+ return false;
}
static WakeupReason qemu_wakeup_requested(void)
@@ -4500,6 +4507,10 @@ int main(int argc, char **argv, char **envp)
}
qemu_add_globals();
+ /* This checkpoint is required by replay to separate prior clock
+ reading from the other reads, because timer polling functions query
+ clock values from the log. */
+ replay_checkpoint(CHECKPOINT_INIT);
qdev_machine_init();
current_machine->ram_size = ram_size;
@@ -4615,6 +4626,10 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
+ /* This checkpoint is required by replay to separate prior clock
+ reading from the other reads, because timer polling functions query
+ clock values from the log. */
+ replay_checkpoint(CHECKPOINT_RESET);
qemu_system_reset(VMRESET_SILENT);
register_global_state();
if (loadvm) {
next prev parent reply other threads:[~2015-09-07 8:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 8:40 [Qemu-devel] [PATCH v17 00/21] Deterministic replay core Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 01/21] i386: partial revert of interrupt poll fix Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 02/21] replay: global variables and function stubs Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 03/21] replay: internal functions for replay log Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 04/21] replay: introduce mutex to protect the " Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 05/21] replay: introduce icount event Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 06/21] cpu-exec: allow temporary disabling icount Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 07/21] cpu: replay instructions sequence Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 08/21] i386: interrupt poll processing Pavel Dovgalyuk
2015-09-07 8:40 ` [Qemu-devel] [PATCH v17 09/21] replay: interrupts and exceptions Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 10/21] replay: asynchronous events infrastructure Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 11/21] replay: recording and replaying clock ticks Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 12/21] replay: shutdown event Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 13/21] icount: improve counting for record/replay Pavel Dovgalyuk
2015-09-07 8:41 ` Pavel Dovgalyuk [this message]
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 15/21] bottom halves: introduce bh call function Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 16/21] replay: ptimer Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 17/21] typedef: add typedef for QemuOpts Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 18/21] replay: initialization and deinitialization Pavel Dovgalyuk
2015-09-07 8:41 ` [Qemu-devel] [PATCH v17 19/21] replay: replay blockers for devices Pavel Dovgalyuk
2015-09-07 8:42 ` [Qemu-devel] [PATCH v17 20/21] replay: command line options Pavel Dovgalyuk
2015-09-07 8:42 ` [Qemu-devel] [PATCH v17 21/21] replay: recording of the user input Pavel Dovgalyuk
2015-09-11 5:52 ` [Qemu-devel] [PATCH v17 00/21] Deterministic replay core Pavel Dovgaluk
[not found] ` <45193.409038666$1441951862@news.gmane.org>
2015-09-11 6:31 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150907084127.1664.46493.stgit@PASHA-ISP \
--to=pavel.dovgaluk@ispras.ru \
--cc=alex.bennee@linaro.org \
--cc=batuzovk@ispras.ru \
--cc=edgar.iglesias@xilinx.com \
--cc=fred.konrad@greensocs.com \
--cc=hines@cert.org \
--cc=igor.rubinov@gmail.com \
--cc=maria.klimushenkova@ispras.ru \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=real@ispras.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).