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 v5 20/31] replay: recording and replaying clock ticks
Date: Wed, 26 Nov 2014 13:40:38 +0300 [thread overview]
Message-ID: <20141126104038.7772.79661.stgit@PASHA-ISP> (raw)
In-Reply-To: <20141126103841.7772.11864.stgit@PASHA-ISP>
Clock ticks are considered as the sources of non-deterministic data for
virtual machine. This patch implements saving the clock values when they
are acquired (virtual, host clock, rdtsc, and some other timers).
When replaying the execution corresponding values are read from log and
transfered to the module, which wants to read the values.
Such a design required the clock polling to be synchronized. Sometimes
it is not true - e.g. when timeouts for timer lists are checked. In this case
we use a cached value of the clock, passing it to the client code.
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
include/qemu/timer.h | 20 ++++++++++--
qemu-timer.c | 3 +-
replay/Makefile.objs | 1 +
replay/replay-internal.h | 11 ++++++
replay/replay-time.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++
replay/replay.h | 21 ++++++++++++
stubs/replay.c | 9 +++++
7 files changed, 141 insertions(+), 3 deletions(-)
create mode 100755 replay/replay-time.c
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 38a02c5..7b43331 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -4,6 +4,7 @@
#include "qemu/typedefs.h"
#include "qemu-common.h"
#include "qemu/notify.h"
+#include "replay/replay.h"
/* timers */
@@ -699,8 +700,8 @@ static inline int64_t get_ticks_per_sec(void)
* Low level clock functions
*/
-/* real time host monotonic timer */
-static inline int64_t get_clock_realtime(void)
+/* real time host monotonic timer implementation */
+static inline int64_t get_clock_realtime_impl(void)
{
struct timeval tv;
@@ -708,6 +709,12 @@ static inline int64_t get_clock_realtime(void)
return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000);
}
+/* real time host monotonic timer interface */
+static inline int64_t get_clock_realtime(void)
+{
+ return REPLAY_CLOCK(REPLAY_CLOCK_HOST, get_clock_realtime_impl());
+}
+
/* Warning: don't insert tracepoints into these functions, they are
also used by simpletrace backend and tracepoints would cause
an infinite recursion! */
@@ -752,6 +759,8 @@ int64_t cpu_icount_to_ns(int64_t icount);
/*******************************************/
/* host CPU ticks (if available) */
+#define cpu_get_real_ticks cpu_get_real_ticks_impl
+
#if defined(_ARCH_PPC)
static inline int64_t cpu_get_real_ticks(void)
@@ -905,6 +914,13 @@ static inline int64_t cpu_get_real_ticks (void)
}
#endif
+#undef cpu_get_real_ticks
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+ return REPLAY_CLOCK(REPLAY_CLOCK_REAL_TICKS, cpu_get_real_ticks_impl());
+}
+
#ifdef CONFIG_PROFILER
static inline int64_t profile_getclock(void)
{
diff --git a/qemu-timer.c b/qemu-timer.c
index 00a5d35..8307913 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -25,6 +25,7 @@
#include "sysemu/sysemu.h"
#include "monitor/monitor.h"
#include "ui/console.h"
+#include "replay/replay.h"
#include "hw/hw.h"
@@ -562,7 +563,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
now = get_clock_realtime();
last = clock->last;
clock->last = now;
- if (now < last) {
+ if (now < last && replay_mode == REPLAY_MODE_NONE) {
notifier_list_notify(&clock->reset_notifiers, &now);
}
return now;
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index 56da09c..257c320 100755
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -1,3 +1,4 @@
obj-y += replay.o
obj-y += replay-internal.o
obj-y += replay-events.o
+obj-y += replay-time.o
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index fcba977..c36d7de 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -22,12 +22,17 @@
#define EVENT_ASYNC_OPT 25
/* for instruction event */
#define EVENT_INSTRUCTION 32
+/* for clock read/writes */
+#define EVENT_CLOCK 64
+/* some of grteater codes are reserved for clocks */
/* Asynchronous events IDs */
#define REPLAY_ASYNC_COUNT 0
typedef struct ReplayState {
+ /*! Cached clock values. */
+ int64_t cached_clock[REPLAY_CLOCK_COUNT];
/*! Current step - number of processed instructions and timer events. */
uint64_t current_step;
/*! Number of instructions to be executed before other events happen. */
@@ -75,6 +80,12 @@ bool skip_async_events(int stop_event);
reports an error and stops the execution. */
void skip_async_events_until(unsigned int kind);
+/*! Reads next clock value from the file.
+ If clock kind read from the file is different from the parameter,
+ the value is not used.
+ If the parameter is -1, the clock value is read to the cache anyway. */
+void replay_read_next_clock(unsigned int kind);
+
/* Asynchronous events queue */
/*! Initializes events' processing internals */
diff --git a/replay/replay-time.c b/replay/replay-time.c
new file mode 100755
index 0000000..3f94f4e
--- /dev/null
+++ b/replay/replay-time.c
@@ -0,0 +1,79 @@
+/*
+ * replay-time.c
+ *
+ * Copyright (c) 2010-2014 Institute for System Programming
+ * of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "replay.h"
+#include "replay-internal.h"
+
+
+int64_t replay_save_clock(unsigned int kind, int64_t clock)
+{
+ replay_save_instructions();
+
+ if (kind >= REPLAY_CLOCK_COUNT) {
+ fprintf(stderr, "invalid clock ID %d for replay\n", kind);
+ exit(1);
+ }
+
+ if (replay_file) {
+ replay_put_event(EVENT_CLOCK + kind);
+ replay_put_qword(clock);
+ }
+
+ return clock;
+}
+
+void replay_read_next_clock(unsigned int kind)
+{
+ replay_fetch_data_kind();
+ if (replay_file) {
+ unsigned int read_kind = replay_data_kind - EVENT_CLOCK;
+
+ if (kind != -1 && read_kind != kind) {
+ return;
+ }
+ if (read_kind >= REPLAY_CLOCK_COUNT) {
+ fprintf(stderr,
+ "invalid clock ID %d was read from replay\n", read_kind);
+ exit(1);
+ }
+
+ int64_t clock = replay_get_qword();
+
+ replay_check_error();
+ replay_has_unread_data = 0;
+
+ replay_state.cached_clock[read_kind] = clock;
+ }
+}
+
+/*! Reads next clock event from the input. */
+int64_t replay_read_clock(unsigned int kind)
+{
+ if (kind >= REPLAY_CLOCK_COUNT) {
+ fprintf(stderr, "invalid clock ID %d for replay\n", kind);
+ exit(1);
+ }
+
+ replay_exec_instructions();
+
+ if (replay_file) {
+ if (skip_async_events(EVENT_CLOCK + kind)) {
+ replay_read_next_clock(kind);
+ }
+ int64_t ret = replay_state.cached_clock[kind];
+
+ return ret;
+ }
+
+ fprintf(stderr, "REPLAY INTERNAL ERROR %d\n", __LINE__);
+ exit(1);
+}
diff --git a/replay/replay.h b/replay/replay.h
index 90a949b..cba3b18 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -16,6 +16,14 @@
#include <stdint.h>
#include "qapi-types.h"
+/* replay clock kinds */
+/* rdtsc */
+#define REPLAY_CLOCK_REAL_TICKS 0
+/* host_clock */
+#define REPLAY_CLOCK_HOST 1
+
+#define REPLAY_CLOCK_COUNT 2
+
extern ReplayMode replay_mode;
extern char *replay_image_suffix;
@@ -47,6 +55,19 @@ bool replay_interrupt(void);
Returns true, when interrupt request is pending */
bool replay_has_interrupt(void);
+/* Processing clocks and other time sources */
+
+/*! Save the specified clock */
+int64_t replay_save_clock(unsigned int kind, int64_t clock);
+/*! Read the specified clock from the log or return cached data */
+int64_t replay_read_clock(unsigned int kind);
+/*! Saves or reads the clock depending on the current replay mode. */
+#define REPLAY_CLOCK(clock, value) \
+ (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
+ : replay_mode == REPLAY_MODE_RECORD \
+ ? replay_save_clock((clock), (value)) \
+ : (value))
+
/* Asynchronous events queue */
/*! Disables storing events in the queue */
diff --git a/stubs/replay.c b/stubs/replay.c
index b146d55..f3f60fe 100755
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -6,3 +6,12 @@ ReplaySubmode replay_get_play_submode(void)
{
return 0;
}
+
+int64_t replay_save_clock(unsigned int kind, int64_t clock)
+{
+}
+
+int64_t replay_read_clock(unsigned int kind)
+{
+ return 0;
+}
next prev parent reply other threads:[~2014-11-26 10:40 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 10:38 [Qemu-devel] [RFC PATCH v5 00/31] Deterministic replay and reverse execution Pavel Dovgalyuk
2014-11-26 10:38 ` [Qemu-devel] [RFC PATCH v5 01/31] cpu-exec: fix cpu_exec_nocache Pavel Dovgalyuk
2014-11-26 10:38 ` [Qemu-devel] [RFC PATCH v5 02/31] acpi: accurate overflow check Pavel Dovgalyuk
2014-11-26 13:15 ` Paolo Bonzini
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 03/31] replay: global variables and function stubs Pavel Dovgalyuk
2014-11-26 15:32 ` Eric Blake
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 04/31] sysemu: system functions for replay Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 05/31] replay: internal functions for replay log Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 06/31] cpu-exec: reset exception_index correctly Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 07/31] icount: implement icount requesting Pavel Dovgalyuk
2014-12-03 10:17 ` Paolo Bonzini
2014-12-04 11:02 ` Pavel Dovgaluk
2014-12-04 15:50 ` Paolo Bonzini
2014-12-05 5:34 ` Pavel Dovgaluk
2014-12-05 10:36 ` Paolo Bonzini
2014-12-05 10:55 ` Pavel Dovgaluk
2014-12-05 11:43 ` Paolo Bonzini
2014-12-05 12:59 ` Pavel Dovgaluk
[not found] ` <12880.8243353435$1417784373@news.gmane.org>
2014-12-05 15:13 ` Paolo Bonzini
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 08/31] icount: improve enable/disable ticks Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 09/31] replay: introduce icount event Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 10/31] i386: do not cross the pages boundaries in replay mode Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 11/31] From 7abf2f72777958d395cfd01d97fe707cc06152b5 Mon Sep 17 00:00:00 2001 Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 12/31] From 185a3a47d08857a66332ae862b372a153ce92bb9 " Pavel Dovgalyuk
2014-11-26 10:39 ` [Qemu-devel] [RFC PATCH v5 13/31] From a0cb9e80ba0de409b5ad556109a1c71ce4d8ce19 " Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 14/31] From 04bbd21134dd2c6b7309a7f5f2b780aae2757003 " Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 15/31] cpu-exec: allow temporary disabling icount Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 16/31] cpu-exec: invalidate nocache translation if they are interrupted Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 17/31] replay: interrupts and exceptions Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 18/31] replay: asynchronous events infrastructure Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 19/31] cpu: replay instructions sequence Pavel Dovgalyuk
2014-11-26 10:40 ` Pavel Dovgalyuk [this message]
2014-11-26 10:52 ` [Qemu-devel] [RFC PATCH v5 20/31] replay: recording and replaying clock ticks Paolo Bonzini
2014-11-26 12:22 ` Pavel Dovgaluk
2014-11-26 12:51 ` Paolo Bonzini
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 21/31] replay: recording and replaying different timers Pavel Dovgalyuk
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 22/31] timer: introduce new QEMU_CLOCK_VIRTUAL_RT clock Pavel Dovgalyuk
2014-11-26 11:04 ` Paolo Bonzini
2014-11-26 12:27 ` Pavel Dovgaluk
2014-11-27 9:11 ` Pavel Dovgaluk
2014-11-27 16:53 ` Paolo Bonzini
2014-11-28 7:52 ` Pavel Dovgaluk
2014-11-28 11:28 ` Pavel Dovgaluk
2014-11-28 12:40 ` Paolo Bonzini
2014-11-26 10:40 ` [Qemu-devel] [RFC PATCH v5 23/31] cpus: make icount warp deterministic in replay mode Pavel Dovgalyuk
2014-11-26 11:26 ` Paolo Bonzini
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 24/31] replay: shutdown event Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 25/31] replay: checkpoints Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 26/31] replay: bottom halves Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 27/31] replay: replay aio requests Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 28/31] replay: thread pool Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 29/31] replay: initialization and deinitialization Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 30/31] replay: command line options Pavel Dovgalyuk
2014-11-26 10:41 ` [Qemu-devel] [RFC PATCH v5 31/31] replay: recording of the user input Pavel Dovgalyuk
2014-11-26 10:47 ` [Qemu-devel] [RFC PATCH v5 00/31] Deterministic replay and reverse execution Pavel Dovgaluk
2014-11-26 13:26 ` Paolo Bonzini
[not found] ` <5475b20f.841f8c0a.8e72.ffffa4f6SMTPIN_ADDED_BROKEN@mx.google.com>
2014-11-27 9:53 ` Artyom Tarasenko
2014-11-27 17:45 ` Paolo Bonzini
2014-11-28 9:39 ` Artyom Tarasenko
2014-11-28 7:51 ` Pavel Dovgaluk
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=20141126104038.7772.79661.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 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).