From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru,
pavel.dovgaluk@ispras.ru, pbonzini@redhat.com,
fred.konrad@greensocs.com
Subject: [Qemu-devel] [RFC PATCH v2 29/49] replay: recording and replaying clock ticks
Date: Thu, 17 Jul 2014 15:04:41 +0400 [thread overview]
Message-ID: <20140717110441.8352.54455.stgit@PASHA-ISP> (raw)
In-Reply-To: <20140717110153.8352.80175.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>
---
cpus.c | 9 ++++++
include/qemu/timer.h | 42 +++++++++++++++++++++++++-
replay/Makefile.objs | 1 +
replay/replay-internal.h | 11 +++++++
replay/replay-time.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
replay/replay.h | 17 ++++++++++
stubs/replay.c | 9 ++++++
7 files changed, 162 insertions(+), 2 deletions(-)
create mode 100755 replay/replay-time.c
diff --git a/cpus.c b/cpus.c
index eb2a795..15a2106 100644
--- a/cpus.c
+++ b/cpus.c
@@ -40,6 +40,7 @@
#include "qemu/bitmap.h"
#include "qemu/seqlock.h"
#include "qapi-event.h"
+#include "replay/replay.h"
#ifndef _WIN32
#include "qemu/compatfd.h"
@@ -206,11 +207,19 @@ int64_t cpu_get_clock(void)
int64_t ti;
unsigned start;
+ if (replay_mode == REPLAY_PLAY) {
+ return replay_read_clock(REPLAY_CLOCK_VIRTUAL);
+ }
+
do {
start = seqlock_read_begin(&timers_state.vm_clock_seqlock);
ti = cpu_get_clock_locked();
} while (seqlock_read_retry(&timers_state.vm_clock_seqlock, start));
+ if (replay_mode == REPLAY_SAVE) {
+ replay_save_clock(REPLAY_CLOCK_VIRTUAL, ti);
+ }
+
return ti;
}
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 7f9a074..9eaed56 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,23 @@ 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)
+{
+ int64_t result;
+
+ if (replay_mode == REPLAY_SAVE) {
+ result = get_clock_realtime_impl();
+ replay_save_clock(REPLAY_CLOCK_REALTIME, result);
+ } else if (replay_mode == REPLAY_PLAY) {
+ result = replay_read_clock(REPLAY_CLOCK_REALTIME);
+ } else {
+ result = get_clock_realtime_impl();
+ }
+
+ return result;
+}
+
/* Warning: don't insert tracepoints into these functions, they are
also used by simpletrace backend and tracepoints would cause
an infinite recursion! */
@@ -749,6 +767,8 @@ int64_t cpu_get_clock(void);
/*******************************************/
/* 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)
@@ -902,6 +922,24 @@ static inline int64_t cpu_get_real_ticks (void)
}
#endif
+#undef cpu_get_real_ticks
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+ int64_t val;
+
+ if (replay_mode == REPLAY_SAVE) {
+ val = cpu_get_real_ticks_impl();
+ replay_save_clock(REPLAY_CLOCK_REAL_TICKS, val);
+ } else if (replay_mode == REPLAY_PLAY) {
+ val = replay_read_clock(REPLAY_CLOCK_REAL_TICKS);
+ } else {
+ val = cpu_get_real_ticks_impl();
+ }
+
+ return val;
+}
+
#ifdef CONFIG_PROFILER
static inline int64_t profile_getclock(void)
{
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 cffc4e2..a4fbc26 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -24,12 +24,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];
/*! Nonzero, when next instruction is repeated one and was already
processed. */
int skipping_instruction;
@@ -78,6 +83,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..905d3e4
--- /dev/null
+++ b/replay/replay-time.c
@@ -0,0 +1,75 @@
+/*
+ * 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"
+
+
+void 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);
+ }
+}
+
+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);
+ }
+
+ 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 7f461c5..3d09ec8 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -24,6 +24,16 @@
/* Normal log replaying */
#define REPLAY_PLAY_NORMAL 1
+/* replay clock kinds */
+/* rdtsc */
+#define REPLAY_CLOCK_REAL_TICKS 0
+/* host_clock */
+#define REPLAY_CLOCK_REALTIME 1
+/* vm_clock */
+#define REPLAY_CLOCK_VIRTUAL 2
+
+#define REPLAY_CLOCK_COUNT 3
+
extern int replay_mode;
extern char *replay_image_suffix;
/*! Shift value for icount based on replay or zero, if it is disabled. */
@@ -58,6 +68,13 @@ 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 */
+void 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);
+
/* Asynchronous events queue */
/*! Disables storing events in the queue */
diff --git a/stubs/replay.c b/stubs/replay.c
index 1e99ca4..3b88b1a 100755
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -7,3 +7,12 @@ int replay_get_play_submode(void)
{
return 0;
}
+
+void 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-07-17 11:18 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-17 11:01 [Qemu-devel] [RFC PATCH v2 00/49] Series short description Pavel Dovgalyuk
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 01/49] acpi: accurate overflow check Pavel Dovgalyuk
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 02/49] integratorcp: adding vmstate for save/restore Pavel Dovgalyuk
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 03/49] pcspk: " Pavel Dovgalyuk
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 04/49] fdc: " Pavel Dovgalyuk
2014-07-28 9:47 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 05/49] parallel: " Pavel Dovgalyuk
2014-07-28 10:02 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 06/49] serial: fixing " Pavel Dovgalyuk
2014-07-28 9:58 ` Paolo Bonzini
2014-07-30 7:01 ` Pavel Dovgaluk
[not found] ` <19697.8771281012$1406703748@news.gmane.org>
2014-07-30 9:19 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 07/49] kvmapic: fixing loading vmstate Pavel Dovgalyuk
2014-07-28 8:49 ` Paolo Bonzini
2014-07-29 12:03 ` Pavel Dovgaluk
2014-07-29 12:16 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 08/49] hpet: fixing saving and loading process Pavel Dovgalyuk
2014-07-28 8:33 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 09/49] pckbd: adding new fields to vmstate Pavel Dovgalyuk
2014-07-28 9:36 ` Paolo Bonzini
2014-07-17 11:02 ` [Qemu-devel] [RFC PATCH v2 10/49] rtl8139: " Pavel Dovgalyuk
2014-07-28 9:41 ` Paolo Bonzini
2014-07-28 9:54 ` Pavel Dovgaluk
[not found] ` <37740.9009532586$1406541296@news.gmane.org>
2014-07-28 10:12 ` Paolo Bonzini
2014-07-30 8:24 ` Pavel Dovgaluk
2014-07-30 9:26 ` Paolo Bonzini
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 11/49] piix: do not raise irq while loading vmstate Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 12/49] mc146818rtc: add missed field to vmstate Pavel Dovgalyuk
2014-07-28 9:42 ` Paolo Bonzini
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 13/49] pl031: " Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 14/49] ide pci: reset status field before loading the vmstate Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 15/49] softmmu: fixing usage of cpu_st/ld* from helpers Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 16/49] target: save cpu state fields Pavel Dovgalyuk
2014-07-31 6:48 ` Andreas Färber
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 17/49] target-i386: update fp status fix Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 18/49] migration: add vmstate for int8 and char arrays Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 19/49] replay: global variables and function stubs Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 20/49] block: add suffix parameter to bdrv_open functions Pavel Dovgalyuk
2014-07-17 11:03 ` [Qemu-devel] [RFC PATCH v2 21/49] sysemu: system functions for replay Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 22/49] replay: internal functions for replay log Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 23/49] cpu: invent instruction count for accurate replay Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 24/49] target-arm: instructions counting code for replay Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 25/49] target-i386: " Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 26/49] replay: interrupts and exceptions Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 27/49] vga: do not use virtual clock for blinking cursor Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 28/49] replay: asynchronous events infrastructure Pavel Dovgalyuk
2014-07-17 11:04 ` Pavel Dovgalyuk [this message]
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 30/49] replay: recording and replaying different timers Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 31/49] replay: shutdown event Pavel Dovgalyuk
2014-07-17 11:04 ` [Qemu-devel] [RFC PATCH v2 32/49] replay: checkpoints Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 33/49] replay: bottom halves Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 34/49] replay: replay aio requests Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 35/49] replay: thread pool Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 36/49] pl031: vmstate in replay mode Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 37/49] replay: initialization and deinitialization Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 38/49] replay: command line options Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 39/49] replay: snapshotting the virtual machine Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 40/49] replay: recording of the user input Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 41/49] tap-win32: destroy the thread at exit Pavel Dovgalyuk
2014-07-17 11:05 ` [Qemu-devel] [RFC PATCH v2 42/49] replay: network packets record/replay Pavel Dovgalyuk
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 43/49] replay: audio data record/replay Pavel Dovgalyuk
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 44/49] replay: serial port Pavel Dovgalyuk
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 45/49] replay: USB passthrough Pavel Dovgalyuk
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 46/49] replay: replay_info command Pavel Dovgalyuk
2014-07-18 15:55 ` Eric Blake
2014-07-18 15:56 ` Eric Blake
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 47/49] replay: replay_break command Pavel Dovgalyuk
2014-07-18 15:58 ` Eric Blake
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 48/49] replay: replay_seek_step command Pavel Dovgalyuk
2014-07-18 15:59 ` Eric Blake
2014-07-17 11:06 ` [Qemu-devel] [RFC PATCH v2 49/49] gdbstub: reverse debugging Pavel Dovgalyuk
2014-07-18 8:10 ` [Qemu-devel] [RFC PATCH v2 00/49] Series short description Frederic Konrad
2014-07-24 17:48 ` Paolo Bonzini
2014-07-28 7:50 ` Pavel Dovgaluk
[not found] ` <2596.37912172384$1406533875@news.gmane.org>
2014-07-28 10:12 ` Paolo Bonzini
2014-07-30 7:44 ` Pavel Dovgaluk
2014-07-30 9:25 ` Paolo Bonzini
2014-07-30 13:19 ` Frederic Konrad
2014-07-30 13:35 ` Paolo Bonzini
2014-07-30 14:51 ` Frederic Konrad
2014-07-31 13:05 ` Frederic Konrad
2014-07-31 14:18 ` Paolo Bonzini
2014-07-31 5:44 ` 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=20140717110441.8352.54455.stgit@PASHA-ISP \
--to=pavel.dovgaluk@ispras.ru \
--cc=batuzovk@ispras.ru \
--cc=fred.konrad@greensocs.com \
--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).