From patchwork Wed Nov 26 10:39:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 415069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id ACCA41400EA for ; Wed, 26 Nov 2014 21:42:28 +1100 (AEDT) Received: from localhost ([::1]:33060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xta3G-0000Dq-RZ for incoming@patchwork.ozlabs.org; Wed, 26 Nov 2014 05:42:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xta0a-0004aV-WC for qemu-devel@nongnu.org; Wed, 26 Nov 2014 05:39:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xta0U-0008Ef-OI for qemu-devel@nongnu.org; Wed, 26 Nov 2014 05:39:40 -0500 Received: from mail.ispras.ru ([83.149.199.45]:34892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xta0U-0008EX-C2 for qemu-devel@nongnu.org; Wed, 26 Nov 2014 05:39:34 -0500 Received: from [10.10.150.37] (unknown [85.142.117.224]) by mail.ispras.ru (Postfix) with ESMTPSA id 8646E54006F; Wed, 26 Nov 2014 13:39:33 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Wed, 26 Nov 2014 13:39:37 +0300 Message-ID: <20141126103937.7772.42790.stgit@PASHA-ISP> In-Reply-To: <20141126103841.7772.11864.stgit@PASHA-ISP> References: <20141126103841.7772.11864.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.45 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 09/31] replay: introduce icount event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Pavel Dovgalyuk --- replay/replay-internal.c | 14 ++++++++++++++ replay/replay-internal.h | 18 ++++++++++++++++++ replay/replay.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ replay/replay.h | 7 +++++++ 4 files changed, 84 insertions(+), 0 deletions(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 429b13c..83a53bd 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" volatile unsigned int replay_data_kind = -1; @@ -139,3 +140,16 @@ void replay_fetch_data_kind(void) } } } + +/*! 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_put_event(EVENT_INSTRUCTION); + replay_put_dword(diff); + replay_state.current_step += diff; + } + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 927f7c7..582b44c 100755 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -14,6 +14,17 @@ #include +/* for instruction event */ +#define EVENT_INSTRUCTION 32 + +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 volatile unsigned int replay_data_kind; extern volatile unsigned int replay_has_unread_data; @@ -47,4 +58,11 @@ void replay_save_instructions(void); Terminates the program in case of error. */ void validate_data_kind(int kind); +/*! 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 ac976b2..c305e0c 100755 --- a/replay/replay.c +++ b/replay/replay.c @@ -9,7 +9,10 @@ * */ +#include "qemu-common.h" #include "replay.h" +#include "replay-internal.h" +#include "qemu/timer.h" ReplayMode replay_mode = REPLAY_MODE_NONE; /*! Stores current submode for PLAY mode */ @@ -18,8 +21,50 @@ ReplaySubmode play_submode = REPLAY_SUBMODE_UNKNOWN; /* Suffix for the disk images filenames */ char *replay_image_suffix; +ReplayState replay_state; ReplaySubmode replay_get_play_submode(void) { return play_submode; } + +bool skip_async_events(int stop_event) +{ + /* nothing to skip - not all instructions used */ + if (replay_state.instructions_count != 0 + && replay_has_unread_data) { + return stop_event == EVENT_INSTRUCTION; + } + + bool res = false; + 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_instructions_counter(); +} diff --git a/replay/replay.h b/replay/replay.h index 51a18fe..e40daf5 100755 --- a/replay/replay.h +++ b/replay/replay.h @@ -12,6 +12,8 @@ * */ +#include +#include #include "qapi-types.h" extern ReplayMode replay_mode; @@ -20,4 +22,9 @@ extern char *replay_image_suffix; /*! Returns replay play submode */ ReplaySubmode replay_get_play_submode(void); +/* Processing the instructions */ + +/*! Returns number of executed instructions. */ +uint64_t replay_get_current_step(void); + #endif