From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887389182891.7150308905141; Thu, 4 May 2017 01:43:09 -0700 (PDT) Received: from localhost ([::1]:40442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CLq-0004H4-JA for importer@patchew.org; Thu, 04 May 2017 04:43:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKS-0003Fb-Na for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKR-0006Cd-OI for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:40 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKR-0006BP-Gm for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:39 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 9863F54006C; Thu, 4 May 2017 11:41:38 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:41:42 +0300 Message-ID: <20170504084142.7488.77770.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 01/10] block: implement bdrv_snapshot_goto for blkreplay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch enables making snapshots with blkreplay used in block devices. This function is required to make bdrv_snapshot_goto without calling .bdrv_open which is not implemented. Signed-off-by: Pavel Dovgalyuk --- block/blkreplay.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blkreplay.c b/block/blkreplay.c index e1102119fb..d13a98d691 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -130,6 +130,12 @@ static int coroutine_fn blkreplay_co_flush(BlockDriver= State *bs) return ret; } =20 +static int blkreplay_snapshot_goto(BlockDriverState *bs, + const char *snapshot_id) +{ + return bdrv_snapshot_goto(bs->file->bs, snapshot_id); +} + static BlockDriver bdrv_blkreplay =3D { .format_name =3D "blkreplay", .protocol_name =3D "blkreplay", @@ -146,6 +152,8 @@ static BlockDriver bdrv_blkreplay =3D { .bdrv_co_pwrite_zeroes =3D blkreplay_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkreplay_co_pdiscard, .bdrv_co_flush =3D blkreplay_co_flush, + + .bdrv_snapshot_goto =3D blkreplay_snapshot_goto, }; =20 static void bdrv_blkreplay_init(void) From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887398545761.2109359374625; Thu, 4 May 2017 01:43:18 -0700 (PDT) Received: from localhost ([::1]:40443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CM1-0004TN-8N for importer@patchew.org; Thu, 04 May 2017 04:43:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKa-0003LB-MT for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKX-0006Is-IG for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:48 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKX-0006IJ-3o for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:45 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 3B3D354006E; Thu, 4 May 2017 11:41:44 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:41:48 +0300 Message-ID: <20170504084148.7488.77468.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 02/10] blkreplay: create temporary overlay for underlaying devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch allows using '-snapshot' behavior in record/replay mode. blkreplay layer creates temporary overlays on top of underlaying disk images. It is needed, because creating an overlay over blkreplay breaks the determinism. This patch creates similar temporary overlay (when it is needed) under the blkreplay driver. Therefore all block operations are controlled by blkreplay. Signed-off-by: Pavel Dovgalyuk --- block/blkreplay.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ stubs/replay.c | 1 + vl.c | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/block/blkreplay.c b/block/blkreplay.c index d13a98d691..a9bab72bfc 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -14,12 +14,69 @@ #include "block/block_int.h" #include "sysemu/replay.h" #include "qapi/error.h" +#include "qapi/qmp/qstring.h" =20 typedef struct Request { Coroutine *co; QEMUBH *bh; } Request; =20 +static BlockDriverState *blkreplay_append_snapshot(BlockDriverState *bs, + Error **errp) +{ + int ret; + BlockDriverState *bs_snapshot; + int64_t total_size; + QemuOpts *opts =3D NULL; + char tmp_filename[PATH_MAX + 1]; + QDict *snapshot_options =3D qdict_new(); + + /* Prepare options QDict for the overlay file */ + qdict_put(snapshot_options, "file.driver", qstring_from_str("file")); + qdict_put(snapshot_options, "driver", qstring_from_str("qcow2")); + + /* Create temporary file */ + ret =3D get_tmp_filename(tmp_filename, PATH_MAX + 1); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not get temporary filename"); + goto out; + } + qdict_put(snapshot_options, "file.filename", + qstring_from_str(tmp_filename)); + + /* Get the required size from the image */ + total_size =3D bdrv_getlength(bs); + if (total_size < 0) { + error_setg_errno(errp, -total_size, "Could not get image size"); + goto out; + } + + opts =3D qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0, &error_abor= t); + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size, &error_abort); + ret =3D bdrv_create(&bdrv_qcow2, tmp_filename, opts, errp); + qemu_opts_del(opts); + if (ret < 0) { + error_prepend(errp, "Could not create temporary overlay '%s': ", + tmp_filename); + goto out; + } + + bs_snapshot =3D bdrv_open(NULL, NULL, snapshot_options, + BDRV_O_RDWR | BDRV_O_TEMPORARY, errp); + snapshot_options =3D NULL; + if (!bs_snapshot) { + goto out; + } + + bdrv_append(bs_snapshot, bs, errp); + + return bs_snapshot; + +out: + QDECREF(snapshot_options); + return NULL; +} + static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -35,6 +92,14 @@ static int blkreplay_open(BlockDriverState *bs, QDict *o= ptions, int flags, goto fail; } =20 + /* Add temporary snapshot to preserve the image */ + if (!replay_snapshot + && !blkreplay_append_snapshot(bs->file->bs, &local_err)) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto fail; + } + ret =3D 0; fail: if (ret < 0) { diff --git a/stubs/replay.c b/stubs/replay.c index 9c8aa48c9c..9991ee5120 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -3,6 +3,7 @@ #include "sysemu/sysemu.h" =20 ReplayMode replay_mode; +char *replay_snapshot; =20 int64_t replay_save_clock(unsigned int kind, int64_t clock) { diff --git a/vl.c b/vl.c index f46e070e0d..eafb3ff7a4 100644 --- a/vl.c +++ b/vl.c @@ -4492,7 +4492,7 @@ int main(int argc, char **argv, char **envp) qapi_free_BlockdevOptions(bdo->bdo); g_free(bdo); } - if (snapshot || replay_mode !=3D REPLAY_MODE_NONE) { + if (snapshot) { qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); } From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887535880720.9344677805474; Thu, 4 May 2017 01:45:35 -0700 (PDT) Received: from localhost ([::1]:40461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6COE-00072Z-IJ for importer@patchew.org; Thu, 04 May 2017 04:45:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKd-0003NI-S3 for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKc-0006Le-Vp for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:51 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKc-0006LK-My for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:50 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id CE1F9540070; Thu, 4 May 2017 11:41:49 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:41:54 +0300 Message-ID: <20170504084153.7488.97620.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 03/10] replay: disable default snapshot for record/replay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch disables setting '-snapshot' option on by default in record/replay mode. This is needed for creating vmstates in record and replay modes. Signed-off-by: Pavel Dovgalyuk --- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index eafb3ff7a4..222610ab7a 100644 --- a/vl.c +++ b/vl.c @@ -3168,7 +3168,13 @@ int main(int argc, char **argv, char **envp) drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); break; case QEMU_OPTION_snapshot: - snapshot =3D 1; + { + Error *blocker =3D NULL; + snapshot =3D 1; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, + "-snapshot"); + replay_add_blocker(blocker); + } break; case QEMU_OPTION_hdachs: { From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887517315725.8280376498025; Thu, 4 May 2017 01:45:17 -0700 (PDT) Received: from localhost ([::1]:40452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CNw-0006dr-3E for importer@patchew.org; Thu, 04 May 2017 04:45:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKl-0003Td-Jx for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKi-0006OX-HN for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:59 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKi-0006OB-9O for qemu-devel@nongnu.org; Thu, 04 May 2017 04:41:56 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 6FC1C540072; Thu, 4 May 2017 11:41:55 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:41:59 +0300 Message-ID: <20170504084159.7488.97487.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 04/10] replay: fix processing async events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk Asynchronous events saved at checkpoints may invoke callbacks when processed. These callbacks may also generate/read new events (e.g. clock reads). Therefore event processing flag must be reset before callback invocation. Signed-off-by: Pavel Dovgalyuk --- replay/replay-events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/replay/replay-events.c b/replay/replay-events.c index 94a6dcccfc..768b505f3d 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -295,13 +295,13 @@ void replay_read_events(int checkpoint) if (!event) { break; } + replay_finish_event(); + read_event_kind =3D -1; replay_mutex_unlock(); replay_run_event(event); replay_mutex_lock(); =20 g_free(event); - replay_finish_event(); - read_event_kind =3D -1; } } =20 From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887642274327.0732710887693; Thu, 4 May 2017 01:47:22 -0700 (PDT) Received: from localhost ([::1]:40468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CPx-0008NF-1N for importer@patchew.org; Thu, 04 May 2017 04:47:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKp-0003WX-00 for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKo-0006Wo-5O for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:03 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKn-0006Vm-TA for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:02 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 0AF1F540074; Thu, 4 May 2017 11:42:01 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:05 +0300 Message-ID: <20170504084205.7488.95093.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 05/10] replay: fixed replay_enable_events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch fixes assignment to internal events_enabled variable. Now it is set only in record/replay mode. This affects the behavior of the external functions that check this flag. Signed-off-by: Pavel Dovgalyuk --- replay/replay-events.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/replay/replay-events.c b/replay/replay-events.c index 768b505f3d..e858254074 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -67,7 +67,9 @@ static void replay_run_event(Event *event) =20 void replay_enable_events(void) { - events_enabled =3D true; + if (replay_mode !=3D REPLAY_MODE_NONE) { + events_enabled =3D true; + } } =20 bool replay_has_events(void) @@ -141,7 +143,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind, =20 void replay_bh_schedule_event(QEMUBH *bh) { - if (replay_mode !=3D REPLAY_MODE_NONE && events_enabled) { + if (events_enabled) { uint64_t id =3D replay_get_current_step(); replay_add_event(REPLAY_ASYNC_EVENT_BH, bh, NULL, id); } else { @@ -161,7 +163,7 @@ void replay_add_input_sync_event(void) =20 void replay_block_event(QEMUBH *bh, uint64_t id) { - if (replay_mode !=3D REPLAY_MODE_NONE && events_enabled) { + if (events_enabled) { replay_add_event(REPLAY_ASYNC_EVENT_BLOCK, bh, NULL, id); } else { qemu_bh_schedule(bh); From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887750531753.5841633721016; Thu, 4 May 2017 01:49:10 -0700 (PDT) Received: from localhost ([::1]:40475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CRf-0001aO-B2 for importer@patchew.org; Thu, 04 May 2017 04:49:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKw-0003j8-RZ for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKt-0006bE-Nv for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:10 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKt-0006al-Fi for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:07 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 99EDC540080; Thu, 4 May 2017 11:42:06 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:10 +0300 Message-ID: <20170504084210.7488.37561.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 06/10] replay: fix save/load vm for non-empty queue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch does not allows saving/loading vmstate when replay events queue is not empty. There is no reliable way to save events queue, because it describes internal coroutine state. Therefore saving and loading operations should be deferred to another record/replay step. Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 3 +++ migration/savevm.c | 13 +++++++++++++ replay/replay-snapshot.c | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index f1c0712795..5c9db2a2ef 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -164,5 +164,8 @@ void replay_audio_in(int *recorded, void *samples, int = *wpos, int size); /*! Called at the start of execution. Loads or saves initial vmstate depending on execution mode. */ void replay_vmstate_init(void); +/*! Called to ensure that replay state is consistent and VM snapshot + can be created */ +bool replay_can_snapshot(void); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 03ae1bdeb4..358d22170d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -54,6 +54,7 @@ #include "qemu/cutils.h" #include "io/channel-buffer.h" #include "io/channel-file.h" +#include "sysemu/replay.h" =20 #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035 @@ -2083,6 +2084,12 @@ int save_vmstate(Monitor *mon, const char *name) Error *local_err =3D NULL; AioContext *aio_context; =20 + if (!replay_can_snapshot()) { + monitor_printf(mon, "Record/replay does not allow making snapshot = right now. " + "Try stopping at another step.\n"); + return ret; + } + if (!bdrv_all_can_snapshot(&bs)) { monitor_printf(mon, "Device '%s' is writable but does not " "support snapshots.\n", bdrv_get_device_name(bs)); @@ -2244,6 +2251,12 @@ int load_vmstate(const char *name) AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 + if (!replay_can_snapshot()) { + error_report("Record/replay does not allow loading snapshot right = now. " + "Try stopping at another step.\n"); + return -EINVAL; + } + if (!bdrv_all_can_snapshot(&bs)) { error_report("Device '%s' is writable but does not support snapsho= ts.", bdrv_get_device_name(bs)); diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 65e2d375c2..438d82ec33 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -76,3 +76,9 @@ void replay_vmstate_init(void) } } } + +bool replay_can_snapshot(void) +{ + return replay_mode =3D=3D REPLAY_MODE_NONE + || !replay_has_events(); +} From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887659110811.806526472239; Thu, 4 May 2017 01:47:39 -0700 (PDT) Received: from localhost ([::1]:40469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CQD-0000IS-TJ for importer@patchew.org; Thu, 04 May 2017 04:47:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CL0-0003p2-Kz for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CKz-0006es-IK for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:14 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CKz-0006eO-3G for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:13 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 3E21C540090; Thu, 4 May 2017 11:42:12 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:16 +0300 Message-ID: <20170504084216.7488.23102.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 07/10] replay: added replay log format description X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds description of the replay log file format into the docs/replay.txt. Signed-off-by: Pavel Dovgalyuk --- docs/replay.txt | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 69 insertions(+) diff --git a/docs/replay.txt b/docs/replay.txt index 486c1e0e9d..c52407fe23 100644 --- a/docs/replay.txt +++ b/docs/replay.txt @@ -232,3 +232,72 @@ Audio devices Audio data is recorded and replay automatically. The command line for reco= rding and replaying must contain identical specifications of audio hardware, e.g= .: -soundhw ac97 + +Replay log format +----------------- + +Record/replay log consits of the header and the sequence of execution +events. The header includes 4-byte replay version id and 8-byte reserved +field. Version is updated every time replay log format changes to prevent +using replay log created by another build of qemu. + +The sequence of the events describes virtual machine state changes. +It includes all non-deterministic inputs of VM, synchronization marks and +instruction counts used to correctly inject inputs at replay. + +Synchronization marks (checkpoints) are used for synchronizing qemu threads +that perform operations with virtual hardware. These operations may change +system's state (e.g., change some register or generate interrupt) and +therefore should execute synchronously with CPU thread. + +Every event in the log includes 1-byte event id and optional arguments. +When argument is an array, it is stored as 4-byte array length +and corresponding number of bytes with data. +Here is the list of events that are written into the log: + + - EVENT_INSTRUCTION. Instructions executed since last event. + Argument: 4-byte number of executed instructions. + - EVENT_INTERRUPT. Used to synchronize interrupt processing. + - EVENT_EXCEPTION. Used to synchronize exception handling. + - EVENT_ASYNC. This is a group of events. They are always processed + together with checkpoints. When such an event is generated, it is + stored in the queue and processed only when checkpoint occurs. + Every such event is followed by 1-byte checkpoint id and 1-byte + async event id from the following list: + - REPLAY_ASYNC_EVENT_BH. Bottom-half callback. This event synchronizes + callbacks that affect virtual machine state, but normally called + asyncronously. + Argument: 8-byte operation id. + - REPLAY_ASYNC_EVENT_INPUT. Input device event. Contains + parameters of keyboard and mouse input operations + (key press/release, mouse pointer movement). + Arguments: 9-16 bytes depending of input event. + - REPLAY_ASYNC_EVENT_INPUT_SYNC. Internal input synchronization event. + - REPLAY_ASYNC_EVENT_CHAR_READ. Character (e.g., serial port) device = input + initiated by the sender. + Arguments: 1-byte character device id. + Array with bytes were read. + - REPLAY_ASYNC_EVENT_BLOCK. Block device operation. Used to synchroni= ze + operations with disk and flash drives with CPU. + Argument: 8-byte operation id. + - REPLAY_ASYNC_EVENT_NET. Incoming network packet. + Arguments: 1-byte network adapter id. + 4-byte packet flags. + Array with packet bytes. + - EVENT_SHUTDOWN. Occurs when user sends shutdown event to qemu, + e.g., by closing the window. + - EVENT_CHAR_WRITE. Used to synchronize character output operations. + Arguments: 4-byte output function return value. + 4-byte offset in the output array. + - EVENT_CHAR_READ_ALL. Used to synchronize character input operations, + initiated by qemu. + Argument: Array with bytes that were read. + - EVENT_CHAR_READ_ALL_ERROR. Unsuccessful character input operation, + initiated by qemu. + Argument: 4-byte error code. + - EVENT_CLOCK + clock_id. Group of events for host clock read operations. + Argument: 8-byte clock value. + - EVENT_CHECKPOINT + checkpoint_id. Checkpoint for synchronization of + CPU, internal threads, and asynchronous input events. May be followed + by one or more EVENT_ASYNC events. + - EVENT_END. Last event in the log. From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887764999571.0348879263504; Thu, 4 May 2017 01:49:24 -0700 (PDT) Received: from localhost ([::1]:40476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CRv-0001k0-Ni for importer@patchew.org; Thu, 04 May 2017 04:49:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CL8-0003vs-0T for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CL4-0006na-Ue for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:22 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CL4-0006mh-MN for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:18 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id C8ACC540092; Thu, 4 May 2017 11:42:17 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:22 +0300 Message-ID: <20170504084221.7488.13443.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 08/10] replay: make safe vmstop at record/replay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch disables bdrv flush/drain in record/replay mode. When block request is in the replay queue it cannot be processed with drain/flush until it is found in the log. Therefore vm should just stop leaving unfinished operations in the queue. Signed-off-by: Pavel Dovgalyuk --- cpus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpus.c b/cpus.c index 740b8dc3f8..f21e7f3166 100644 --- a/cpus.c +++ b/cpus.c @@ -932,9 +932,10 @@ static int do_vm_stop(RunState state) qapi_event_send_stop(&error_abort); } =20 - bdrv_drain_all(); - replay_disable_events(); - ret =3D bdrv_flush_all(); + if (!replay_events_enabled()) { + bdrv_drain_all(); + ret =3D bdrv_flush_all(); + } =20 return ret; } From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887839629680.8879970610843; Thu, 4 May 2017 01:50:39 -0700 (PDT) Received: from localhost ([::1]:40485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CT8-0002ZQ-3a for importer@patchew.org; Thu, 04 May 2017 04:50:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CLB-0003z5-J3 for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CLA-0006wy-Lt for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:25 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CLA-0006w9-9C for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:24 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 68711540096; Thu, 4 May 2017 11:42:23 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:27 +0300 Message-ID: <20170504084227.7488.16343.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 09/10] replay: save prior value of the host clock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch adds saving/restoring of the host clock field 'last'. It is used in host clock calculation and therefore clock may become incorrect when using restored vmstate. Signed-off-by: Pavel Dovgalyuk --- include/qemu/timer.h | 14 ++++++++++++++ replay/replay-internal.h | 2 ++ replay/replay-snapshot.c | 3 +++ util/qemu-timer.c | 12 ++++++++++++ 4 files changed, 31 insertions(+) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 8a1eb74839..5e9adbbf01 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -251,6 +251,20 @@ bool qemu_clock_run_timers(QEMUClockType type); */ bool qemu_clock_run_all_timers(void); =20 +/** + * qemu_clock_get_last: + * + * Returns last clock query time. + */ +uint64_t qemu_clock_get_last(QEMUClockType type); +/** + * qemu_clock_set_last: + * + * Sets last clock query time. + */ +void qemu_clock_set_last(QEMUClockType type, uint64_t last); + + /* * QEMUTimerList */ diff --git a/replay/replay-internal.h b/replay/replay-internal.h index ed66ed803c..738983e76a 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -77,6 +77,8 @@ typedef struct ReplayState { This counter is global, because requests from different block devices should not get overlapping ids. */ uint64_t block_request_id; + /*! Prior value of the host clock */ + uint64_t host_clock_last; } ReplayState; extern ReplayState replay_state; =20 diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 438d82ec33..1a0b76b9ca 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -24,12 +24,14 @@ static void replay_pre_save(void *opaque) { ReplayState *state =3D opaque; state->file_offset =3D ftell(replay_file); + state->host_clock_last =3D qemu_clock_get_last(QEMU_CLOCK_HOST); } =20 static int replay_post_load(void *opaque, int version_id) { ReplayState *state =3D opaque; fseek(replay_file, state->file_offset, SEEK_SET); + qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last); /* If this was a vmstate, saved in recording mode, we need to initialize replay data fields. */ replay_fetch_data_kind(); @@ -51,6 +53,7 @@ static const VMStateDescription vmstate_replay =3D { VMSTATE_UINT32(has_unread_data, ReplayState), VMSTATE_UINT64(file_offset, ReplayState), VMSTATE_UINT64(block_request_id, ReplayState), + VMSTATE_UINT64(host_clock_last, ReplayState), VMSTATE_END_OF_LIST() }, }; diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 82d56507a2..2ed1bf2778 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -622,6 +622,18 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } =20 +uint64_t qemu_clock_get_last(QEMUClockType type) +{ + QEMUClock *clock =3D qemu_clock_ptr(type); + return clock->last; +} + +void qemu_clock_set_last(QEMUClockType type, uint64_t last) +{ + QEMUClock *clock =3D qemu_clock_ptr(type); + clock->last =3D last; +} + void qemu_clock_register_reset_notifier(QEMUClockType type, Notifier *notifier) { From nobody Mon May 6 02:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493887453801862.7103475840383; Thu, 4 May 2017 01:44:13 -0700 (PDT) Received: from localhost ([::1]:40446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CMu-0005SG-4q for importer@patchew.org; Thu, 04 May 2017 04:44:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CLJ-00045n-Jt for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6CLG-000752-9Q for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:33 -0400 Received: from mail.ispras.ru ([83.149.199.45]:42446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6CLF-00073U-RL for qemu-devel@nongnu.org; Thu, 04 May 2017 04:42:30 -0400 Received: from [10.10.150.19] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 011BB54009B; Thu, 4 May 2017 11:42:28 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 04 May 2017 11:42:33 +0300 Message-ID: <20170504084233.7488.8159.stgit@PASHA-ISP> In-Reply-To: <20170504084135.7488.24715.stgit@PASHA-ISP> References: <20170504084135.7488.24715.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v9 10/10] icount: fixed saving/restoring of icount warp timers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, jasowang@redhat.com, mst@redhat.com, dovgaluk@ispras.ru, kraxel@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch adds saving and restoring of the icount warp timers in the vmstate. It is needed because there timers affect the virtual clock value. Therefore determinism of the execution in icount record/replay mode depends on determinism of the timers. Signed-off-by: Pavel Dovgalyuk --- cpus.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/cpus.c b/cpus.c index f21e7f3166..5c955a709c 100644 --- a/cpus.c +++ b/cpus.c @@ -118,16 +118,11 @@ static bool all_cpu_threads_idle(void) /* Protected by TimersState seqlock */ =20 static bool icount_sleep =3D true; -static int64_t vm_clock_warp_start =3D -1; /* Conversion factor from emulated instructions to virtual clock ticks. */ static int icount_time_shift; /* Arbitrarily pick 1MIPS as the minimum allowable speed. */ #define MAX_ICOUNT_SHIFT 10 =20 -static QEMUTimer *icount_rt_timer; -static QEMUTimer *icount_vm_timer; -static QEMUTimer *icount_warp_timer; - typedef struct TimersState { /* Protected by BQL. */ int64_t cpu_ticks_prev; @@ -145,6 +140,11 @@ typedef struct TimersState { int64_t qemu_icount_bias; /* Only written by TCG thread */ int64_t qemu_icount; + /* for adjusting icount */ + int64_t vm_clock_warp_start; + QEMUTimer *icount_rt_timer; + QEMUTimer *icount_vm_timer; + QEMUTimer *icount_warp_timer; } TimersState; =20 static TimersState timers_state; @@ -430,14 +430,14 @@ static void icount_adjust(void) =20 static void icount_adjust_rt(void *opaque) { - timer_mod(icount_rt_timer, + timer_mod(timers_state.icount_rt_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) + 1000); icount_adjust(); } =20 static void icount_adjust_vm(void *opaque) { - timer_mod(icount_vm_timer, + timer_mod(timers_state.icount_vm_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 10); icount_adjust(); @@ -458,7 +458,7 @@ static void icount_warp_rt(void) */ do { seq =3D seqlock_read_begin(&timers_state.vm_clock_seqlock); - warp_start =3D vm_clock_warp_start; + warp_start =3D timers_state.vm_clock_warp_start; } while (seqlock_read_retry(&timers_state.vm_clock_seqlock, seq)); =20 if (warp_start =3D=3D -1) { @@ -471,7 +471,7 @@ static void icount_warp_rt(void) cpu_get_clock_locked()); int64_t warp_delta; =20 - warp_delta =3D clock - vm_clock_warp_start; + warp_delta =3D clock - timers_state.vm_clock_warp_start; if (use_icount =3D=3D 2) { /* * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too @@ -483,7 +483,7 @@ static void icount_warp_rt(void) } timers_state.qemu_icount_bias +=3D warp_delta; } - vm_clock_warp_start =3D -1; + timers_state.vm_clock_warp_start =3D -1; seqlock_write_end(&timers_state.vm_clock_seqlock); =20 if (qemu_clock_expired(QEMU_CLOCK_VIRTUAL)) { @@ -592,11 +592,11 @@ void qemu_start_warp_timer(void) * every 100ms. */ seqlock_write_begin(&timers_state.vm_clock_seqlock); - if (vm_clock_warp_start =3D=3D -1 || vm_clock_warp_start > clo= ck) { - vm_clock_warp_start =3D clock; + if (timers_state.vm_clock_warp_start =3D=3D -1 || timers_state= .vm_clock_warp_start > clock) { + timers_state.vm_clock_warp_start =3D clock; } seqlock_write_end(&timers_state.vm_clock_seqlock); - timer_mod_anticipate(icount_warp_timer, clock + deadline); + timer_mod_anticipate(timers_state.icount_warp_timer, clock + d= eadline); } } else if (deadline =3D=3D 0) { qemu_clock_notify(QEMU_CLOCK_VIRTUAL); @@ -621,7 +621,7 @@ static void qemu_account_warp_timer(void) return; } =20 - timer_del(icount_warp_timer); + timer_del(timers_state.icount_warp_timer); icount_warp_rt(); } =20 @@ -630,6 +630,44 @@ static bool icount_state_needed(void *opaque) return use_icount; } =20 +static bool warp_timer_state_needed(void *opaque) +{ + TimersState *s =3D opaque; + return s->icount_warp_timer !=3D NULL; +} + +static bool adjust_timers_state_needed(void *opaque) +{ + TimersState *s =3D opaque; + return s->icount_rt_timer !=3D NULL; +} + +/* + * Subsection for warp timer migration is optional, because may not be cre= ated + */ +static const VMStateDescription icount_vmstate_warp_timer =3D { + .name =3D "timer/icount/warp_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D warp_timer_state_needed, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER_PTR(icount_warp_timer, TimersState), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription icount_vmstate_adjust_timers =3D { + .name =3D "timer/icount/timers", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D adjust_timers_state_needed, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER_PTR(icount_rt_timer, TimersState), + VMSTATE_TIMER_PTR(icount_vm_timer, TimersState), + VMSTATE_END_OF_LIST() + } +}; + /* * This is a subsection for icount migration. */ @@ -641,7 +679,13 @@ static const VMStateDescription icount_vmstate_timers = =3D { .fields =3D (VMStateField[]) { VMSTATE_INT64(qemu_icount_bias, TimersState), VMSTATE_INT64(qemu_icount, TimersState), + VMSTATE_INT64(vm_clock_warp_start, TimersState), VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription*[]) { + &icount_vmstate_warp_timer, + &icount_vmstate_adjust_timers, + NULL } }; =20 @@ -752,7 +796,7 @@ void configure_icount(QemuOpts *opts, Error **errp) =20 icount_sleep =3D qemu_opt_get_bool(opts, "sleep", true); if (icount_sleep) { - icount_warp_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL_RT, + timers_state.icount_warp_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL= _RT, icount_timer_cb, NULL); } =20 @@ -786,13 +830,14 @@ void configure_icount(QemuOpts *opts, Error **errp) the virtual time trigger catches emulated time passing too fast. Realtime triggers occur even when idle, so use them less frequently than VM triggers. */ - icount_rt_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL_RT, + timers_state.vm_clock_warp_start =3D -1; + timers_state.icount_rt_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL_RT, icount_adjust_rt, NULL); - timer_mod(icount_rt_timer, + timer_mod(timers_state.icount_rt_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) + 1000); - icount_vm_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + timers_state.icount_vm_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, icount_adjust_vm, NULL); - timer_mod(icount_vm_timer, + timer_mod(timers_state.icount_vm_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 10); }