All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
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 v9 14/23] replay: checkpoints
Date: Wed, 18 Feb 2015 14:57:04 +0300	[thread overview]
Message-ID: <20150218115703.4176.16661.stgit@PASHA-ISP> (raw)
In-Reply-To: <20150218115534.4176.12578.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>
---
 block.c                  |   12 ++++++++++++
 cpus.c                   |    5 +++++
 main-loop.c              |    6 ++++++
 qemu-timer.c             |   38 ++++++++++++++++++++++++++++++++++----
 replay/replay-internal.h |    4 ++++
 replay/replay.c          |   36 ++++++++++++++++++++++++++++++++++++
 replay/replay.h          |   18 ++++++++++++++++++
 stubs/replay.c           |   11 +++++++++++
 vl.c                     |    5 ++++-
 9 files changed, 130 insertions(+), 5 deletions(-)

diff --git a/block.c b/block.c
index 210fd5f..37b9bd8 100644
--- a/block.c
+++ b/block.c
@@ -36,6 +36,7 @@
 #include "qmp-commands.h"
 #include "qemu/timer.h"
 #include "qapi-event.h"
+#include "replay/replay.h"
 
 #ifdef CONFIG_BSD
 #include <sys/types.h>
@@ -1994,6 +1995,11 @@ void bdrv_drain_all(void)
     BlockDriverState *bs;
 
     while (busy) {
+        if (!replay_checkpoint(CHECKPOINT_BDRV_DRAIN)) {
+            /* 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) {
@@ -2004,6 +2010,12 @@ void bdrv_drain_all(void)
             aio_context_release(aio_context);
         }
     }
+    if (replay_mode == REPLAY_MODE_PLAY) {
+        /* Skip checkpoints from the log */
+        while (replay_checkpoint(CHECKPOINT_BDRV_DRAIN)) {
+            /* Nothing */
+        }
+    }
 }
 
 /* make a BlockDriverState anonymous by removing from bdrv_state and
diff --git a/cpus.c b/cpus.c
index b40b48c..5b2f896 100644
--- a/cpus.c
+++ b/cpus.c
@@ -391,6 +391,11 @@ void qemu_clock_warp(QEMUClockType type)
         return;
     }
 
+    /* warp clock deterministically in record/replay mode */
+    if (!replay_checkpoint(CHECKPOINT_CLOCK_WARP)) {
+        return;
+    }
+
     /*
      * If the CPUs have been sleeping, advance QEMU_CLOCK_VIRTUAL timer now.
      * This ensures that the deadline for the timer is computed correctly below.
diff --git a/main-loop.c b/main-loop.c
index 981bcb5..06aad06 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -29,6 +29,7 @@
 #include "slirp/libslirp.h"
 #include "qemu/main-loop.h"
 #include "block/aio.h"
+#include "replay/replay.h"
 
 #ifndef _WIN32
 
@@ -497,6 +498,11 @@ int main_loop_wait(int nonblocking)
     slirp_pollfds_poll(gpollfds, (ret < 0));
 #endif
 
+    /* CPU thread can infinitely wait for event after
+       missing the warp */
+    if (replay_mode == REPLAY_MODE_PLAY) {
+        qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
+    }
     qemu_clock_run_all_timers();
 
     return ret;
diff --git a/qemu-timer.c b/qemu-timer.c
index d605afd..37d9098 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -478,10 +478,33 @@ 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;
+        }
+    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 +568,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 27a3b0a..fb27b48 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -29,6 +29,10 @@ enum ReplayEvents {
     /* some of grteater codes are reserved for clocks */
     EVENT_CLOCK,
     EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
+    /* for checkpoint event */
+    /* some of grteater 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 3330432..9cc8dd0 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -161,3 +161,39 @@ void replay_shutdown_request(void)
         replay_put_event(EVENT_SHUTDOWN);
     }
 }
+
+bool replay_checkpoint(ReplayCheckpoint checkpoint)
+{
+    bool res = false;
+    replay_save_instructions();
+
+    if (replay_file) {
+        if (replay_mode == REPLAY_MODE_PLAY) {
+            replay_mutex_lock();
+            if (!skip_async_events(EVENT_CHECKPOINT + checkpoint)) {
+                if (replay_data_kind == EVENT_ASYNC) {
+                    replay_read_events(checkpoint);
+                    replay_fetch_data_kind();
+                    res = replay_data_kind != EVENT_ASYNC;
+                    replay_mutex_unlock();
+                    return res;
+                }
+                replay_mutex_unlock();
+                return res;
+            }
+            replay_has_unread_data = 0;
+            replay_read_events(checkpoint);
+            replay_fetch_data_kind();
+            res = replay_data_kind != EVENT_ASYNC;
+            replay_mutex_unlock();
+            return res;
+        } else if (replay_mode == REPLAY_MODE_RECORD) {
+            replay_mutex_lock();
+            replay_put_event(EVENT_CHECKPOINT + checkpoint);
+            replay_save_events(checkpoint);
+            replay_mutex_unlock();
+        }
+    }
+
+    return true;
+}
diff --git a/replay/replay.h b/replay/replay.h
index fcc93d1..f4bdb31 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -26,6 +26,18 @@ enum ReplayClockKind {
 };
 typedef enum ReplayClockKind ReplayClockKind;
 
+/* IDs of the checkpoints */
+enum ReplayCheckpoint {
+    CHECKPOINT_BDRV_DRAIN,
+    CHECKPOINT_CLOCK_WARP,
+    CHECKPOINT_RESET_REQUESTED,
+    CHECKPOINT_CLOCK_VIRTUAL,
+    CHECKPOINT_CLOCK_HOST,
+    CHECKPOINT_CLOCK_VIRTUAL_RT,
+    CHECKPOINT_COUNT
+};
+typedef enum ReplayCheckpoint ReplayCheckpoint;
+
 extern ReplayMode replay_mode;
 
 /* Processing the instructions */
@@ -70,6 +82,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 121bca6..1be3575 100755
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -1,4 +1,5 @@
 #include "replay/replay.h"
+#include "sysemu/sysemu.h"
 
 ReplayMode replay_mode;
 
@@ -10,3 +11,13 @@ int64_t replay_read_clock(unsigned int kind)
 {
     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 58b9dd5..565bbb2 100644
--- a/vl.c
+++ b/vl.c
@@ -118,6 +118,7 @@ int main(int argc, char **argv)
 #include "qapi/opts-visitor.h"
 #include "qom/object_interfaces.h"
 #include "qapi-event.h"
+#include "replay/replay.h"
 
 #define DEFAULT_RAM_SIZE 128
 
@@ -1757,7 +1758,9 @@ static bool main_loop_should_exit(void)
             return true;
         }
     }
