From d73abd6dcc105fb5cacc34716046fca63132a264 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:23:37 +0300 Subject: replay: global variables and function stubs This patch adds global variables, defines, function declarations, and function stubs for deterministic VM replay used by external modules. Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162337.8676.41538.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini --- include/sysemu/replay.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 include/sysemu/replay.h (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h new file mode 100644 index 0000000000..d6b73c3304 --- /dev/null +++ b/include/sysemu/replay.h @@ -0,0 +1,19 @@ +#ifndef REPLAY_H +#define REPLAY_H + +/* + * replay.h + * + * Copyright (c) 2010-2015 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 "qapi-types.h" + +extern ReplayMode replay_mode; + +#endif -- cgit v1.2.3 From 26bc60ac82f88d14e65be5387eb4a136edf94f1b Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:23:54 +0300 Subject: replay: introduce icount event This patch adds icount event to the replay subsystem. This event corresponds to execution of several instructions and used to synchronize input events in the replay phase. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162354.8676.31351.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini --- include/sysemu/replay.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index d6b73c3304..a03c7485d4 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -12,8 +12,15 @@ * */ +#include +#include #include "qapi-types.h" extern ReplayMode replay_mode; +/* Processing the instructions */ + +/*! Returns number of executed instructions. */ +uint64_t replay_get_current_step(void); + #endif -- cgit v1.2.3 From 8b42704441865611a5ee241ac9fc5cabc47a079b Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:05 +0300 Subject: cpu: replay instructions sequence This patch adds calls to replay functions into the icount setup block. In record mode number of executed instructions is written to the log. In replay mode number of istructions to execute is taken from the replay log. When replayed instructions counter is expired qemu_notify_event() function is called to wake up the iothread. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162405.8676.31890.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini --- include/sysemu/replay.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index a03c7485d4..d19715fde0 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -22,5 +22,9 @@ extern ReplayMode replay_mode; /*! Returns number of executed instructions. */ uint64_t replay_get_current_step(void); +/*! Returns number of instructions to execute in replay mode. */ +int replay_get_instructions(void); +/*! Updates instructions counter in replay mode. */ +void replay_account_executed_instructions(void); #endif -- cgit v1.2.3 From 6f0609697f3670bf755a91477487507a8ffee471 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:16 +0300 Subject: replay: interrupts and exceptions This patch includes modifications of common cpu files. All interrupts and exceptions occured during recording are written into the replay log. These events allow correct replaying the execution by kicking cpu thread when one of these events is found in the log. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162416.8676.57647.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini --- include/sysemu/replay.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index d19715fde0..8915523eaf 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -27,4 +27,21 @@ int replay_get_instructions(void); /*! Updates instructions counter in replay mode. */ void replay_account_executed_instructions(void); +/* Interrupts and exceptions */ + +/*! Called by exception handler to write or read + exception processing events. */ +bool replay_exception(void); +/*! Used to determine that exception is pending. + Does not proceed to the next event in the log. */ +bool replay_has_exception(void); +/*! Called by interrupt handlers to write or read + interrupt processing events. + \return true if interrupt should be processed */ +bool replay_interrupt(void); +/*! Tries to read interrupt event from the file. + Returns true, when interrupt request is pending */ +bool replay_has_interrupt(void); + + #endif -- cgit v1.2.3 From c0c071d05279ec1429352200affc5c70bb4e5980 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:22 +0300 Subject: replay: asynchronous events infrastructure This patch adds module for saving and replaying asynchronous events. These events include network packets, keyboard and mouse input, USB packets, thread pool and bottom halves callbacks. All events are stored in the queue to be processed at synchronization points such as beginning of TB execution, or checkpoint in the iothread. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162422.8676.88696.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 8915523eaf..c2a7651d7a 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -43,5 +43,11 @@ bool replay_interrupt(void); Returns true, when interrupt request is pending */ bool replay_has_interrupt(void); +/* Asynchronous events queue */ + +/*! Disables storing events in the queue */ +void replay_disable_events(void); +/*! Returns true when saving events is enabled */ +bool replay_events_enabled(void); #endif -- cgit v1.2.3 From 8eda206e09089914006bfbdd71467d5246c06e4a Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:28 +0300 Subject: replay: recording and replaying clock ticks 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). 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 Message-Id: <20150917162427.8676.36558.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index c2a7651d7a..2398509188 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -16,6 +16,16 @@ #include #include "qapi-types.h" +/* replay clock kinds */ +enum ReplayClockKind { + /* host_clock */ + REPLAY_CLOCK_HOST, + /* virtual_rt_clock */ + REPLAY_CLOCK_VIRTUAL_RT, + REPLAY_CLOCK_COUNT +}; +typedef enum ReplayClockKind ReplayClockKind; + extern ReplayMode replay_mode; /* Processing the instructions */ @@ -43,6 +53,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(ReplayClockKind kind, int64_t clock); +/*! Read the specified clock from the log or return cached data */ +int64_t replay_read_clock(ReplayClockKind 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 */ -- cgit v1.2.3 From b60c48a7019614902f2debe4d4181ec8cfa60e0d Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:33 +0300 Subject: replay: shutdown event This patch records and replays simulator shutdown event. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162433.8676.32262.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 2398509188..fcc93d1a8f 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -66,6 +66,11 @@ int64_t replay_read_clock(ReplayClockKind kind); ? replay_save_clock((clock), (value)) \ : (value)) +/* Events */ + +/*! Called when qemu shutdown is requested. */ +void replay_shutdown_request(void); + /* Asynchronous events queue */ /*! Disables storing events in the queue */ -- cgit v1.2.3 From 8bd7f71d794b93ce027b856f5b79a98f4f82e44c Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:44 +0300 Subject: replay: checkpoints 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 Message-Id: <20150917162444.8676.52916.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index fcc93d1a8f..e2696fe396 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/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 */ -- cgit v1.2.3 From 8a354bd935a800dd2d98ac8f30707e2912c80ae6 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:56 +0300 Subject: replay: ptimer This patch adds deterministic replay for hardware periodic countdown timers. ptimer uses bottom halves layer to execute such an asynchronous callback. We put this callback into the replay queue instead of bottom halves one. When checkpoint is met by main loop thread, the replay queue is processed and callback is executed. Binding callback moment to one of the checkpoints makes it deterministic. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162456.8676.83366.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index e2696fe396..fdf46f8089 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -15,6 +15,7 @@ #include #include #include "qapi-types.h" +#include "qemu/typedefs.h" /* replay clock kinds */ enum ReplayClockKind { @@ -97,5 +98,7 @@ bool replay_checkpoint(ReplayCheckpoint checkpoint); void replay_disable_events(void); /*! Returns true when saving events is enabled */ bool replay_events_enabled(void); +/*! Adds bottom half event to the queue */ +void replay_bh_schedule_event(QEMUBH *bh); #endif -- cgit v1.2.3 From 7615936ebf4e60c4565268a30df2356c841526f8 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:07 +0300 Subject: replay: initialization and deinitialization This patch introduces the functions for enabling the record/replay and for freeing the resources when simulator closes. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162507.8676.90232.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index fdf46f8089..ad5234c8fb 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -43,6 +43,15 @@ typedef enum ReplayCheckpoint ReplayCheckpoint; extern ReplayMode replay_mode; +/* Replay process control functions */ + +/*! Enables recording or saving event log with specified parameters */ +void replay_configure(struct QemuOpts *opts); +/*! Initializes timers used for snapshotting and enables events recording */ +void replay_start(void); +/*! Closes replay log file and frees other resources. */ +void replay_finish(void); + /* Processing the instructions */ /*! Returns number of executed instructions. */ -- cgit v1.2.3 From 0194749ac4131e1bed8e166c5d5cf541678ef204 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:13 +0300 Subject: replay: replay blockers for devices Some devices are not supported by record/replay subsystem. This patch introduces replay blocker which denies starting record/replay if such devices are included into the configuration. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162512.8676.11367.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index ad5234c8fb..3b27f12633 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -15,6 +15,7 @@ #include #include #include "qapi-types.h" +#include "qapi/error.h" #include "qemu/typedefs.h" /* replay clock kinds */ @@ -51,6 +52,8 @@ void replay_configure(struct QemuOpts *opts); void replay_start(void); /*! Closes replay log file and frees other resources. */ void replay_finish(void); +/*! Adds replay blocker with the specified error description */ +void replay_add_blocker(Error *reason); /* Processing the instructions */ -- cgit v1.2.3 From ee312992a323530ea2cda8680f3a34746c72db8f Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:24 +0300 Subject: replay: recording of the user input This records user input (keyboard and mouse events) in record mode and replays these input events in replay mode. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162524.8676.11696.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/sysemu/replay.h') diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 3b27f12633..abb4688200 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -112,5 +112,9 @@ void replay_disable_events(void); bool replay_events_enabled(void); /*! Adds bottom half event to the queue */ void replay_bh_schedule_event(QEMUBH *bh); +/*! Adds input event to the queue */ +void replay_input_event(QemuConsole *src, InputEvent *evt); +/*! Adds input sync event to the queue */ +void replay_input_sync_event(void); #endif -- cgit v1.2.3