From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO3Em-0006pU-B4 for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YO3Ek-0002ar-Kz for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:16 -0500 Received: from mail.ispras.ru ([83.149.199.45]:38199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO3Ek-0002aZ-8Z for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:14 -0500 From: Pavel Dovgalyuk Date: Wed, 18 Feb 2015 14:56:15 +0300 Message-ID: <20150218115615.4176.14168.stgit@PASHA-ISP> In-Reply-To: <20150218115534.4176.12578.stgit@PASHA-ISP> References: <20150218115534.4176.12578.stgit@PASHA-ISP> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH v9 06/23] replay: introduce icount event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 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 --- replay/replay-internal.c | 21 +++++++++++++++++++++ replay/replay-internal.h | 24 ++++++++++++++++++++++++ replay/replay.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ replay/replay.h | 7 +++++++ 4 files changed, 98 insertions(+), 0 deletions(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index ce7a1d8..21bb42e 100755 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -10,6 +10,7 @@ */ #include "qemu-common.h" +#include "replay.h" #include "replay-internal.h" unsigned int replay_data_kind = -1; @@ -34,6 +35,7 @@ void replay_put_byte(uint8_t byte) void replay_put_event(uint8_t event) { + assert(event < EVENT_COUNT); replay_put_byte(event); } @@ -145,6 +147,10 @@ void replay_fetch_data_kind(void) replay_data_kind = replay_get_byte(); replay_check_error(); replay_has_unread_data = 1; + if (replay_data_kind >= EVENT_COUNT) { + error_report("Replay: unknown event kind %d", replay_data_kind); + exit(1); + } } } } @@ -168,3 +174,18 @@ void replay_mutex_unlock(void) { qemu_mutex_unlock(&lock); } + +/*! Saves cached instructions. */ +void replay_save_instructions(void) +{ + if (replay_file && replay_mode == REPLAY_MODE_RECORD) { + int diff = (int)(replay_get_current_step() - replay_state.current_step); + if (first_cpu != NULL && diff > 0) { + replay_mutex_lock(); + replay_put_event(EVENT_INSTRUCTION); + replay_put_dword(diff); + replay_state.current_step += diff; + replay_mutex_unlock(); + } + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index d92410e..3588448 100755 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -14,6 +14,20 @@ #include +enum ReplayEvents { + /* for instruction event */ + EVENT_INSTRUCTION, + EVENT_COUNT +}; + +typedef struct ReplayState { + /*! Current step - number of processed instructions and timer events. */ + uint64_t current_step; + /*! Number of instructions to be executed before other events happen. */ + int instructions_count; +} ReplayState; +extern ReplayState replay_state; + extern unsigned int replay_data_kind; extern unsigned int replay_has_unread_data; @@ -48,4 +62,14 @@ void replay_check_error(void); replay_data_kind variable. */ void replay_fetch_data_kind(void); +/*! Saves queued events (like instructions and sound). */ +void replay_save_instructions(void); + +/*! Skips async events until some sync event will be found. */ +bool skip_async_events(int stop_event); +/*! Skips async events invocations from the input, + until required data kind is found. If the requested data is not found + reports an error and stops the execution. */ +void skip_async_events_until(unsigned int kind); + #endif diff --git a/replay/replay.c b/replay/replay.c index 5ce066f..a43bbbc 100755 --- a/replay/replay.c +++ b/replay/replay.c @@ -9,6 +9,52 @@ * */ +#include "qemu-common.h" #include "replay.h" +#include "replay-internal.h" +#include "qemu/timer.h" ReplayMode replay_mode = REPLAY_MODE_NONE; + +ReplayState replay_state; + +bool skip_async_events(int stop_event) +{ + bool res = false; + + /* nothing to skip - not all instructions used */ + if (replay_state.instructions_count != 0 + && replay_has_unread_data) { + return stop_event == EVENT_INSTRUCTION; + } + + while (true) { + replay_fetch_data_kind(); + if (stop_event == replay_data_kind) { + res = true; + } + switch (replay_data_kind) { + case EVENT_INSTRUCTION: + replay_state.instructions_count = replay_get_dword(); + return res; + default: + /* clock, time_t, checkpoint and other events */ + return res; + } + } + return res; +} + +void skip_async_events_until(unsigned int kind) +{ + if (!skip_async_events(kind)) { + fprintf(stderr, "%"PRId64": Read data kind %d instead of expected %d\n", + replay_get_current_step(), replay_data_kind, kind); + exit(1); + } +} + +uint64_t replay_get_current_step(void) +{ + return cpu_get_icount_raw(); +} diff --git a/replay/replay.h b/replay/replay.h index d6b73c3..a03c748 100755 --- a/replay/replay.h +++ b/replay/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