-    if (qemu_reset_requested()) {
+    if (qemu_reset_requested_get()
+        && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) {
+        qemu_reset_requested();
         pause_all_vcpus();
         cpu_synchronize_all_states();
         qemu_system_reset(VMRESET_REPORT);

  parent reply	other threads:[~2015-02-18 11:57 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-18 11:55 [Qemu-devel] [RFC PATCH v9 00/23] Deterministic replay core Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 01/23] i386: partial revert of interrupt poll fix Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 02/23] replay: global variables and function stubs Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 03/23] sysemu: system functions for replay Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 04/23] replay: internal functions for replay log Pavel Dovgalyuk
2015-02-18 12:43   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 05/23] replay: introduce mutex to protect the " Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 06/23] replay: introduce icount event Pavel Dovgalyuk
2015-02-18 13:49   ` Paolo Bonzini
2015-02-18 14:14   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 07/23] cpu-exec: allow temporary disabling icount Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 08/23] cpu: replay instructions sequence Pavel Dovgalyuk
2015-02-18 12:50   ` Paolo Bonzini
2015-02-18 13:48   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 09/23] replay: interrupts and exceptions Pavel Dovgalyuk
2015-02-18 13:54   ` Paolo Bonzini
2015-02-18 14:14   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 10/23] replay: asynchronous events infrastructure Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 11/23] replay: recording and replaying clock ticks Pavel Dovgalyuk
2015-02-18 14:13   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 12/23] timer: replace time() with QEMU_CLOCK_HOST Pavel Dovgalyuk
2015-02-18 13:04   ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 13/23] replay: shutdown event Pavel Dovgalyuk
2015-02-18 11:57 ` Pavel Dovgalyuk [this message]
2015-02-18 14:14   ` [Qemu-devel] [RFC PATCH v9 14/23] replay: checkpoints Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 15/23] aio: replace stack of bottom halves with queue Pavel Dovgalyuk
2015-02-18 13:06   ` Paolo Bonzini
2015-02-18 13:10   ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 16/23] replay: bottom halves Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 17/23] replay: replay aio requests Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 18/23] replay: thread pool Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 19/23] typedef: add typedef for QemuOpts Pavel Dovgalyuk
2015-02-18 13:11   ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 20/23] replay: initialization and deinitialization Pavel Dovgalyuk
2015-02-18 13:14   ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 21/23] replay: replay blockers for devices Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 22/23] replay: command line options Pavel Dovgalyuk
2015-02-18 13:18   ` Paolo Bonzini
2015-02-20  8:02     ` Pavel Dovgaluk
     [not found]     ` <23594.561199616$1424419399@news.gmane.org>
2015-02-20 10:28       ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 23/23] replay: recording of the user input Pavel Dovgalyuk
2015-02-18 14:19 ` [Qemu-devel] [RFC PATCH v9 00/23] Deterministic replay core Paolo Bonzini
2015-02-27  9:23   ` Pavel Dovgaluk
2015-02-27 13:07     ` 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=20150218115703.4176.16661.stgit@PASHA-ISP \
    --to=pavel.dovgaluk@ispras.ru \
    --cc=afaerber@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=batuzovk@ispras.ru \
    --cc=fred.konrad@greensocs.com \
    --cc=maria.klimushenkova@ispras.ru \
    --cc=mark.burton@greensocs.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.