From patchwork Tue May 5 10:18:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 468042 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 A0949140783 for ; Tue, 5 May 2015 20:18:55 +1000 (AEST) Received: from localhost ([::1]:38075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpZwD-0007EQ-Ee for incoming@patchwork.ozlabs.org; Tue, 05 May 2015 06:18:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpZvY-0005yV-Ra for qemu-devel@nongnu.org; Tue, 05 May 2015 06:18:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpZvV-0007UJ-Lo for qemu-devel@nongnu.org; Tue, 05 May 2015 06:18:12 -0400 Received: from mail.ispras.ru ([83.149.199.45]:38822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpZvV-0007UA-9N for qemu-devel@nongnu.org; Tue, 05 May 2015 06:18:09 -0400 Received: from [10.10.150.75] (unknown [85.142.117.224]) by mail.ispras.ru (Postfix) with ESMTPSA id 8CAD5540070; Tue, 5 May 2015 13:18:08 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Tue, 05 May 2015 13:18:10 +0300 Message-ID: <20150505101809.16764.79115.stgit@PASHA-ISP> In-Reply-To: <20150505101732.16764.93601.stgit@PASHA-ISP> References: <20150505101732.16764.93601.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, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH v12 06/21] 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. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- replay/replay-internal.c | 24 ++++++++++++++++++++++++ replay/replay-internal.h | 21 +++++++++++++++++++++ replay/replay.c | 34 ++++++++++++++++++++++++++++++++++ replay/replay.h | 7 +++++++ 4 files changed, 86 insertions(+), 0 deletions(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index f7c03bc..064ddf9 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); } @@ -143,8 +145,15 @@ void replay_fetch_data_kind(void) if (replay_file) { if (!replay_has_unread_data) { replay_data_kind = replay_get_byte(); + if (replay_data_kind == EVENT_INSTRUCTION) { + replay_state.instructions_count = replay_get_dword(); + } 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); + } } } } @@ -174,3 +183,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) { + replay_mutex_lock(); + 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; + } + replay_mutex_unlock(); + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 8a0de0d..acae7ac 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; /* File for replay writing */ @@ -50,4 +64,11 @@ void replay_finish_event(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. + \return true, if event was found */ +bool replay_next_event_is(int event); + #endif diff --git a/replay/replay.c b/replay/replay.c index 5ce066f..43798e1 100755 --- a/replay/replay.c +++ b/replay/replay.c @@ -9,6 +9,40 @@ * */ +#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 replay_next_event_is(int event) +{ + bool res = false; + + /* nothing to skip - not all instructions used */ + if (replay_state.instructions_count != 0) { + assert(replay_data_kind == EVENT_INSTRUCTION); + return event == EVENT_INSTRUCTION; + } + + while (true) { + replay_fetch_data_kind(); + if (event == replay_data_kind) { + res = true; + } + switch (replay_data_kind) { + default: + /* clock, time_t, checkpoint and other events */ + return res; + } + } + return res; +} + +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