From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549354932632685.5461640069842; Tue, 5 Feb 2019 00:22:12 -0800 (PST) Received: from localhost ([127.0.0.1]:56135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzV-0000SK-Hj for importer@patchew.org; Tue, 05 Feb 2019 03:22:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxP-0007ej-O3 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxN-0007yQ-RR for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:51 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxL-0007uW-VJ for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:48 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 38D3354008A; Tue, 5 Feb 2019 11:19:46 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:19:47 +0300 Message-ID: <154935478737.7509.7376973512667308936.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 01/25] replay: add missing fix for internal function 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: pbonzini@redhat.com This is a fix which was missed by patch 74c0b816adfc6aa1b01b4426fdf385e32e35cbac, which added current_step parameter to the replay_advance_current_step function. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- replay/replay-internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 8f87e9b957..7e6de03182 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -229,7 +229,7 @@ void replay_mutex_unlock(void) =20 void replay_advance_current_step(uint64_t current_step) { - int diff =3D (int)(replay_get_current_step() - replay_state.current_st= ep); + int diff =3D (int)(current_step - replay_state.current_step); =20 /* Time can only go forward */ assert(diff >=3D 0); From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15493550979581000.9862693702298; Tue, 5 Feb 2019 00:24:57 -0800 (PST) Received: from localhost ([127.0.0.1]:56164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw2F-0002nE-R2 for importer@patchew.org; Tue, 05 Feb 2019 03:24:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxS-0007es-RR for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxR-000821-Ri for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:54 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxR-00080R-Js for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:53 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id CF96E540089; Tue, 5 Feb 2019 11:19:51 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:19:53 +0300 Message-ID: <154935479300.7509.17359115569001391731.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 02/25] 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Pavel Dovgalyuk 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 reviewed-by for the block-related patches. --- block/blkreplay.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blkreplay.c b/block/blkreplay.c index b5d9efdeca..142dfe3157 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -126,6 +126,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, NULL); +} + static BlockDriver bdrv_blkreplay =3D { .format_name =3D "blkreplay", .instance_size =3D 0, @@ -140,6 +146,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 Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549354936076881.2304863150049; Tue, 5 Feb 2019 00:22:16 -0800 (PST) Received: from localhost ([127.0.0.1]:56137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzb-0000WX-Ts for importer@patchew.org; Tue, 05 Feb 2019 03:22:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxX-0007hg-9y for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxW-00085H-Jw for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:59 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxW-000853-Cd for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:19:58 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 8791B540089; Tue, 5 Feb 2019 11:19:57 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:19:58 +0300 Message-ID: <154935479869.7509.15478826657419300596.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 03/25] 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Pavel Dovgalyuk 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 reviewed-by for the block-related patches. --- vl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index 9cf0fbe0b8..8b97ed7b3f 100644 --- a/vl.c +++ b/vl.c @@ -3199,7 +3199,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_numa: opts =3D qemu_opts_parse_noisily(qemu_find_opts("numa"), @@ -4468,7 +4474,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 Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549354962273630.9315192344865; Tue, 5 Feb 2019 00:22:42 -0800 (PST) Received: from localhost ([127.0.0.1]:56141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw04-0000wq-7l for importer@patchew.org; Tue, 05 Feb 2019 03:22:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxd-0007m8-5B for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxc-00087v-7s for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:05 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxc-00087i-0R for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:04 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 3139B540089; Tue, 5 Feb 2019 11:20:03 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:04 +0300 Message-ID: <154935480433.7509.6439846085623193495.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 04/25] replay: update docs for record/replay with block 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch updates the description of the command lines for using record/replay with attached block devices. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- docs/replay.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/replay.txt b/docs/replay.txt index 3497585f5a..2c2c5f6118 100644 --- a/docs/replay.txt +++ b/docs/replay.txt @@ -27,7 +27,7 @@ Usage of the record/replay: * First, record the execution with the following command line: qemu-system-i386 \ -icount shift=3D7,rr=3Drecord,rrfile=3Dreplay.bin \ - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct \ + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct \ -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkre= play \ -device ide-hd,drive=3Dimg-blkreplay \ -netdev user,id=3Dnet1 -device rtl8139,netdev=3Dnet1 \ @@ -35,7 +35,7 @@ Usage of the record/replay: * After recording, you can replay it by using another command line: qemu-system-i386 \ -icount shift=3D7,rr=3Dreplay,rrfile=3Dreplay.bin \ - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct \ + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct \ -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkre= play \ -device ide-hd,drive=3Dimg-blkreplay \ -netdev user,id=3Dnet1 -device rtl8139,netdev=3Dnet1 \ @@ -223,7 +223,7 @@ Block devices record/replay module intercepts calls of bdrv coroutine functions at the top of block drivers stack. To record and replay block operations the drive must be configured as following: - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkreplay -device ide-hd,drive=3Dimg-blkreplay =20 @@ -252,6 +252,12 @@ This snapshot is created at start of recording and res= tored at start of replaying. It also can be loaded while replaying to roll back the execution. =20 +'snapshot' flag of the disk image must be removed to save the snapshots +in the overlay (or original image) instead of using the temporary overlay. + -drive file=3Ddisk.ovl,if=3Dnone,id=3Dimg-direct + -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkreplay + -device ide-hd,drive=3Dimg-blkreplay + Use QEMU monitor to create additional snapshots. 'savevm ' command created the snapshot and 'loadvm ' restores it. To prevent corruption of the original disk image, use overlay files linked to the original image= s. From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355096369111.14261211825647; Tue, 5 Feb 2019 00:24:56 -0800 (PST) Received: from localhost ([127.0.0.1]:56166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw2H-0002oX-B2 for importer@patchew.org; Tue, 05 Feb 2019 03:24:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxj-0007rq-3Z for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxi-0008AX-3D for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:11 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxh-0008A0-NQ for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:10 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id CE87E54008A; Tue, 5 Feb 2019 11:20:08 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:10 +0300 Message-ID: <154935480995.7509.13012048579786526886.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 05/25] replay: don't drain/flush bdrv queue while RR is working 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" In record/replay mode bdrv queue is controlled by replay mechanism. It does not allow saving or loading the snapshots when bdrv queue is not empty. Stopping the VM is not blocked by nonempty queue, but flushing the queue is still impossible there, because it may cause deadlocks in replay mode. This patch disables bdrv_drain_all and bdrv_flush_all in record/replay mode. Stopping the machine when the IO requests are not finished is needed for the debugging. E.g., breakpoint may be set at the specified step, and forcing the IO requests to finish may break the determinism of the execution. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- block/io.c | 28 ++++++++++++++++++++++++++++ cpus.c | 2 -- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 213ca03d8d..c25864a8ee 100644 --- a/block/io.c +++ b/block/io.c @@ -32,6 +32,7 @@ #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "sysemu/replay.h" =20 #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progr= ess */ =20 @@ -538,6 +539,15 @@ void bdrv_drain_all_begin(void) return; } =20 + /* + * bdrv queue is managed by record/replay, + * waiting for finishing the I/O requests may + * be infinite + */ + if (replay_events_enabled()) { + return; + } + /* AIO_WAIT_WHILE() with a NULL context can only be called from the ma= in * loop AioContext, so make sure we're in the main context. */ assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); @@ -566,6 +576,15 @@ void bdrv_drain_all_end(void) { BlockDriverState *bs =3D NULL; =20 + /* + * bdrv queue is managed by record/replay, + * waiting for finishing the I/O requests may + * be endless + */ + if (replay_events_enabled()) { + return; + } + while ((bs =3D bdrv_next_all_states(bs))) { AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 @@ -1998,6 +2017,15 @@ int bdrv_flush_all(void) BlockDriverState *bs =3D NULL; int result =3D 0; =20 + /* + * bdrv queue is managed by record/replay, + * creating new flush request for stopping + * the VM may break the determinism + */ + if (replay_events_enabled()) { + return result; + } + for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; diff --git a/cpus.c b/cpus.c index b09b702712..aa33fb15b3 100644 --- a/cpus.c +++ b/cpus.c @@ -1078,7 +1078,6 @@ static int do_vm_stop(RunState state, bool send_stop) } =20 bdrv_drain_all(); - replay_disable_events(); ret =3D bdrv_flush_all(); =20 return ret; @@ -2149,7 +2148,6 @@ int vm_prepare_start(void) /* We are sending this now, but the CPUs will be resumed shortly later= */ qapi_event_send_resume(); =20 - replay_enable_events(); cpu_enable_ticks(); runstate_set(RUN_STATE_RUNNING); vm_state_notify(1, RUN_STATE_RUNNING); From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355134793197.31034674334342; Tue, 5 Feb 2019 00:25:34 -0800 (PST) Received: from localhost ([127.0.0.1]:56170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw2t-0003OE-O2 for importer@patchew.org; Tue, 05 Feb 2019 03:25:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxy-00084G-Gi for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxx-0008Fp-JX for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:26 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxx-0008Ca-7w for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:25 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 866D3540089; Tue, 5 Feb 2019 11:20:14 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:15 +0300 Message-ID: <154935481562.7509.3286769643322025195.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 06/25] replay: finish record/replay before closing the disks 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" After recent updates block devices cannot be closed on qemu exit. This happens due to the block request polling when replay is not finished. Therefore now we stop execution recording before closing the block devices. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- replay/replay.c | 2 ++ vl.c | 1 + 2 files changed, 3 insertions(+) diff --git a/replay/replay.c b/replay/replay.c index 8b172b2d1b..b75820a1c1 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -385,6 +385,8 @@ void replay_finish(void) g_free(replay_snapshot); replay_snapshot =3D NULL; =20 + replay_mode =3D REPLAY_MODE_NONE; + replay_finish_events(); } =20 diff --git a/vl.c b/vl.c index 8b97ed7b3f..00cf47339e 100644 --- a/vl.c +++ b/vl.c @@ -4674,6 +4674,7 @@ int main(int argc, char **argv, char **envp) =20 /* No more vcpu or device emulation activity beyond this point */ vm_shutdown(); + replay_finish(); =20 job_cancel_sync_all(); bdrv_close_all(); From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355269710693.1907575979579; Tue, 5 Feb 2019 00:27:49 -0800 (PST) Received: from localhost ([127.0.0.1]:56222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw4w-0005HZ-Bt for importer@patchew.org; Tue, 05 Feb 2019 03:27:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxy-00084H-HC for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxx-0008Fj-IJ for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:26 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxw-0008E6-Fp for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:25 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 3975F54008A; Tue, 5 Feb 2019 11:20:20 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:21 +0300 Message-ID: <154935482136.7509.7880533141451228759.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 07/25] qcow2: introduce icount field for snapshots 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch introduces the icount field for saving within the snapshot. It is required for navigation between the snapshots in record/replay mode. Signed-off-by: Pavel Dovgalyuk Acked-by: Kevin Wolf -- v2: - documented format changes in docs/interop/qcow2.txt (suggested by Eric Blake) v10: - updated the documentation reviewed-by for the block-related patches. --- block/qcow2-snapshot.c | 7 +++++++ block/qcow2.h | 2 ++ docs/interop/qcow2.txt | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index bb6a5b7516..d68294658a 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -103,6 +103,12 @@ int qcow2_read_snapshots(BlockDriverState *bs) sn->disk_size =3D bs->total_sectors * BDRV_SECTOR_SIZE; } =20 + if (extra_data_size >=3D 24) { + sn->icount =3D be64_to_cpu(extra.icount); + } else { + sn->icount =3D -1ULL; + } + /* Read snapshot ID */ sn->id_str =3D g_malloc(id_str_size + 1); ret =3D bdrv_pread(bs->file, offset, sn->id_str, id_str_size); @@ -209,6 +215,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) memset(&extra, 0, sizeof(extra)); extra.vm_state_size_large =3D cpu_to_be64(sn->vm_state_size); extra.disk_size =3D cpu_to_be64(sn->disk_size); + extra.icount =3D cpu_to_be64(sn->icount); =20 id_str_size =3D strlen(sn->id_str); name_size =3D strlen(sn->name); diff --git a/block/qcow2.h b/block/qcow2.h index 32cce9eee2..09d13e5b69 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -159,6 +159,7 @@ typedef struct QEMU_PACKED QCowSnapshotHeader { typedef struct QEMU_PACKED QCowSnapshotExtraData { uint64_t vm_state_size_large; uint64_t disk_size; + uint64_t icount; } QCowSnapshotExtraData; =20 =20 @@ -172,6 +173,7 @@ typedef struct QCowSnapshot { uint32_t date_sec; uint32_t date_nsec; uint64_t vm_clock_nsec; + uint64_t icount; } QCowSnapshot; =20 struct Qcow2Cache; diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index fb5cb47245..14ca489e0c 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -540,6 +540,10 @@ Snapshot table entry: =20 Byte 48 - 55: Virtual disk size of the snapshot in b= ytes =20 + Byte 56 - 63: icount value which corresponds to + the record/replay instruction count + when the snapshot was taken + Version 3 images must include extra data at least up to byte 55. =20 From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355134081204.64606768149395; Tue, 5 Feb 2019 00:25:34 -0800 (PST) Received: from localhost ([127.0.0.1]:56168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw2p-0003Kb-UP for importer@patchew.org; Tue, 05 Feb 2019 03:25:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvy1-00084h-2C for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvxz-0008H3-PB for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:29 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33502) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvxz-0008GL-DY for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:27 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id DBFDD540089; Tue, 5 Feb 2019 11:20:25 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:27 +0300 Message-ID: <154935482702.7509.14721831249423314035.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 08/25] migration: introduce icount field for snapshots 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Saving icount as a parameters of the snapshot allows navigation between them in the execution replay scenario. This information can be used for finding a specific snapshot for proceeding the recorded execution to the specific moment of the time. E.g., 'reverse step' action (introduced in one of the following patches) needs to load the nearest snapshot which is prior to the current moment of time . Signed-off-by: Pavel Dovgalyuk Acked-by: Markus Armbruster -- v2: - made icount in SnapshotInfo optional (suggested by Eric Blake) v7: - added more comments for icount member (suggested by Markus Armbruster) v9: - updated icount comment v10: - updated icount comment again reviewed-by for the block-related patches. --- block/qapi.c | 18 ++++++++++++++---- block/qcow2-snapshot.c | 2 ++ blockdev.c | 10 ++++++++++ include/block/snapshot.h | 1 + migration/savevm.c | 5 +++++ qapi/block-core.json | 7 ++++++- qapi/block.json | 3 ++- 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index c66f949db8..ccf23f3b35 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -210,6 +210,8 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs, info->date_nsec =3D sn_tab[i].date_nsec; info->vm_clock_sec =3D sn_tab[i].vm_clock_nsec / 1000000000; info->vm_clock_nsec =3D sn_tab[i].vm_clock_nsec % 1000000000; + info->icount =3D sn_tab[i].icount; + info->has_icount =3D sn_tab[i].icount !=3D -1ULL; =20 info_list =3D g_new0(SnapshotInfoList, 1); info_list->value =3D info; @@ -663,14 +665,15 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf= , void *f, QEMUSnapshotInfo *sn) { char buf1[128], date_buf[128], clock_buf[128]; + char icount_buf[128] =3D {0}; struct tm tm; time_t ti; int64_t secs; =20 if (!sn) { func_fprintf(f, - "%-10s%-20s%7s%20s%15s", - "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK"); + "%-10s%-18s%7s%20s%13s%11s", + "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK", "ICOUNT"); } else { ti =3D sn->date_sec; localtime_r(&ti, &tm); @@ -683,13 +686,18 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf= , void *f, (int)((secs / 60) % 60), (int)(secs % 60), (int)((sn->vm_clock_nsec / 1000000) % 1000)); + if (sn->icount !=3D -1ULL) { + snprintf(icount_buf, sizeof(icount_buf), + "%"PRId64, sn->icount); + } func_fprintf(f, - "%-10s%-20s%7s%20s%15s", + "%-10s%-18s%7s%20s%13s%11s", sn->id_str, sn->name, get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size), date_buf, - clock_buf); + clock_buf, + icount_buf); } } =20 @@ -857,6 +865,8 @@ void bdrv_image_info_dump(fprintf_function func_fprintf= , void *f, .date_nsec =3D elem->value->date_nsec, .vm_clock_nsec =3D elem->value->vm_clock_sec * 1000000000U= LL + elem->value->vm_clock_nsec, + .icount =3D elem->value->has_icount ? + elem->value->icount : -1ULL, }; =20 pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id); diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index d68294658a..96b57f4ec8 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -379,6 +379,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSna= pshotInfo *sn_info) sn->date_sec =3D sn_info->date_sec; sn->date_nsec =3D sn_info->date_nsec; sn->vm_clock_nsec =3D sn_info->vm_clock_nsec; + sn->icount =3D sn_info->icount; =20 /* Allocate the L1 table of the snapshot and copy the current one ther= e. */ l1_table_offset =3D qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint6= 4_t)); @@ -698,6 +699,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnaps= hotInfo **psn_tab) sn_info->date_sec =3D sn->date_sec; sn_info->date_nsec =3D sn->date_nsec; sn_info->vm_clock_nsec =3D sn->vm_clock_nsec; + sn_info->icount =3D sn->icount; } *psn_tab =3D sn_tab; return s->nb_snapshots; diff --git a/blockdev.c b/blockdev.c index fb18e9c975..f5775fdf5a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -57,6 +57,7 @@ #include "block/trace.h" #include "sysemu/arch_init.h" #include "sysemu/qtest.h" +#include "sysemu/replay.h" #include "qemu/cutils.h" #include "qemu/help_option.h" #include "qemu/throttle-options.h" @@ -1239,6 +1240,10 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_= sync(const char *device, info->vm_state_size =3D sn.vm_state_size; info->vm_clock_nsec =3D sn.vm_clock_nsec % 1000000000; info->vm_clock_sec =3D sn.vm_clock_nsec / 1000000000; + if (sn.icount !=3D -1ULL) { + info->icount =3D sn.icount; + info->has_icount =3D true; + } =20 return info; =20 @@ -1447,6 +1452,11 @@ static void internal_snapshot_prepare(BlkActionState= *common, sn->date_sec =3D tv.tv_sec; sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (replay_mode !=3D REPLAY_MODE_NONE) { + sn->icount =3D replay_get_current_step(); + } else { + sn->icount =3D -1ULL; + } =20 ret1 =3D bdrv_snapshot_create(bs, sn); if (ret1 < 0) { diff --git a/include/block/snapshot.h b/include/block/snapshot.h index f73d1094af..c9c89754ef 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -42,6 +42,7 @@ typedef struct QEMUSnapshotInfo { uint32_t date_sec; /* UTC date of the snapshot */ uint32_t date_nsec; uint64_t vm_clock_nsec; /* VM clock relative to boot */ + uint64_t icount; /* record/replay step */ } QEMUSnapshotInfo; =20 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, diff --git a/migration/savevm.c b/migration/savevm.c index 322660438d..fa3b9d1a54 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2510,6 +2510,11 @@ int save_snapshot(const char *name, Error **errp) sn->date_sec =3D tv.tv_sec; sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (replay_mode !=3D REPLAY_MODE_NONE) { + sn->icount =3D replay_get_current_step(); + } else { + sn->icount =3D -1ULL; + } =20 if (name) { ret =3D bdrv_snapshot_find(bs, old_sn, name); diff --git a/qapi/block-core.json b/qapi/block-core.json index 5f17d67d71..69ec06e8ac 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -26,13 +26,18 @@ # # @vm-clock-nsec: fractional part in nano seconds to be used with vm-clock= -sec # +# @icount: Current instruction count. Appears when execution record/replay +# is enabled. Used for "time-traveling" to match the moment +# in the recorded execution with the snapshots. (since 4.0) +# # Since: 1.3 # ## { 'struct': 'SnapshotInfo', 'data': { 'id': 'str', 'name': 'str', 'vm-state-size': 'int', 'date-sec': 'int', 'date-nsec': 'int', - 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } } + 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int', + '*icount': 'int' } } =20 ## # @ImageInfoSpecificQCow2EncryptionBase: diff --git a/qapi/block.json b/qapi/block.json index 5a79d639e8..fd9c0ee715 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -176,7 +176,8 @@ # "date-sec": 1000012, # "date-nsec": 10, # "vm-clock-sec": 100, -# "vm-clock-nsec": 20 +# "vm-clock-nsec": 20, +# "icount": 220414 # } # } # From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355304391264.4919874986897; Tue, 5 Feb 2019 00:28:24 -0800 (PST) Received: from localhost ([127.0.0.1]:56232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw5Y-0005my-8q for importer@patchew.org; Tue, 05 Feb 2019 03:28:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyA-0008Dc-KK for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvy7-0008O3-QK for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:37 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvy5-0008Mn-Np for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:35 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 86371540089; Tue, 5 Feb 2019 11:20:31 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:32 +0300 Message-ID: <154935483268.7509.14506888393182010328.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 09/25] replay: provide an accessor for rr filename 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch adds an accessor function for the name of the record/replay log file. Adding an accessor instead of making variable global, prevents accidental modification of this variable by other modules. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- include/sysemu/replay.h | 2 ++ replay/replay.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 3a7c58e423..b3f593f2f0 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -71,6 +71,8 @@ void replay_start(void); void replay_finish(void); /*! Adds replay blocker with the specified error description */ void replay_add_blocker(Error *reason); +/* Returns name of the replay log file */ +const char *replay_get_filename(void); =20 /* Processing the instructions */ =20 diff --git a/replay/replay.c b/replay/replay.c index b75820a1c1..aa534116b5 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -394,3 +394,8 @@ void replay_add_blocker(Error *reason) { replay_blockers =3D g_slist_prepend(replay_blockers, reason); } + +const char *replay_get_filename(void) +{ + return replay_filename; +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355467199184.00677299030144; Tue, 5 Feb 2019 00:31:07 -0800 (PST) Received: from localhost ([127.0.0.1]:56284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw8D-0008E8-4M for importer@patchew.org; Tue, 05 Feb 2019 03:31:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyD-0008GE-I7 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyC-0008Q3-88 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:41 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyB-0008PB-BW for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:40 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id DD629540089; Tue, 5 Feb 2019 11:20:37 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:39 +0300 Message-ID: <154935483903.7509.2641437081687401076.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 10/25] qapi: introduce replay.json for record/replay-related stuff 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch adds replay.json file. It will be used for adding record/replay-related data structures and commands. Signed-off-by: Pavel Dovgalyuk Reviewed-by: Markus Armbruster -- v10: - minor changes reviewed-by for the block-related patches. --- MAINTAINERS | 1 + Makefile.objs | 4 ++-- include/sysemu/replay.h | 2 +- qapi/misc.json | 18 ------------------ qapi/qapi-schema.json | 1 + qapi/replay.json | 26 ++++++++++++++++++++++++++ 6 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 qapi/replay.json diff --git a/MAINTAINERS b/MAINTAINERS index 9a76845581..330b5f6181 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2131,6 +2131,7 @@ F: net/filter-replay.c F: include/sysemu/replay.h F: docs/replay.txt F: stubs/replay.c +F: qapi/replay.json =20 IOVA Tree M: Peter Xu diff --git a/Makefile.objs b/Makefile.objs index 67a054b08a..098691fad3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,6 +1,6 @@ QAPI_MODULES =3D block-core block char common crypto introspect job migrat= ion -QAPI_MODULES +=3D misc net rdma rocker run-state sockets tpm trace transac= tion -QAPI_MODULES +=3D ui +QAPI_MODULES +=3D misc net rdma replay rocker run-state sockets tpm trace +QAPI_MODULES +=3D transaction ui =20 ####################################################################### # Common libraries for tools and emulators diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index b3f593f2f0..3fe14b5f57 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -13,7 +13,7 @@ */ =20 #include "sysemu.h" -#include "qapi/qapi-types-misc.h" +#include "qapi/qapi-types-replay.h" #include "qapi/qapi-types-ui.h" =20 /* replay clock kinds */ diff --git a/qapi/misc.json b/qapi/misc.json index 426274ecf8..8eef451700 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3160,24 +3160,6 @@ { 'event': 'RTC_CHANGE', 'data': { 'offset': 'int' } } =20 -## -# @ReplayMode: -# -# Mode of the replay subsystem. -# -# @none: normal execution mode. Replay or record are not enabled. -# -# @record: record mode. All non-deterministic data is written into the -# replay log. -# -# @play: replay mode. Non-deterministic data required for system execution -# is read from the log. -# -# Since: 2.5 -## -{ 'enum': 'ReplayMode', - 'data': [ 'none', 'record', 'play' ] } - ## # @xen-load-devices-state: # diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 1845aa78ff..ac4b136f3e 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -96,4 +96,5 @@ { 'include': 'transaction.json' } { 'include': 'trace.json' } { 'include': 'introspect.json' } +{ 'include': 'replay.json' } { 'include': 'misc.json' } diff --git a/qapi/replay.json b/qapi/replay.json new file mode 100644 index 0000000000..9e13551d20 --- /dev/null +++ b/qapi/replay.json @@ -0,0 +1,26 @@ +# -*- Mode: Python -*- +# + +## +# =3D Record/replay +## + +{ 'include': 'common.json' } + +## +# @ReplayMode: +# +# Mode of the replay subsystem. +# +# @none: normal execution mode. Replay or record are not enabled. +# +# @record: record mode. All non-deterministic data is written into the +# replay log. +# +# @play: replay mode. Non-deterministic data required for system execution +# is read from the log. +# +# Since: 2.5 +## +{ 'enum': 'ReplayMode', + 'data': [ 'none', 'record', 'play' ] } From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15493554271064.726912210007185; Tue, 5 Feb 2019 00:30:27 -0800 (PST) Received: from localhost ([127.0.0.1]:56248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw7Z-0007g5-02 for importer@patchew.org; Tue, 05 Feb 2019 03:30:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyK-0008Mm-EB for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyH-0008SB-Cj for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:46 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyH-0008Rg-0t for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:45 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 89AAA540089; Tue, 5 Feb 2019 11:20:43 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:44 +0300 Message-ID: <154935484469.7509.13604340421487424814.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 11/25] replay: introduce info hmp/qmp command 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch introduces 'info replay' monitor command and corresponding qmp request. These commands request the current record/replay mode, replay log file name, and the instruction count (number of recorded/replayed instructions). The instruction count can be used with the replay_seek/replay_break commands added in the next two patches. Signed-off-by: Pavel Dovgalyuk Acked-by: Dr. David Alan Gilbert Acked-by: Markus Armbruster -- v2: - renamed info_replay qmp into query-replay (suggested by Eric Blake) v7: - added empty line (suggested by Markus Armbruster) v9: - changed 'step' parameter name to 'icount' - moved json stuff to replay.json and updated the descriptions (suggested by Markus Armbruster) v10: - updated descriptions and messages for rr stuff reviewed-by for the block-related patches. --- hmp-commands-info.hx | 14 ++++++++++++++ hmp.h | 1 + qapi/block-core.json | 3 ++- qapi/replay.json | 39 +++++++++++++++++++++++++++++++++++++++ replay/Makefile.objs | 3 ++- replay/replay-debugging.c | 43 +++++++++++++++++++++++++++++++++++++++++= ++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 replay/replay-debugging.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index cbee8b944d..7cc0baadba 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -916,6 +916,20 @@ STEXI @item info sev @findex info sev Show SEV information. +ETEXI + + { + .name =3D "replay", + .args_type =3D "", + .params =3D "", + .help =3D "show record/replay information", + .cmd =3D hmp_info_replay, + }, + +STEXI +@item info replay +@findex info replay +Display the record/replay information: mode and the current icount. ETEXI =20 STEXI diff --git a/hmp.h b/hmp.h index 5f1addcca2..d792149f24 100644 --- a/hmp.h +++ b/hmp.h @@ -148,5 +148,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *q= dict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); +void hmp_info_replay(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi/block-core.json b/qapi/block-core.json index 69ec06e8ac..9a6e18f3c9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -28,7 +28,8 @@ # # @icount: Current instruction count. Appears when execution record/replay # is enabled. Used for "time-traveling" to match the moment -# in the recorded execution with the snapshots. (since 4.0) +# in the recorded execution with the snapshots. This counter may +# be obtained through @query-replay command (since 4.0) # # Since: 1.3 # diff --git a/qapi/replay.json b/qapi/replay.json index 9e13551d20..4206150544 100644 --- a/qapi/replay.json +++ b/qapi/replay.json @@ -24,3 +24,42 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @ReplayInfo: +# +# Record/replay information. +# +# @mode: current mode. +# +# @filename: name of the record/replay log file. +# It is present only in record or replay modes, when the log +# is recorded or replayed. +# +# @icount: current number of executed instructions. +# +# Since: 4.0 +# +## +{ 'struct': 'ReplayInfo', + 'data': { 'mode': 'ReplayMode', '*filename': 'str', 'icount': 'int' } } + +## +# @query-replay: +# +# Retrieve the record/replay information. +# It includes current instruction count which may be used for +# @replay-break and @replay-seek commands. +# +# Returns: record/replay information. +# +# Since: 4.0 +# +# Example: +# +# -> { "execute": "query-replay" } +# <- { "return": { "mode": "play", "filename": "log.rr", "icount": 220414 = } } +# +## +{ 'command': 'query-replay', + 'returns': 'ReplayInfo' } diff --git a/replay/Makefile.objs b/replay/Makefile.objs index cee6539a23..6694e3e2a2 100644 --- a/replay/Makefile.objs +++ b/replay/Makefile.objs @@ -6,4 +6,5 @@ common-obj-y +=3D replay-input.o common-obj-y +=3D replay-char.o common-obj-y +=3D replay-snapshot.o common-obj-y +=3D replay-net.o -common-obj-y +=3D replay-audio.o \ No newline at end of file +common-obj-y +=3D replay-audio.o +common-obj-y +=3D replay-debugging.o diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c new file mode 100644 index 0000000000..51f1c4d82d --- /dev/null +++ b/replay/replay-debugging.c @@ -0,0 +1,43 @@ +/* + * replay-debugging.c + * + * Copyright (c) 2010-2018 Institute for System Programming + * of the Russian Academy of Sciences. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/replay.h" +#include "replay-internal.h" +#include "hmp.h" +#include "monitor/monitor.h" +#include "qapi/qapi-commands-replay.h" + +void hmp_info_replay(Monitor *mon, const QDict *qdict) +{ + if (replay_mode =3D=3D REPLAY_MODE_NONE) { + monitor_printf(mon, "Record/replay is not active\n"); + } else { + monitor_printf(mon, + "%s execution '%s': instruction count =3D %"PRId64"\n", + replay_mode =3D=3D REPLAY_MODE_RECORD ? "Recording" : "Replayi= ng", + replay_get_filename(), replay_get_current_step()); + } +} + +ReplayInfo *qmp_query_replay(Error **errp) +{ + ReplayInfo *retval =3D g_new0(ReplayInfo, 1); + + retval->mode =3D replay_mode; + if (replay_get_filename()) { + retval->filename =3D g_strdup(replay_get_filename()); + retval->has_filename =3D true; + } + retval->icount =3D replay_get_current_step(); + return retval; +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15493552893322.743071034162199; Tue, 5 Feb 2019 00:28:09 -0800 (PST) Received: from localhost ([127.0.0.1]:56230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw5F-0005XY-13 for importer@patchew.org; Tue, 05 Feb 2019 03:27:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyU-00006f-7U for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyQ-00007v-Bp for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:56 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyO-0008V9-8l for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:54 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 332B2540089; Tue, 5 Feb 2019 11:20:49 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:50 +0300 Message-ID: <154935485034.7509.10540246603743274403.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 12/25] replay: introduce breakpoint at the specified step 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch introduces replay_break, replay_delete_break qmp and hmp commands. These commands allow stopping at the specified instruction. It may be useful for debugging when there are some known events that should be investigated. replay_break command has one argument - number of instructions executed since the start of the replay. replay_delete_break removes previously set breakpoint. Signed-off-by: Pavel Dovgalyuk Acked-by: Markus Armbruster -- v2: - renamed replay_break qmp command into replay-break (suggested by Eric Blake) v7: - introduces replay_delete_break command v9: - changed 'step' parameter name to 'icount' - moved json stuff to replay.json and updated the description (suggested by Markus Armbruster) v10: - updated descriptions (suggested by Markus Armbruster) reviewed-by for the block-related patches. --- hmp-commands.hx | 34 ++++++++++++++++++ hmp.h | 2 + qapi/replay.json | 36 +++++++++++++++++++ replay/replay-debugging.c | 86 +++++++++++++++++++++++++++++++++++++++++= ++++ replay/replay-internal.h | 4 ++ replay/replay.c | 17 +++++++++ 6 files changed, 179 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index ba71558c25..2ec8cb8254 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1887,6 +1887,40 @@ ETEXI STEXI @item qom-set @var{path} @var{property} @var{value} Set QOM property @var{property} of object at location @var{path} to value = @var{value} +ETEXI + + { + .name =3D "replay_break", + .args_type =3D "icount:i", + .params =3D "icount", + .help =3D "set breakpoint at the specified instruction count= ", + .cmd =3D hmp_replay_break, + }, + +STEXI +@item replay_break @var{icount} +@findex replay_break +Set replay breakpoint at instruction count @var{icount}. +Execution stops when the specified instruction is reached. +There can be at most one breakpoint. When breakpoint is set, any prior +one is removed. The breakpoint may be set only in replay mode and only +"in the future", i.e. at instruction counts greater than the current one. +The current instruction count can be observed with 'info replay'. +ETEXI + + { + .name =3D "replay_delete_break", + .args_type =3D "", + .params =3D "", + .help =3D "removes replay breakpoint", + .cmd =3D hmp_replay_delete_break, + }, + +STEXI +@item replay_delete_break +@findex replay_delete_break +Remove replay breakpoint which was previously set with replay_break. +The command is ignored when there are no replay breakpoints. ETEXI =20 { diff --git a/hmp.h b/hmp.h index d792149f24..c9b9b4f8c4 100644 --- a/hmp.h +++ b/hmp.h @@ -149,5 +149,7 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDic= t *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_info_replay(Monitor *mon, const QDict *qdict); +void hmp_replay_break(Monitor *mon, const QDict *qdict); +void hmp_replay_delete_break(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi/replay.json b/qapi/replay.json index 4206150544..84c148cc4e 100644 --- a/qapi/replay.json +++ b/qapi/replay.json @@ -63,3 +63,39 @@ ## { 'command': 'query-replay', 'returns': 'ReplayInfo' } + +## +# @replay-break: +# +# Set replay breakpoint at instruction count @icount. +# Execution stops when the specified instruction is reached. +# There can be at most one breakpoint. When breakpoint is set, any prior +# one is removed. The breakpoint may be set only in replay mode and only +# "in the future", i.e. at instruction counts greater than the current one. +# The current instruction count can be observed with @query-replay. +# +# @icount: instruction count to stop at +# +# Since: 4.0 +# +# Example: +# +# -> { "execute": "replay-break", "data": { "icount": 220414 } } +# +## +{ 'command': 'replay-break', 'data': { 'icount': 'int' } } + +## +# @replay-delete-break: +# +# Remove replay breakpoint which was set with @replay-break. +# The command is ignored when there are no replay breakpoints. +# +# Since: 4.0 +# +# Example: +# +# -> { "execute": "replay-delete-break" } +# +## +{ 'command': 'replay-delete-break' } diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 51f1c4d82d..a94685e437 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -16,6 +16,8 @@ #include "hmp.h" #include "monitor/monitor.h" #include "qapi/qapi-commands-replay.h" +#include "qapi/qmp/qdict.h" +#include "qemu/timer.h" =20 void hmp_info_replay(Monitor *mon, const QDict *qdict) { @@ -41,3 +43,87 @@ ReplayInfo *qmp_query_replay(Error **errp) retval->icount =3D replay_get_current_step(); return retval; } + +static void replay_break(uint64_t icount, QEMUTimerCB callback, void *opaq= ue) +{ + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + assert(replay_mutex_locked()); + assert(replay_break_icount >=3D replay_get_current_step()); + assert(callback); + + replay_break_icount =3D icount; + + if (replay_break_timer) { + timer_del(replay_break_timer); + } else { + replay_break_timer =3D timer_new_ns(QEMU_CLOCK_REALTIME, + callback, opaque); + } +} + +static void replay_delete_break(void) +{ + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + assert(replay_mutex_locked()); + + if (replay_break_timer) { + timer_del(replay_break_timer); + timer_free(replay_break_timer); + replay_break_timer =3D NULL; + } + replay_break_icount =3D -1ULL; +} + +static void replay_stop_vm(void *opaque) +{ + vm_stop(RUN_STATE_PAUSED); + replay_delete_break(); +} + +void qmp_replay_break(int64_t icount, Error **errp) +{ + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + if (icount >=3D replay_get_current_step()) { + replay_break(icount, replay_stop_vm, NULL); + } else { + error_setg(errp, + "cannot set breakpoint at the instruction in the past"); + } + } else { + error_setg(errp, "setting the breakpoint is allowed only in play m= ode"); + } +} + +void hmp_replay_break(Monitor *mon, const QDict *qdict) +{ + int64_t icount =3D qdict_get_try_int(qdict, "icount", -1LL); + Error *err =3D NULL; + + qmp_replay_break(icount, &err); + if (err) { + error_report_err(err); + error_free(err); + return; + } +} + +void qmp_replay_delete_break(Error **errp) +{ + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + replay_delete_break(); + } else { + error_setg(errp, "replay breakpoints are allowed only in play mode= "); + } +} + +void hmp_replay_delete_break(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + + qmp_replay_delete_break(&err); + if (err) { + error_report_err(err); + error_free(err); + return; + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index af6f4d55d4..8c15a41350 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -91,6 +91,10 @@ extern ReplayState replay_state; =20 /* File for replay writing */ extern FILE *replay_file; +/* Instruction count of the replay breakpoint */ +extern uint64_t replay_break_icount; +/* Timer for the replay breakpoint callback */ +extern QEMUTimer *replay_break_timer; =20 void replay_put_byte(uint8_t byte); void replay_put_event(uint8_t event); diff --git a/replay/replay.c b/replay/replay.c index aa534116b5..1be34aa824 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -34,6 +34,10 @@ static char *replay_filename; ReplayState replay_state; static GSList *replay_blockers; =20 +/* Replay breakpoints */ +uint64_t replay_break_icount =3D -1ULL; +QEMUTimer *replay_break_timer; + bool replay_next_event_is(int event) { bool res =3D false; @@ -73,6 +77,13 @@ int replay_get_instructions(void) replay_mutex_lock(); if (replay_next_event_is(EVENT_INSTRUCTION)) { res =3D replay_state.instructions_count; + if (replay_break_icount !=3D -1LL) { + uint64_t current =3D replay_get_current_step(); + assert(replay_break_icount >=3D current); + if (current + res > replay_break_icount) { + res =3D replay_break_icount - current; + } + } } replay_mutex_unlock(); return res; @@ -99,6 +110,12 @@ void replay_account_executed_instructions(void) will be read from the log. */ qemu_notify_event(); } + /* Execution reached the break step */ + if (replay_break_icount =3D=3D replay_state.current_step) { + /* Cannot make callback directly from the vCPU thread */ + timer_mod_ns(replay_break_timer, + qemu_clock_get_ns(QEMU_CLOCK_REALTIME)); + } } } } From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355667207384.274719020314; Tue, 5 Feb 2019 00:34:27 -0800 (PST) Received: from localhost ([127.0.0.1]:56313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwBR-0002II-4n for importer@patchew.org; Tue, 05 Feb 2019 03:34:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyW-000090-CL for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyU-0000Bx-Mw for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:00 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyU-00008d-9M for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:20:58 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id D9C49540089; Tue, 5 Feb 2019 11:20:54 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:20:56 +0300 Message-ID: <154935485599.7509.10172876427978603259.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 13/25] replay: implement replay-seek command 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch adds hmp/qmp commands replay_seek/replay-seek that proceed the execution to the specified instruction count. The command automatically loads nearest snapshot and replays the execution to find the desired instruction count. Signed-off-by: Pavel Dovgalyuk Acked-by: Markus Armbruster -- v2: - renamed replay_seek qmp command into replay-seek (suggested by Eric Blake) v7: - small fixes related to Markus Armbruster's review v9: - changed 'step' parameter name to 'icount' - moved json stuff to replay.json and updated the description (suggested by Markus Armbruster) v10: - updated the descriptions reviewed-by for the block-related patches. --- hmp-commands.hx | 19 +++++++++ hmp.h | 1=20 qapi/replay.json | 20 ++++++++++ replay/replay-debugging.c | 92 +++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 132 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 2ec8cb8254..3c077a55e6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1921,6 +1921,25 @@ STEXI @findex replay_delete_break Remove replay breakpoint which was previously set with replay_break. The command is ignored when there are no replay breakpoints. +ETEXI + + { + .name =3D "replay_seek", + .args_type =3D "icount:i", + .params =3D "icount", + .help =3D "replay execution to the specified instruction cou= nt", + .cmd =3D hmp_replay_seek, + }, + +STEXI +@item replay_seek @var{icount} +@findex replay_seek +Automatically proceed to the instruction count @var{icount}, when +replaying the execution. The command automatically loads nearest +snapshot and replays the execution to find the desired instruction. +When there is no preceding snapshot or the execution is not replayed, +then the command fails. +icount for the reference may be observed with 'info replay' command. ETEXI =20 { diff --git a/hmp.h b/hmp.h index c9b9b4f8c4..d6e1d7e90b 100644 --- a/hmp.h +++ b/hmp.h @@ -151,5 +151,6 @@ void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_info_replay(Monitor *mon, const QDict *qdict); void hmp_replay_break(Monitor *mon, const QDict *qdict); void hmp_replay_delete_break(Monitor *mon, const QDict *qdict); +void hmp_replay_seek(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi/replay.json b/qapi/replay.json index 84c148cc4e..550fb2e6cf 100644 --- a/qapi/replay.json +++ b/qapi/replay.json @@ -99,3 +99,23 @@ # ## { 'command': 'replay-delete-break' } + +## +# @replay-seek: +# +# Automatically proceed to the instruction count @icount, when +# replaying the execution. The command automatically loads nearest +# snapshot and replays the execution to find the desired instruction. +# When there is no preceding snapshot or the execution is not replayed, +# then the command fails. +# icount for the reference may be obtained with @query-replay command. +# +# @icount: target instruction count +# +# Since: 4.0 +# +# Example: +# +# -> { "execute": "replay-seek", "data": { "icount": 220414 } } +## +{ 'command': 'replay-seek', 'data': { 'icount': 'int' } } diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index a94685e437..e3821ab1ba 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -18,6 +18,8 @@ #include "qapi/qapi-commands-replay.h" #include "qapi/qmp/qdict.h" #include "qemu/timer.h" +#include "block/snapshot.h" +#include "migration/snapshot.h" =20 void hmp_info_replay(Monitor *mon, const QDict *qdict) { @@ -127,3 +129,93 @@ void hmp_replay_delete_break(Monitor *mon, const QDict= *qdict) return; } } + +static char *replay_find_nearest_snapshot(int64_t icount, + int64_t *snapshot_icount) +{ + BlockDriverState *bs; + QEMUSnapshotInfo *sn_tab; + QEMUSnapshotInfo *nearest =3D NULL; + char *ret =3D NULL; + int nb_sns, i; + AioContext *aio_context; + + *snapshot_icount =3D -1; + + bs =3D bdrv_all_find_vmstate_bs(); + if (!bs) { + goto fail; + } + aio_context =3D bdrv_get_aio_context(bs); + + aio_context_acquire(aio_context); + nb_sns =3D bdrv_snapshot_list(bs, &sn_tab); + aio_context_release(aio_context); + + for (i =3D 0; i < nb_sns; i++) { + if (bdrv_all_find_snapshot(sn_tab[i].name, &bs) =3D=3D 0) { + if (sn_tab[i].icount !=3D -1ULL + && sn_tab[i].icount <=3D icount + && (!nearest || nearest->icount < sn_tab[i].icount)) { + nearest =3D &sn_tab[i]; + } + } + } + if (nearest) { + ret =3D g_strdup(nearest->name); + *snapshot_icount =3D nearest->icount; + } + g_free(sn_tab); + +fail: + return ret; +} + +static void replay_seek(int64_t icount, QEMUTimerCB callback, Error **errp) +{ + char *snapshot =3D NULL; + int64_t snapshot_icount; + + if (replay_mode !=3D REPLAY_MODE_PLAY) { + error_setg(errp, "replay must be enabled to seek"); + return; + } + if (!replay_snapshot) { + error_setg(errp, "snapshotting is disabled"); + return; + } + + snapshot =3D replay_find_nearest_snapshot(icount, &snapshot_icount); + if (snapshot) { + if (icount < replay_get_current_step() + || replay_get_current_step() < snapshot_icount) { + vm_stop(RUN_STATE_RESTORE_VM); + load_snapshot(snapshot, errp); + } + g_free(snapshot); + } + if (replay_get_current_step() <=3D icount) { + replay_break(icount, callback, NULL); + vm_start(); + } else { + error_setg(errp, "cannot seek to the specified instruction count"); + } +} + +void qmp_replay_seek(int64_t icount, Error **errp) +{ + replay_seek(icount, replay_stop_vm, errp); +} + +void hmp_replay_seek(Monitor *mon, const QDict *qdict) +{ + int64_t icount =3D qdict_get_try_int(qdict, "icount", -1LL); + Error *err =3D NULL; + + qmp_replay_seek(icount, &err); + if (err) { + error_report_err(err); + error_free(err); + return; + } +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355448153765.7720923006949; Tue, 5 Feb 2019 00:30:48 -0800 (PST) Received: from localhost ([127.0.0.1]:56268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw7q-0007wH-3H for importer@patchew.org; Tue, 05 Feb 2019 03:30:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyY-0000C0-IB for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyX-0000Fu-L2 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:02 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyX-0000FA-DA for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:01 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 8245A540089; Tue, 5 Feb 2019 11:21:00 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:01 +0300 Message-ID: <154935486167.7509.11882555468888632462.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 14/25] replay: refine replay-time module 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch removes refactoring artifacts from the replay/replay-time.c Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- replay/replay-time.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/replay/replay-time.c b/replay/replay-time.c index 0df1693337..60f47b73a7 100644 --- a/replay/replay-time.c +++ b/replay/replay-time.c @@ -15,18 +15,19 @@ #include "replay-internal.h" #include "qemu/error-report.h" =20 -int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, int64_t raw= _icount) +int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, + int64_t raw_icount) { - if (replay_file) { - g_assert(replay_mutex_locked()); + g_assert(replay_file); + g_assert(replay_mutex_locked()); =20 - /* Due to the caller's locking requirements we get the icount from= it - * instead of using replay_save_instructions(). - */ - replay_advance_current_step(raw_icount); - replay_put_event(EVENT_CLOCK + kind); - replay_put_qword(clock); - } + /* + * Due to the caller's locking requirements we get the icount from it + * instead of using replay_save_instructions(). + */ + replay_advance_current_step(raw_icount); + replay_put_event(EVENT_CLOCK + kind); + replay_put_qword(clock); =20 return clock; } @@ -48,20 +49,15 @@ void replay_read_next_clock(ReplayClockKind kind) /*! Reads next clock event from the input. */ int64_t replay_read_clock(ReplayClockKind kind) { + int64_t ret; g_assert(replay_file && replay_mutex_locked()); =20 replay_account_executed_instructions(); =20 - if (replay_file) { - int64_t ret; - if (replay_next_event_is(EVENT_CLOCK + kind)) { - replay_read_next_clock(kind); - } - ret =3D replay_state.cached_clock[kind]; - - return ret; + if (replay_next_event_is(EVENT_CLOCK + kind)) { + replay_read_next_clock(kind); } + ret =3D replay_state.cached_clock[kind]; =20 - error_report("REPLAY INTERNAL ERROR %d", __LINE__); - exit(1); + return ret; } From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355360963860.5950619145584; Tue, 5 Feb 2019 00:29:20 -0800 (PST) Received: from localhost ([127.0.0.1]:56238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw6U-0006dH-Mz for importer@patchew.org; Tue, 05 Feb 2019 03:29:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvye-0000FP-B6 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyd-0000OM-I9 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:08 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyd-0000NU-Aa for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:07 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 39D97540089; Tue, 5 Feb 2019 11:21:06 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:07 +0300 Message-ID: <154935486729.7509.1713779951598019570.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 15/25] replay: flush rr queue before loading the vmstate 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Non-empty record/replay queue prevents saving and loading the VM state, because it includes pending bottom halves and block coroutines. But when the new VM state is loaded, we don't have to preserve the consiste= ncy of the current state anymore. Therefore this patch just flushes the queue allowing the coroutines to finish. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- include/sysemu/replay.h | 2 ++ migration/savevm.c | 6 ++++++ replay/replay-internal.h | 2 -- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 3fe14b5f57..d7e859d915 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -140,6 +140,8 @@ void replay_disable_events(void); void replay_enable_events(void); /*! Returns true when saving events is enabled */ bool replay_events_enabled(void); +/* Flushes events queue */ +void replay_flush_events(void); /*! Adds bottom half event to the queue */ void replay_bh_schedule_event(QEMUBH *bh); /*! Adds input event to the queue */ diff --git a/migration/savevm.c b/migration/savevm.c index fa3b9d1a54..eea97b4a8f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2702,6 +2702,12 @@ int load_snapshot(const char *name, Error **errp) return -EINVAL; } =20 + /* + * Flush the record/replay queue. Now the VM state is going + * to change. Therefore we don't need to preserve its consistency + */ + replay_flush_events(); + /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 8c15a41350..945802361b 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -146,8 +146,6 @@ void replay_read_next_clock(unsigned int kind); void replay_init_events(void); /*! Clears internal data structures for events handling */ void replay_finish_events(void); -/*! Flushes events queue */ -void replay_flush_events(void); /*! Returns true if there are any unsaved events in the queue */ bool replay_has_events(void); /*! Saves events from queue into the file */ From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355867058614.8401096189862; Tue, 5 Feb 2019 00:37:47 -0800 (PST) Received: from localhost ([127.0.0.1]:56372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwEc-0004qU-Vz for importer@patchew.org; Tue, 05 Feb 2019 03:37:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyk-0000J8-Mc for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyj-0000Wt-Db for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:14 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyj-0000W5-1B for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:13 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 27A30540089; Tue, 5 Feb 2019 11:21:12 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:13 +0300 Message-ID: <154935487327.7509.5368327029472083307.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 16/25] gdbstub: add reverse step support in replay mode 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" GDB remote protocol supports two reverse debugging commands: reverse step and reverse continue. This patch adds support of the first one to the gdbstub. Reverse step is intended to step one instruction in the backwards direction. This is not possible in regular execution. But replayed execution is deterministic, therefore we can load one of the prior snapshots and proceed to the desired step. It is equivalent to stepping one instruction back. There should be at least one snapshot preceding the debugged part of the replay log. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- accel/tcg/translator.c | 1 + cpus.c | 14 +++++++++++--- exec.c | 7 +++++++ gdbstub.c | 44 +++++++++++++++++++++++++++++++++++++++++= --- include/sysemu/replay.h | 11 +++++++++++ replay/replay-debugging.c | 33 +++++++++++++++++++++++++++++++++ stubs/replay.c | 5 +++++ 7 files changed, 109 insertions(+), 6 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index afd0a49ea6..33a543e82f 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -17,6 +17,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "sysemu/replay.h" =20 /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if diff --git a/cpus.c b/cpus.c index aa33fb15b3..013341ca4f 100644 --- a/cpus.c +++ b/cpus.c @@ -1104,9 +1104,17 @@ static bool cpu_can_run(CPUState *cpu) =20 static void cpu_handle_guest_debug(CPUState *cpu) { - gdb_set_stop_cpu(cpu); - qemu_system_debug_request(); - cpu->stopped =3D true; + if (!replay_running_debug()) { + gdb_set_stop_cpu(cpu); + qemu_system_debug_request(); + cpu->stopped =3D true; + } else { + if (!cpu->singlestep_enabled) { + cpu_single_step(cpu, SSTEP_ENABLE); + } else { + cpu_single_step(cpu, 0); + } + } } =20 #ifdef CONFIG_LINUX diff --git a/exec.c b/exec.c index 03dd673d36..fdbd65c5b8 100644 --- a/exec.c +++ b/exec.c @@ -2742,6 +2742,13 @@ static void check_watchpoint(int offset, int len, Me= mTxAttrs attrs, int flags) QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { if (cpu_watchpoint_address_matches(wp, vaddr, len) && (wp->flags & flags)) { + if (replay_running_debug()) { + /* + * Don't process the watchpoints when we are + * in a reverse debugging operation. + */ + return; + } if (flags =3D=3D BP_MEM_READ) { wp->flags |=3D BP_WATCHPOINT_HIT_READ; } else { diff --git a/gdbstub.c b/gdbstub.c index 3129b5c284..d9bf3863c1 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -39,6 +39,7 @@ #include "sysemu/kvm.h" #include "exec/semihost.h" #include "exec/exec-all.h" +#include "sysemu/replay.h" =20 #ifdef CONFIG_USER_ONLY #define GDB_ATTACHED "0" @@ -344,6 +345,20 @@ typedef struct GDBState { */ static int sstep_flags =3D SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; =20 +/* Retrieves flags for single step mode. */ +static int get_sstep_flags(void) +{ + /* + * In replay mode all events written into the log should be replayed. + * That is why NOIRQ flag is removed in this mode. + */ + if (replay_mode !=3D REPLAY_MODE_NONE) { + return SSTEP_ENABLE; + } else { + return sstep_flags; + } +} + static GDBState *gdbserver_state; =20 bool gdb_has_xml; @@ -434,7 +449,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) CPU_FOREACH(cpu) { if (newstates[cpu->cpu_index] =3D=3D 's') { trace_gdbstub_op_stepping(cpu->cpu_index); - cpu_single_step(cpu, sstep_flags); + cpu_single_step(cpu, get_sstep_flags()); } } s->running_state =3D 1; @@ -453,7 +468,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) break; /* nothing to do here */ case 's': trace_gdbstub_op_stepping(cpu->cpu_index); - cpu_single_step(cpu, sstep_flags); + cpu_single_step(cpu, get_sstep_flags()); cpu_resume(cpu); flag =3D 1; break; @@ -1409,9 +1424,28 @@ static int gdb_handle_packet(GDBState *s, const char= *line_buf) addr =3D strtoull(p, (char **)&p, 16); gdb_set_cpu_pc(s, addr); } - cpu_single_step(s->c_cpu, sstep_flags); + cpu_single_step(s->c_cpu, get_sstep_flags()); gdb_continue(s); return RS_IDLE; + case 'b': + /* Backward debugging commands */ + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + switch (*p) { + case 's': + if (replay_reverse_step()) { + gdb_continue(s); + return RS_IDLE; + } else { + put_packet(s, "E14"); + break; + } + default: + goto unknown_command; + } + } else { + put_packet(s, "E22"); + } + goto unknown_command; case 'F': { target_ulong ret; @@ -1714,6 +1748,10 @@ static int gdb_handle_packet(GDBState *s, const char= *line_buf) } pstrcat(buf, sizeof(buf), ";multiprocess+"); =20 + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + pstrcat(buf, sizeof(buf), ";ReverseStep+"); + } + put_packet(s, buf); break; } diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index d7e859d915..533003f2b0 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -73,6 +73,17 @@ void replay_finish(void); void replay_add_blocker(Error *reason); /* Returns name of the replay log file */ const char *replay_get_filename(void); +/* + * Start making one step in backward direction. + * Used by gdbstub for backwards debugging. + * Returns true on success. + */ +bool replay_reverse_step(void); +/* + * Returns true if replay module is processing + * reverse_continue or reverse_step request + */ +bool replay_running_debug(void); =20 /* Processing the instructions */ =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index e3821ab1ba..0c7e34f50f 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -21,6 +21,13 @@ #include "block/snapshot.h" #include "migration/snapshot.h" =20 +static bool replay_is_debugging; + +bool replay_running_debug(void) +{ + return replay_is_debugging; +} + void hmp_info_replay(Monitor *mon, const QDict *qdict) { if (replay_mode =3D=3D REPLAY_MODE_NONE) { @@ -219,3 +226,29 @@ void hmp_replay_seek(Monitor *mon, const QDict *qdict) return; } } + +static void replay_stop_vm_debug(void *opaque) +{ + replay_is_debugging =3D false; + vm_stop(RUN_STATE_DEBUG); + replay_break(-1LL, NULL, NULL); +} + +bool replay_reverse_step(void) +{ + Error *err =3D NULL; + + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + + if (replay_get_current_step() !=3D 0) { + replay_seek(replay_get_current_step() - 1, replay_stop_vm_debug, &= err); + if (err) { + error_free(err); + return false; + } + replay_is_debugging =3D true; + return true; + } + + return false; +} diff --git a/stubs/replay.c b/stubs/replay.c index 4ac607895d..521552fa83 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -80,3 +80,8 @@ void replay_mutex_lock(void) void replay_mutex_unlock(void) { } + +bool replay_reverse_step(void) +{ + return false; +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355543336653.0967433298549; Tue, 5 Feb 2019 00:32:23 -0800 (PST) Received: from localhost ([127.0.0.1]:56293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqw9L-0000kl-GE for importer@patchew.org; Tue, 05 Feb 2019 03:32:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvz4-0000Zo-CD for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvyz-00018e-8A for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:30 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvyv-0000j2-Kq for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:26 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id CD9AE540089; Tue, 5 Feb 2019 11:21:17 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:19 +0300 Message-ID: <154935487896.7509.843303050095073079.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 17/25] gdbstub: add reverse continue support in replay mode 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch adds support of the reverse continue operation for gdbstub. Reverse continue finds the last breakpoint that would happen in normal execution from the beginning to the current moment. Implementation of the reverse continue replays the execution twice: to find the breakpoints that were hit and to seek to the last breakpoint. Reverse continue loads the previous snapshot and tries to find the breakpoi= nt since that moment. If there are no such breakpoints, it proceeds to the earlier snapshot, and so on. When no breakpoints or watchpoints were hit at all, execution stops at the beginning of the replay log. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- cpus.c | 5 +++ exec.c | 1 + gdbstub.c | 10 ++++++ include/sysemu/replay.h | 8 +++++ replay/replay-debugging.c | 71 +++++++++++++++++++++++++++++++++++++++++= ++++ stubs/replay.c | 5 +++ 6 files changed, 99 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 013341ca4f..6ef0992971 100644 --- a/cpus.c +++ b/cpus.c @@ -1110,6 +1110,11 @@ static void cpu_handle_guest_debug(CPUState *cpu) cpu->stopped =3D true; } else { if (!cpu->singlestep_enabled) { + /* + * Report about the breakpoint and + * make a single step to skip it + */ + replay_breakpoint(); cpu_single_step(cpu, SSTEP_ENABLE); } else { cpu_single_step(cpu, 0); diff --git a/exec.c b/exec.c index fdbd65c5b8..66fe4c36d9 100644 --- a/exec.c +++ b/exec.c @@ -2747,6 +2747,7 @@ static void check_watchpoint(int offset, int len, Mem= TxAttrs attrs, int flags) * Don't process the watchpoints when we are * in a reverse debugging operation. */ + replay_breakpoint(); return; } if (flags =3D=3D BP_MEM_READ) { diff --git a/gdbstub.c b/gdbstub.c index d9bf3863c1..3d10f75a37 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1439,6 +1439,14 @@ static int gdb_handle_packet(GDBState *s, const char= *line_buf) put_packet(s, "E14"); break; } + case 'c': + if (replay_reverse_continue()) { + gdb_continue(s); + return RS_IDLE; + } else { + put_packet(s, "E14"); + break; + } default: goto unknown_command; } @@ -1749,7 +1757,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) pstrcat(buf, sizeof(buf), ";multiprocess+"); =20 if (replay_mode =3D=3D REPLAY_MODE_PLAY) { - pstrcat(buf, sizeof(buf), ";ReverseStep+"); + pstrcat(buf, sizeof(buf), ";ReverseStep+;ReverseContinue+"= ); } =20 put_packet(s, buf); diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 533003f2b0..1d18c9b6ea 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -79,11 +79,19 @@ const char *replay_get_filename(void); * Returns true on success. */ bool replay_reverse_step(void); +/* + * Start searching the last breakpoint/watchpoint. + * Used by gdbstub for backwards debugging. + * Returns true if the process successfully started. + */ +bool replay_reverse_continue(void); /* * Returns true if replay module is processing * reverse_continue or reverse_step request */ bool replay_running_debug(void); +/* Called in reverse debugging mode to collect breakpoint information */ +void replay_breakpoint(void); =20 /* Processing the instructions */ =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 0c7e34f50f..9bbab5f02b 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -22,6 +22,8 @@ #include "migration/snapshot.h" =20 static bool replay_is_debugging; +static int64_t replay_last_breakpoint; +static int64_t replay_last_snapshot; =20 bool replay_running_debug(void) { @@ -252,3 +254,72 @@ bool replay_reverse_step(void) =20 return false; } + +static void replay_continue_end(void) +{ + replay_is_debugging =3D false; + vm_stop(RUN_STATE_DEBUG); + replay_break(-1LL, NULL, NULL); +} + +static void replay_continue_stop(void *opaque) +{ + Error *err =3D NULL; + if (replay_last_breakpoint !=3D -1LL) { + replay_seek(replay_last_breakpoint, replay_stop_vm_debug, &err); + if (err) { + error_free(err); + replay_continue_end(); + } + return; + } + /* + * No breakpoints since the last snapshot. + * Find previous snapshot and try again. + */ + if (replay_last_snapshot !=3D 0) { + replay_seek(replay_last_snapshot - 1, replay_continue_stop, &err); + if (err) { + error_free(err); + replay_continue_end(); + } + replay_last_snapshot =3D replay_get_current_step(); + return; + } else { + /* Seek to the very first step */ + replay_seek(0, replay_stop_vm_debug, &err); + if (err) { + error_free(err); + replay_continue_end(); + } + return; + } + replay_continue_end(); +} + +bool replay_reverse_continue(void) +{ + Error *err =3D NULL; + + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + + if (replay_get_current_step() !=3D 0) { + replay_seek(replay_get_current_step() - 1, replay_continue_stop, &= err); + if (err) { + error_free(err); + return false; + } + replay_last_breakpoint =3D -1LL; + replay_is_debugging =3D true; + replay_last_snapshot =3D replay_get_current_step(); + return true; + } + + return false; +} + +void replay_breakpoint(void) +{ + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + replay_last_breakpoint =3D replay_get_current_step(); +} diff --git a/stubs/replay.c b/stubs/replay.c index 521552fa83..ee649726f4 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -85,3 +85,8 @@ bool replay_reverse_step(void) { return false; } + +bool replay_reverse_continue(void) +{ + return false; +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355624360256.2219436898372; Tue, 5 Feb 2019 00:33:44 -0800 (PST) Received: from localhost ([127.0.0.1]:56305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwAe-0001kN-Vq for importer@patchew.org; Tue, 05 Feb 2019 03:33:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvz6-0000bj-EE for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvz3-0001Ko-4J for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:34 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33748) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvz0-0000xu-3b for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:30 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 8291554008A; Tue, 5 Feb 2019 11:21:23 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:24 +0300 Message-ID: <154935488467.7509.11541186923836724868.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 18/25] replay: describe reverse debugging in docs/replay.txt 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch updates the documentation and describes usage of the reverse debugging in QEMU+GDB. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- docs/replay.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/replay.txt b/docs/replay.txt index 2c2c5f6118..8447fdd350 100644 --- a/docs/replay.txt +++ b/docs/replay.txt @@ -293,6 +293,39 @@ for recording and replaying must contain identical num= ber of ports in record and replay modes, but their backends may differ. E.g., '-serial stdio' in record mode, and '-serial null' in replay mode. =20 +Reverse debugging +----------------- + +Reverse debugging allows "executing" the program in reverse direction. +GDB remote protocol supports "reverse step" and "reverse continue" +commands. The first one steps single instruction backwards in time, +and the second one finds the last breakpoint in the past. + +Recorded executions may be used to enable reverse debugging. QEMU can't +execute the code in backwards direction, but can load a snapshot and +replay forward to find the desired position or breakpoint. + +The following GDB commands are supported: + - reverse-stepi (or rsi) - step one instruction backwards + - reverse-continue (or rc) - find last breakpoint in the past + +Reverse step loads the nearest snapshot and replays the execution until +the required instruction is met. + +Reverse continue may include several passes of examining the execution +between the snapshots. Each of the passes include the following steps: + 1. loading the snapshot + 2. replaying to examine the breakpoints + 3. if breakpoint or watchpoint was met + - loading the snaphot again + - replaying to the required breakpoint + 4. else + - proceeding to the p.1 with the earlier snapshot + +Therefore usage of the reverse debugging requires at least one snapshot +created in advance. See the "Snapshotting" section to learn about running +record/replay and creating the snapshot in these modes. + Replay log format ----------------- =20 From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15493560520171002.3996027569611; Tue, 5 Feb 2019 00:40:52 -0800 (PST) Received: from localhost ([127.0.0.1]:56437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwHd-0007JY-RW for importer@patchew.org; Tue, 05 Feb 2019 03:40:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzE-0000jT-Om for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvz5-0001Rn-8E for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:39 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvz0-0001AM-BB for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:32 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 3FCC954008B; Tue, 5 Feb 2019 11:21:29 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:30 +0300 Message-ID: <154935489035.7509.9609366489534881286.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 19/25] replay: add BH oneshot event for block layer 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Replay is capable of recording normal BH events, but sometimes there are single use callbacks scheduled with aio_bh_schedule_oneshot function. This patch enables recording and replaying such callbacks. Block layer uses these events for calling the completion function. Replaying these calls makes the execution deterministic. Signed-off-by: Pavel Dovgalyuk -- v6: - moved stub function to the separate file for fixing linux-user build v10: - replaced all block layer aio_bh_schedule_oneshot calls reviewed-by for the block-related patches. --- block/block-backend.c | 8 +++++--- block/io.c | 4 ++-- block/iscsi.c | 5 +++-- block/nfs.c | 5 +++-- block/null.c | 4 +++- block/nvme.c | 6 ++++-- block/rbd.c | 5 +++-- block/vxhs.c | 5 +++-- include/sysemu/replay.h | 3 +++ replay/replay-events.c | 16 ++++++++++++++++ replay/replay-internal.h | 1 + replay/replay.c | 2 +- stubs/Makefile.objs | 1 + stubs/replay-user.c | 9 +++++++++ 14 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 stubs/replay-user.c diff --git a/block/block-backend.c b/block/block-backend.c index f6ea824308..9ccd89b56a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -17,6 +17,7 @@ #include "block/throttle-groups.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" +#include "sysemu/replay.h" #include "qapi/error.h" #include "qapi/qapi-events-block.h" #include "qemu/id.h" @@ -1293,7 +1294,8 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, acb->blk =3D blk; acb->ret =3D ret; =20 - aio_bh_schedule_oneshot(blk_get_aio_context(blk), error_callback_bh, a= cb); + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + error_callback_bh, acb); return &acb->common; } =20 @@ -1349,8 +1351,8 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, in= t64_t offset, int bytes, =20 acb->has_returned =3D true; if (acb->rwco.ret !=3D NOT_DONE) { - aio_bh_schedule_oneshot(blk_get_aio_context(blk), - blk_aio_complete_bh, acb); + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); } =20 return &acb->common; diff --git a/block/io.c b/block/io.c index c25864a8ee..a7d97b59e4 100644 --- a/block/io.c +++ b/block/io.c @@ -340,8 +340,8 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, if (bs) { bdrv_inc_in_flight(bs); } - aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), - bdrv_co_drain_bh_cb, &data); + replay_bh_schedule_oneshot_event(bdrv_get_aio_context(bs), + bdrv_co_drain_bh_cb, &data); =20 qemu_coroutine_yield(); /* If we are resumed from some other event (such as an aio completion = or a diff --git a/block/iscsi.c b/block/iscsi.c index ff473206e6..571bec80c9 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -38,6 +38,7 @@ #include "qemu/iov.h" #include "qemu/option.h" #include "qemu/uuid.h" +#include "sysemu/replay.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qmp/qdict.h" @@ -275,8 +276,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, =20 out: if (iTask->co) { - aio_bh_schedule_oneshot(iTask->iscsilun->aio_context, - iscsi_co_generic_bh_cb, iTask); + replay_bh_schedule_oneshot_event(iTask->iscsilun->aio_context, + iscsi_co_generic_bh_cb, iTask); } else { iTask->complete =3D 1; } diff --git a/block/nfs.c b/block/nfs.c index eab1a2c408..e8b6c90cf1 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -36,6 +36,7 @@ #include "qemu/uri.h" #include "qemu/cutils.h" #include "sysemu/sysemu.h" +#include "sysemu/replay.h" #include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" @@ -256,8 +257,8 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, voi= d *data, if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } - aio_bh_schedule_oneshot(task->client->aio_context, - nfs_co_generic_bh_cb, task); + replay_bh_schedule_oneshot_event(task->client->aio_context, + nfs_co_generic_bh_cb, task); } =20 static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offse= t, diff --git a/block/null.c b/block/null.c index d442d3e901..733873c79b 100644 --- a/block/null.c +++ b/block/null.c @@ -16,6 +16,7 @@ #include "qapi/qmp/qstring.h" #include "qemu/option.h" #include "block/block_int.h" +#include "sysemu/replay.h" =20 #define NULL_OPT_LATENCY "latency-ns" #define NULL_OPT_ZEROES "read-zeroes" @@ -178,7 +179,8 @@ static inline BlockAIOCB *null_aio_common(BlockDriverSt= ate *bs, timer_mod_ns(&acb->timer, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + s->latency_n= s); } else { - aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), null_bh_cb, acb); + replay_bh_schedule_oneshot_event(bdrv_get_aio_context(bs), + null_bh_cb, acb); } return &acb->common; } diff --git a/block/nvme.c b/block/nvme.c index b5952c9b08..7ada0794e8 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -21,6 +21,7 @@ #include "qemu/option.h" #include "qemu/vfio-helpers.h" #include "block/block_int.h" +#include "sysemu/replay.h" #include "trace.h" =20 #include "block/nvme.h" @@ -346,7 +347,8 @@ static bool nvme_process_completion(BDRVNVMeState *s, N= VMeQueuePair *q) smp_mb_release(); *q->cq.doorbell =3D cpu_to_le32(q->cq.head); if (!qemu_co_queue_empty(&q->free_req_queue)) { - aio_bh_schedule_oneshot(s->aio_context, nvme_free_req_queue_cb= , q); + replay_bh_schedule_oneshot_event(s->aio_context, + nvme_free_req_queue_cb, q); } } q->busy =3D false; @@ -897,7 +899,7 @@ static void nvme_rw_cb(void *opaque, int ret) /* The rw coroutine hasn't yielded, don't try to enter. */ return; } - aio_bh_schedule_oneshot(data->ctx, nvme_rw_cb_bh, data); + replay_bh_schedule_oneshot_event(data->ctx, nvme_rw_cb_bh, data); } =20 static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, diff --git a/block/rbd.c b/block/rbd.c index 8a1a9f4b6e..daaddbc28c 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -21,6 +21,7 @@ #include "block/qdict.h" #include "crypto/secret.h" #include "qemu/cutils.h" +#include "sysemu/replay.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" @@ -858,8 +859,8 @@ static void rbd_finish_aiocb(rbd_completion_t c, RADOSC= B *rcb) rcb->ret =3D rbd_aio_get_return_value(c); rbd_aio_release(c); =20 - aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), - rbd_finish_bh, rcb); + replay_bh_schedule_oneshot_event(bdrv_get_aio_context(acb->common.bs), + rbd_finish_bh, rcb); } =20 static int rbd_aio_discard_wrapper(rbd_image_t image, diff --git a/block/vxhs.c b/block/vxhs.c index 0cb0a007e9..3ac35cb6bd 100644 --- a/block/vxhs.c +++ b/block/vxhs.c @@ -21,6 +21,7 @@ #include "qapi/error.h" #include "qemu/uuid.h" #include "crypto/tlscredsx509.h" +#include "sysemu/replay.h" =20 #define VXHS_OPT_FILENAME "filename" #define VXHS_OPT_VDISK_ID "vdisk-id" @@ -104,8 +105,8 @@ static void vxhs_iio_callback(void *ctx, uint32_t opcod= e, uint32_t error) trace_vxhs_iio_callback(error); } =20 - aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), - vxhs_complete_aio_bh, acb); + replay_bh_schedule_oneshot_event(bdrv_get_aio_context(acb->common.= bs), + vxhs_complete_aio_bh, acb); break; =20 default: diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 1d18c9b6ea..b7394a1f5c 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -163,6 +163,9 @@ bool replay_events_enabled(void); void replay_flush_events(void); /*! Adds bottom half event to the queue */ void replay_bh_schedule_event(QEMUBH *bh); +/* Adds oneshot bottom half event to the queue */ +void replay_bh_schedule_oneshot_event(AioContext *ctx, + QEMUBHFunc *cb, void *opaque); /*! Adds input event to the queue */ void replay_input_event(QemuConsole *src, InputEvent *evt); /*! Adds input sync event to the queue */ diff --git a/replay/replay-events.c b/replay/replay-events.c index d9a2d495b9..fc9b08225d 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -37,6 +37,9 @@ static void replay_run_event(Event *event) case REPLAY_ASYNC_EVENT_BH: aio_bh_call(event->opaque); break; + case REPLAY_ASYNC_EVENT_BH_ONESHOT: + ((QEMUBHFunc *)event->opaque)(event->opaque2); + break; case REPLAY_ASYNC_EVENT_INPUT: qemu_input_event_send_impl(NULL, (InputEvent *)event->opaque); qapi_free_InputEvent((InputEvent *)event->opaque); @@ -132,6 +135,17 @@ void replay_bh_schedule_event(QEMUBH *bh) } } =20 +void replay_bh_schedule_oneshot_event(AioContext *ctx, + QEMUBHFunc *cb, void *opaque) +{ + if (events_enabled) { + uint64_t id =3D replay_get_current_step(); + replay_add_event(REPLAY_ASYNC_EVENT_BH_ONESHOT, cb, opaque, id); + } else { + aio_bh_schedule_oneshot(ctx, cb, opaque); + } +} + void replay_add_input_event(struct InputEvent *event) { replay_add_event(REPLAY_ASYNC_EVENT_INPUT, event, NULL, 0); @@ -162,6 +176,7 @@ static void replay_save_event(Event *event, int checkpo= int) /* save event-specific data */ switch (event->event_kind) { case REPLAY_ASYNC_EVENT_BH: + case REPLAY_ASYNC_EVENT_BH_ONESHOT: replay_put_qword(event->id); break; case REPLAY_ASYNC_EVENT_INPUT: @@ -217,6 +232,7 @@ static Event *replay_read_event(int checkpoint) /* Events that has not to be in the queue */ switch (replay_state.read_event_kind) { case REPLAY_ASYNC_EVENT_BH: + case REPLAY_ASYNC_EVENT_BH_ONESHOT: if (replay_state.read_event_id =3D=3D -1) { replay_state.read_event_id =3D replay_get_qword(); } diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 945802361b..e9786b2377 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -51,6 +51,7 @@ enum ReplayEvents { =20 enum ReplayAsyncEventKind { REPLAY_ASYNC_EVENT_BH, + REPLAY_ASYNC_EVENT_BH_ONESHOT, REPLAY_ASYNC_EVENT_INPUT, REPLAY_ASYNC_EVENT_INPUT_SYNC, REPLAY_ASYNC_EVENT_CHAR_READ, diff --git a/replay/replay.c b/replay/replay.c index 1be34aa824..e578958659 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -22,7 +22,7 @@ =20 /* Current version of the replay mechanism. Increase it when file format changes. */ -#define REPLAY_VERSION 0xe02007 +#define REPLAY_VERSION 0xe02008 /* Size of replay log header */ #define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t)) =20 diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 5dd0aeeec6..8e8df1ec17 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -24,6 +24,7 @@ stub-obj-y +=3D monitor.o stub-obj-y +=3D notify-event.o stub-obj-y +=3D qtest.o stub-obj-y +=3D replay.o +stub-obj-y +=3D replay-user.o stub-obj-y +=3D runstate-check.o stub-obj-y +=3D set-fd-handler.o stub-obj-y +=3D slirp.o diff --git a/stubs/replay-user.c b/stubs/replay-user.c new file mode 100644 index 0000000000..2ad9e27203 --- /dev/null +++ b/stubs/replay-user.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "sysemu/replay.h" +#include "sysemu/sysemu.h" + +void replay_bh_schedule_oneshot_event(AioContext *ctx, + QEMUBHFunc *cb, void *opaque) +{ + aio_bh_schedule_oneshot(ctx, cb, opaque); +} From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355645340879.2775480858138; Tue, 5 Feb 2019 00:34:05 -0800 (PST) Received: from localhost ([127.0.0.1]:56311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwB5-000217-7e for importer@patchew.org; Tue, 05 Feb 2019 03:33:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzL-0000op-4I for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzK-0002BD-EH for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:51 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33796) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzI-0001Sq-H4 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:49 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id E84B7540089; Tue, 5 Feb 2019 11:21:34 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:36 +0300 Message-ID: <154935489606.7509.6832662317553683481.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 20/25] replay: init rtc after enabling the 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch postpones the call of 'configure_rtc' function. This call uses host clock to configure the rtc, but host clock access should be recorded when using icount record/replay mode. Therefore now rtc is configured after switching record/replay mode on. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- vl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vl.c b/vl.c index 00cf47339e..3b6168c190 100644 --- a/vl.c +++ b/vl.c @@ -3011,6 +3011,7 @@ int main(int argc, char **argv, char **envp) DisplayState *ds; QemuOpts *opts, *machine_opts; QemuOpts *icount_opts =3D NULL, *accel_opts =3D NULL; + QemuOpts *rtc_opts =3D NULL; QemuOptsList *olist; int optind; const char *optarg; @@ -3817,9 +3818,9 @@ int main(int argc, char **argv, char **envp) warn_report("This option is ignored and will be removed so= on"); break; case QEMU_OPTION_rtc: - opts =3D qemu_opts_parse_noisily(qemu_find_opts("rtc"), op= targ, - false); - if (!opts) { + rtc_opts =3D qemu_opts_parse_noisily(qemu_find_opts("rtc"), + optarg, false); + if (!rtc_opts) { exit(1); } break; @@ -4025,6 +4026,9 @@ int main(int argc, char **argv, char **envp) loc_set_none(); =20 replay_configure(icount_opts); + if (rtc_opts) { + configure_rtc(rtc_opts); + } =20 if (incoming && !preconfig_exit_requested) { error_report("'preconfig' and 'incoming' options are " From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355840002504.74915357340126; Tue, 5 Feb 2019 00:37:20 -0800 (PST) Received: from localhost ([127.0.0.1]:56368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwED-0004Tt-Sx for importer@patchew.org; Tue, 05 Feb 2019 03:37:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzP-0000ql-9N for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzN-0002H2-68 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:55 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzM-0001mA-Ni for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:53 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 96EBA54008A; Tue, 5 Feb 2019 11:21:40 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:41 +0300 Message-ID: <154935490175.7509.6880563108257208975.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 21/25] replay: document development rules 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch introduces docs/devel/replay.txt which describes the rules that should be followed to make virtual devices usable in record/replay mod= e. Signed-off-by: Pavel Dovgalyuk -- v9: fixed external virtual clock description (reported by Artem Pisarenko) reviewed-by for the block-related patches. --- docs/devel/replay.txt | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs/devel/replay.txt diff --git a/docs/devel/replay.txt b/docs/devel/replay.txt new file mode 100644 index 0000000000..e641c35add --- /dev/null +++ b/docs/devel/replay.txt @@ -0,0 +1,46 @@ +Record/replay mechanism, that could be enabled through icount mode, expects +the virtual devices to satisfy the following requirements. + +The main idea behind this document is that everything that affects +the guest state during execution in icount mode should be deterministic. + +Timers +=3D=3D=3D=3D=3D=3D + +All virtual devices should use virtual clock for timers that change the gu= est +state. Virtual clock is deterministic, therefore such timers are determini= stic +too. + +Virtual devices can also use realtime clock for the events that do not cha= nge +the guest state directly. When the clock ticking should depend on VM execu= tion +speed, use virtual clock with EXTERNAL attribute. It is not deterministic, +but its speed depends on the guest execution. This clock is used by +the virtual devices (e.g., slirp routing device) that lie outside the +replayed guest. + +Bottom halves +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Bottom half callbacks, that affect the guest state, should be invoked thro= ugh +replay_bh_schedule_event or replay_bh_schedule_oneshot_event functions. +Their invocations are saved in record mode and synchronized with the exist= ing +log in replay mode. + +Saving/restoring the VM state +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +All fields in the device state structure (including virtual timers) +should be restored by loadvm to the same values they had before savevm. + +Avoid accessing other devices' state, because the order of saving/restoring +is not defined. It means that you should not call functions like +'update_irq' in post_load callback. Save everything explicitly to avoid +the dependencies that may make restoring the VM state non-deterministic. + +Stopping the VM +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Stopping the guest should not interfere with its state (with the exception +of the network connections, that could be broken by the remote timeouts). +VM can be stopped at any moment of replay by the user. Restarting the VM +after that stop should not break the replay by the unneeded guest state ch= ange. From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549356008060644.7964160405442; Tue, 5 Feb 2019 00:40:08 -0800 (PST) Received: from localhost ([127.0.0.1]:56389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwGt-0006h7-Vx for importer@patchew.org; Tue, 05 Feb 2019 03:40:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzR-0000sv-EE for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzP-0002Mp-BN for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:57 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzN-00020M-7M for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:55 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 47C1054008B; Tue, 5 Feb 2019 11:21:46 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:47 +0300 Message-ID: <154935490741.7509.7068818566955459104.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 22/25] util/qemu-timer: refactor deadline calculation for external 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" icount-based record/replay uses qemu_clock_deadline_ns_all to measure the period until vCPU may be interrupted. This function takes in account the virtual timers, because they belong to the virtual devices that may generate interrupt request or affect the virtual machine state. However, there are a subset of virtual timers, that are marked with 'external' flag. These do not change the virtual machine state and only based on virtual clock. Calculating the deadling using the external timers breaks the determinism, because they do not belong to the replayed part of the virtual machine. This patch fixes the deadline calculation for this case. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- cpus.c | 9 ++++----- include/qemu/timer.h | 7 +++---- qtest.c | 2 +- tests/ptimer-test-stubs.c | 2 +- tests/ptimer-test.c | 4 ++-- util/qemu-timer.c | 41 +++++++++++++++++++++++++++++++++-------- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/cpus.c b/cpus.c index 6ef0992971..fb656cefc8 100644 --- a/cpus.c +++ b/cpus.c @@ -550,7 +550,7 @@ void qtest_clock_warp(int64_t dest) assert(qtest_enabled()); aio_context =3D qemu_get_aio_context(); while (clock < dest) { - int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL= ); + int64_t deadline =3D virtual_clock_deadline_ns(); int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); =20 seqlock_write_lock(&timers_state.vm_clock_seqlock, @@ -610,7 +610,7 @@ void qemu_start_warp_timer(void) =20 /* We want to use the earliest deadline from ALL vm_clocks */ clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT); - deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + deadline =3D virtual_clock_deadline_ns(); if (deadline < 0) { static bool notified; if (!icount_sleep && !notified) { @@ -1355,7 +1355,7 @@ static int64_t tcg_get_icount_limit(void) int64_t deadline; =20 if (replay_mode !=3D REPLAY_MODE_PLAY) { - deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + deadline =3D virtual_clock_deadline_ns(); =20 /* Maintain prior (possibly buggy) behaviour where if no deadline * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more= than @@ -1376,8 +1376,7 @@ static void handle_icount_deadline(void) { assert(qemu_in_vcpu_thread()); if (use_icount) { - int64_t deadline =3D - qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + int64_t deadline =3D virtual_clock_deadline_ns(); =20 if (deadline =3D=3D 0) { /* Wake up other AioContexts. */ diff --git a/include/qemu/timer.h b/include/qemu/timer.h index a86330c987..cfc77450f2 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -176,16 +176,15 @@ bool qemu_clock_expired(QEMUClockType type); bool qemu_clock_use_for_deadline(QEMUClockType type); =20 /** - * qemu_clock_deadline_ns_all: - * @type: the clock type + * virtual_clock_deadline_ns: * * Calculate the deadline across all timer lists associated - * with a clock (as opposed to just the default one) + * with virtual clock (excluding external timers) * in nanoseconds, or -1 if no timer is set to expire. * * Returns: time until expiry in nanoseconds or -1 */ -int64_t qemu_clock_deadline_ns_all(QEMUClockType type); +int64_t virtual_clock_deadline_ns(void); =20 /** * qemu_clock_get_main_loop_timerlist: diff --git a/qtest.c b/qtest.c index 60988c8aa2..341190eb71 100644 --- a/qtest.c +++ b/qtest.c @@ -655,7 +655,7 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) int ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); g_assert(ret =3D=3D 0); } else { - ns =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + ns =3D virtual_clock_deadline_ns(); } qtest_clock_warp(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); qtest_send_prefix(chr); diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c index 54b3fd26f6..31b09c88f3 100644 --- a/tests/ptimer-test-stubs.c +++ b/tests/ptimer-test-stubs.c @@ -88,7 +88,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return ptimer_test_time_ns; } =20 -int64_t qemu_clock_deadline_ns_all(QEMUClockType type) +int64_t virtual_clock_deadline_ns(void) { QEMUTimerList *timer_list =3D main_loop_tlg.tl[type]; QEMUTimer *t =3D timer_list->active_timers.next; diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c index b30aad0737..338a4e0c10 100644 --- a/tests/ptimer-test.c +++ b/tests/ptimer-test.c @@ -50,13 +50,13 @@ static void ptimer_test_set_qemu_time_ns(int64_t ns) =20 static void qemu_clock_step(uint64_t ns) { - int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + int64_t deadline =3D virtual_clock_deadline_ns(); int64_t advanced_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns; =20 while (deadline !=3D -1 && deadline <=3D advanced_time) { ptimer_test_set_qemu_time_ns(deadline); ptimer_test_expire_qemu_timers(deadline, QEMU_CLOCK_VIRTUAL); - deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); + deadline =3D virtual_clock_deadline_ns(); } =20 ptimer_test_set_qemu_time_ns(advanced_time); diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 1cc1b2f2c3..88fbf04469 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -236,6 +236,7 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list) qemu_mutex_unlock(&timer_list->active_timers_lock); return -1; } + expire_time =3D timer_list->active_timers->expire_time; qemu_mutex_unlock(&timer_list->active_timers_lock); =20 @@ -248,19 +249,43 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_li= st) return delta; } =20 -/* Calculate the soonest deadline across all timerlists attached - * to the clock. This is used for the icount timeout so we - * ignore whether or not the clock should be used in deadline - * calculations. +/* + * Calculate the soonest deadline across all timerlists attached + * to the virtual clock (excluding the external timers that do not affect + * the replayed guest state. */ -int64_t qemu_clock_deadline_ns_all(QEMUClockType type) +int64_t virtual_clock_deadline_ns(void) { int64_t deadline =3D -1; + int64_t delta; + int64_t expire_time; + QEMUTimer *ts; QEMUTimerList *timer_list; - QEMUClock *clock =3D qemu_clock_ptr(type); + QEMUClock *clock =3D qemu_clock_ptr(QEMU_CLOCK_VIRTUAL); + + if (!clock->enabled) { + return -1; + } + QLIST_FOREACH(timer_list, &clock->timerlists, list) { - deadline =3D qemu_soonest_timeout(deadline, - timerlist_deadline_ns(timer_list)); + qemu_mutex_lock(&timer_list->active_timers_lock); + ts =3D timer_list->active_timers; + /* Skip all external timers */ + while (ts && (ts->attributes & QEMU_TIMER_ATTR_EXTERNAL)) { + ts =3D ts->next; + } + if (!ts) { + qemu_mutex_unlock(&timer_list->active_timers_lock); + continue; + } + expire_time =3D ts->expire_time; + qemu_mutex_unlock(&timer_list->active_timers_lock); + + delta =3D expire_time - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (delta <=3D 0) { + delta =3D 0; + } + deadline =3D qemu_soonest_timeout(deadline, delta); } return deadline; } From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355818828508.36146229240956; Tue, 5 Feb 2019 00:36:58 -0800 (PST) Received: from localhost ([127.0.0.1]:56364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwDs-0004FK-PE for importer@patchew.org; Tue, 05 Feb 2019 03:36:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzR-0000sw-EE for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzP-0002Ml-BS for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:57 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzN-0002F4-5u for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:55 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id EE7CA540089; Tue, 5 Feb 2019 11:21:51 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:53 +0300 Message-ID: <154935491310.7509.1922243125715075415.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 23/25] replay: fix replay shutdown 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch fixes shutdown of the replay process, which is terminated with the assert when shutdown event is read from the log. replay_finish_event reads new data_kind and therefore the value of data_kind should be preserved to be valid at qemu_system_shutdown_request call. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- replay/replay.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/replay/replay.c b/replay/replay.c index e578958659..8f2e17c8cb 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -49,14 +49,14 @@ bool replay_next_event_is(int event) } =20 while (true) { - if (event =3D=3D replay_state.data_kind) { + unsigned int data_kind =3D replay_state.data_kind; + if (event =3D=3D data_kind) { res =3D true; } - switch (replay_state.data_kind) { + switch (data_kind) { case EVENT_SHUTDOWN ... EVENT_SHUTDOWN_LAST: replay_finish_event(); - qemu_system_shutdown_request(replay_state.data_kind - - EVENT_SHUTDOWN); + qemu_system_shutdown_request(data_kind - EVENT_SHUTDOWN); break; default: /* clock, time_t, checkpoint and other events */ From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154935573435296.86265970514489; Tue, 5 Feb 2019 00:35:34 -0800 (PST) Received: from localhost ([127.0.0.1]:56319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwCW-0003GP-5X for importer@patchew.org; Tue, 05 Feb 2019 03:35:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzV-0000x3-FT for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:22:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzT-0002du-KF for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:22:01 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzT-0002Y7-3X for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:21:59 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 9BE50540089; Tue, 5 Feb 2019 11:21:57 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:21:58 +0300 Message-ID: <154935491876.7509.3362365927769261001.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 24/25] replay: rename step-related variables and functions 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch renames replay_get_current_step() and related variables to make these names consistent with hmp/qmp commands. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- blockdev.c | 2 +- include/sysemu/replay.h | 2 +- migration/savevm.c | 2 +- replay/replay-debugging.c | 30 ++++++++++++++++-------------- replay/replay-events.c | 4 ++-- replay/replay-internal.c | 10 +++++----- replay/replay-internal.h | 10 +++++----- replay/replay-snapshot.c | 6 +++--- replay/replay-time.c | 2 +- replay/replay.c | 26 +++++++++++++------------- 10 files changed, 48 insertions(+), 46 deletions(-) diff --git a/blockdev.c b/blockdev.c index f5775fdf5a..d6ab78cd51 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1453,7 +1453,7 @@ static void internal_snapshot_prepare(BlkActionState = *common, sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); if (replay_mode !=3D REPLAY_MODE_NONE) { - sn->icount =3D replay_get_current_step(); + sn->icount =3D replay_get_current_icount(); } else { sn->icount =3D -1ULL; } diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index b7394a1f5c..057a458463 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -96,7 +96,7 @@ void replay_breakpoint(void); /* Processing the instructions */ =20 /*! Returns number of executed instructions. */ -uint64_t replay_get_current_step(void); +uint64_t replay_get_current_icount(void); /*! Returns number of instructions to execute in replay mode. */ int replay_get_instructions(void); /*! Updates instructions counter in replay mode. */ diff --git a/migration/savevm.c b/migration/savevm.c index eea97b4a8f..21cb3adf52 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2511,7 +2511,7 @@ int save_snapshot(const char *name, Error **errp) sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); if (replay_mode !=3D REPLAY_MODE_NONE) { - sn->icount =3D replay_get_current_step(); + sn->icount =3D replay_get_current_icount(); } else { sn->icount =3D -1ULL; } diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 9bbab5f02b..135957bb63 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -38,7 +38,7 @@ void hmp_info_replay(Monitor *mon, const QDict *qdict) monitor_printf(mon, "%s execution '%s': instruction count =3D %"PRId64"\n", replay_mode =3D=3D REPLAY_MODE_RECORD ? "Recording" : "Replayi= ng", - replay_get_filename(), replay_get_current_step()); + replay_get_filename(), replay_get_current_icount()); } } =20 @@ -51,7 +51,7 @@ ReplayInfo *qmp_query_replay(Error **errp) retval->filename =3D g_strdup(replay_get_filename()); retval->has_filename =3D true; } - retval->icount =3D replay_get_current_step(); + retval->icount =3D replay_get_current_icount(); return retval; } =20 @@ -59,7 +59,7 @@ static void replay_break(uint64_t icount, QEMUTimerCB cal= lback, void *opaque) { assert(replay_mode =3D=3D REPLAY_MODE_PLAY); assert(replay_mutex_locked()); - assert(replay_break_icount >=3D replay_get_current_step()); + assert(replay_break_icount >=3D replay_get_current_icount()); assert(callback); =20 replay_break_icount =3D icount; @@ -94,7 +94,7 @@ static void replay_stop_vm(void *opaque) void qmp_replay_break(int64_t icount, Error **errp) { if (replay_mode =3D=3D REPLAY_MODE_PLAY) { - if (icount >=3D replay_get_current_step()) { + if (icount >=3D replay_get_current_icount()) { replay_break(icount, replay_stop_vm, NULL); } else { error_setg(errp, @@ -196,14 +196,14 @@ static void replay_seek(int64_t icount, QEMUTimerCB c= allback, Error **errp) =20 snapshot =3D replay_find_nearest_snapshot(icount, &snapshot_icount); if (snapshot) { - if (icount < replay_get_current_step() - || replay_get_current_step() < snapshot_icount) { + if (icount < replay_get_current_icount() + || replay_get_current_icount() < snapshot_icount) { vm_stop(RUN_STATE_RESTORE_VM); load_snapshot(snapshot, errp); } g_free(snapshot); } - if (replay_get_current_step() <=3D icount) { + if (replay_get_current_icount() <=3D icount) { replay_break(icount, callback, NULL); vm_start(); } else { @@ -242,8 +242,9 @@ bool replay_reverse_step(void) =20 assert(replay_mode =3D=3D REPLAY_MODE_PLAY); =20 - if (replay_get_current_step() !=3D 0) { - replay_seek(replay_get_current_step() - 1, replay_stop_vm_debug, &= err); + if (replay_get_current_icount() !=3D 0) { + replay_seek(replay_get_current_icount() - 1, + replay_stop_vm_debug, &err); if (err) { error_free(err); return false; @@ -283,7 +284,7 @@ static void replay_continue_stop(void *opaque) error_free(err); replay_continue_end(); } - replay_last_snapshot =3D replay_get_current_step(); + replay_last_snapshot =3D replay_get_current_icount(); return; } else { /* Seek to the very first step */ @@ -303,15 +304,16 @@ bool replay_reverse_continue(void) =20 assert(replay_mode =3D=3D REPLAY_MODE_PLAY); =20 - if (replay_get_current_step() !=3D 0) { - replay_seek(replay_get_current_step() - 1, replay_continue_stop, &= err); + if (replay_get_current_icount() !=3D 0) { + replay_seek(replay_get_current_icount() - 1, + replay_continue_stop, &err); if (err) { error_free(err); return false; } replay_last_breakpoint =3D -1LL; replay_is_debugging =3D true; - replay_last_snapshot =3D replay_get_current_step(); + replay_last_snapshot =3D replay_get_current_icount(); return true; } =20 @@ -321,5 +323,5 @@ bool replay_reverse_continue(void) void replay_breakpoint(void) { assert(replay_mode =3D=3D REPLAY_MODE_PLAY); - replay_last_breakpoint =3D replay_get_current_step(); + replay_last_breakpoint =3D replay_get_current_icount(); } diff --git a/replay/replay-events.c b/replay/replay-events.c index fc9b08225d..4778eb0ede 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -128,7 +128,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind, void replay_bh_schedule_event(QEMUBH *bh) { if (events_enabled) { - uint64_t id =3D replay_get_current_step(); + uint64_t id =3D replay_get_current_icount(); replay_add_event(REPLAY_ASYNC_EVENT_BH, bh, NULL, id); } else { qemu_bh_schedule(bh); @@ -139,7 +139,7 @@ void replay_bh_schedule_oneshot_event(AioContext *ctx, QEMUBHFunc *cb, void *opaque) { if (events_enabled) { - uint64_t id =3D replay_get_current_step(); + uint64_t id =3D replay_get_current_icount(); replay_add_event(REPLAY_ASYNC_EVENT_BH_ONESHOT, cb, opaque, id); } else { aio_bh_schedule_oneshot(ctx, cb, opaque); diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 7e6de03182..b45725dbb1 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -173,7 +173,7 @@ void replay_fetch_data_kind(void) if (!replay_state.has_unread_data) { replay_state.data_kind =3D replay_get_byte(); if (replay_state.data_kind =3D=3D EVENT_INSTRUCTION) { - replay_state.instructions_count =3D replay_get_dword(); + replay_state.instruction_count =3D replay_get_dword(); } replay_check_error(); replay_state.has_unread_data =3D 1; @@ -227,9 +227,9 @@ void replay_mutex_unlock(void) } } =20 -void replay_advance_current_step(uint64_t current_step) +void replay_advance_current_icount(uint64_t current_icount) { - int diff =3D (int)(current_step - replay_state.current_step); + int diff =3D (int)(current_icount - replay_state.current_icount); =20 /* Time can only go forward */ assert(diff >=3D 0); @@ -237,7 +237,7 @@ void replay_advance_current_step(uint64_t current_step) if (diff > 0) { replay_put_event(EVENT_INSTRUCTION); replay_put_dword(diff); - replay_state.current_step +=3D diff; + replay_state.current_icount +=3D diff; } } =20 @@ -246,6 +246,6 @@ void replay_save_instructions(void) { if (replay_file && replay_mode =3D=3D REPLAY_MODE_RECORD) { g_assert(replay_mutex_locked()); - replay_advance_current_step(replay_get_current_step()); + replay_advance_current_icount(replay_get_current_icount()); } } diff --git a/replay/replay-internal.h b/replay/replay-internal.h index e9786b2377..ba9f374374 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -65,10 +65,10 @@ typedef enum ReplayAsyncEventKind ReplayAsyncEventKind; typedef struct ReplayState { /*! Cached clock values. */ int64_t cached_clock[REPLAY_CLOCK_COUNT]; - /*! Current step - number of processed instructions and timer events. = */ - uint64_t current_step; + /*! Current icount - number of processed instructions. */ + uint64_t current_icount; /*! Number of instructions to be executed before other events happen. = */ - int instructions_count; + int instruction_count; /*! Type of the currently executed event. */ unsigned int data_kind; /*! Flag which indicates that event is not processed yet. */ @@ -127,8 +127,8 @@ void replay_finish_event(void); data_kind variable. */ void replay_fetch_data_kind(void); =20 -/*! Advance replay_state.current_step to the specified value. */ -void replay_advance_current_step(uint64_t current_step); +/*! Advance replay_state.current_icount to the specified value. */ +void replay_advance_current_icount(uint64_t current_icount); /*! Saves queued events (like instructions and sound). */ void replay_save_instructions(void); =20 diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 16bacc98bc..7619f9b276 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -42,7 +42,7 @@ static int replay_post_load(void *opaque, int version_id) } else if (replay_mode =3D=3D REPLAY_MODE_RECORD) { /* This is only useful for loading the initial state. Therefore reset all the counters. */ - state->instructions_count =3D 0; + state->instruction_count =3D 0; state->block_request_id =3D 0; } =20 @@ -57,8 +57,8 @@ static const VMStateDescription vmstate_replay =3D { .post_load =3D replay_post_load, .fields =3D (VMStateField[]) { VMSTATE_INT64_ARRAY(cached_clock, ReplayState, REPLAY_CLOCK_COUNT), - VMSTATE_UINT64(current_step, ReplayState), - VMSTATE_INT32(instructions_count, ReplayState), + VMSTATE_UINT64(current_icount, ReplayState), + VMSTATE_INT32(instruction_count, ReplayState), VMSTATE_UINT32(data_kind, ReplayState), VMSTATE_UINT32(has_unread_data, ReplayState), VMSTATE_UINT64(file_offset, ReplayState), diff --git a/replay/replay-time.c b/replay/replay-time.c index 60f47b73a7..2260b1d00e 100644 --- a/replay/replay-time.c +++ b/replay/replay-time.c @@ -25,7 +25,7 @@ int64_t replay_save_clock(ReplayClockKind kind, int64_t c= lock, * Due to the caller's locking requirements we get the icount from it * instead of using replay_save_instructions(). */ - replay_advance_current_step(raw_icount); + replay_advance_current_icount(raw_icount); replay_put_event(EVENT_CLOCK + kind); replay_put_qword(clock); =20 diff --git a/replay/replay.c b/replay/replay.c index 8f2e17c8cb..11b9c12eb6 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -43,7 +43,7 @@ bool replay_next_event_is(int event) bool res =3D false; =20 /* nothing to skip - not all instructions used */ - if (replay_state.instructions_count !=3D 0) { + if (replay_state.instruction_count !=3D 0) { assert(replay_state.data_kind =3D=3D EVENT_INSTRUCTION); return event =3D=3D EVENT_INSTRUCTION; } @@ -66,7 +66,7 @@ bool replay_next_event_is(int event) return res; } =20 -uint64_t replay_get_current_step(void) +uint64_t replay_get_current_icount(void) { return cpu_get_icount_raw(); } @@ -76,9 +76,9 @@ int replay_get_instructions(void) int res =3D 0; replay_mutex_lock(); if (replay_next_event_is(EVENT_INSTRUCTION)) { - res =3D replay_state.instructions_count; + res =3D replay_state.instruction_count; if (replay_break_icount !=3D -1LL) { - uint64_t current =3D replay_get_current_step(); + uint64_t current =3D replay_get_current_icount(); assert(replay_break_icount >=3D current); if (current + res > replay_break_icount) { res =3D replay_break_icount - current; @@ -93,16 +93,16 @@ void replay_account_executed_instructions(void) { if (replay_mode =3D=3D REPLAY_MODE_PLAY) { g_assert(replay_mutex_locked()); - if (replay_state.instructions_count > 0) { - int count =3D (int)(replay_get_current_step() - - replay_state.current_step); + if (replay_state.instruction_count > 0) { + int count =3D (int)(replay_get_current_icount() + - replay_state.current_icount); =20 /* Time can only go forward */ assert(count >=3D 0); =20 - replay_state.instructions_count -=3D count; - replay_state.current_step +=3D count; - if (replay_state.instructions_count =3D=3D 0) { + replay_state.instruction_count -=3D count; + replay_state.current_icount +=3D count; + if (replay_state.instruction_count =3D=3D 0) { assert(replay_state.data_kind =3D=3D EVENT_INSTRUCTION); replay_finish_event(); /* Wake up iothread. This is required because @@ -111,7 +111,7 @@ void replay_account_executed_instructions(void) qemu_notify_event(); } /* Execution reached the break step */ - if (replay_break_icount =3D=3D replay_state.current_step) { + if (replay_break_icount =3D=3D replay_state.current_icount) { /* Cannot make callback directly from the vCPU thread */ timer_mod_ns(replay_break_timer, qemu_clock_get_ns(QEMU_CLOCK_REALTIME)); @@ -290,8 +290,8 @@ static void replay_enable(const char *fname, int mode) replay_mutex_init(); =20 replay_state.data_kind =3D -1; - replay_state.instructions_count =3D 0; - replay_state.current_step =3D 0; + replay_state.instruction_count =3D 0; + replay_state.current_icount =3D 0; replay_state.has_unread_data =3D 0; =20 /* skip file header for RECORD and check it for PLAY */ From nobody Sun Apr 28 00:15:56 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549355939015913.7442562311543; Tue, 5 Feb 2019 00:38:59 -0800 (PST) Received: from localhost ([127.0.0.1]:56381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqwFj-0005fM-GJ for importer@patchew.org; Tue, 05 Feb 2019 03:38:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzZ-00010D-5P for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqvzY-0002yK-Ej for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:22:05 -0500 Received: from mail.ispras.ru ([83.149.199.45]:33916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqvzY-0002vn-4V for qemu-devel@nongnu.org; Tue, 05 Feb 2019 03:22:04 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 47EA6540089; Tue, 5 Feb 2019 11:22:03 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Feb 2019 11:22:04 +0300 Message-ID: <154935492442.7509.12661851937201541525.stgit@pasha-VirtualBox> In-Reply-To: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> References: <154935478086.7509.4349987292919289245.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty 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 X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [PATCH v12 25/25] icount: clean up cpu_can_io before jumping to the next block 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, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, crosthwaite.peter@gmail.com, ciro.santilli@gmail.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, mreitz@redhat.com, alex.bennee@linaro.org, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, artem.k.pisarenko@gmail.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Most of IO instructions can be executed only at the end of the block in icount mode. Therefore translator can set cpu_can_io flag when translating the last instruction. But when the blocks are chained, then this flag is not reset and may remain set at the beginning of the next block. This patch resets the flag before "chaining" the translation blocks. Signed-off-by: Pavel Dovgalyuk reviewed-by for the block-related patches. --- accel/tcg/tcg-runtime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index d0d4484406..5871f5aba2 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -151,6 +151,8 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env) target_ulong cs_base, pc; uint32_t flags; =20 + /* We are going to jump to the next block. can_do_io should be reset */ + cpu->can_do_io =3D !use_icount; tb =3D tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, curr_cflags()); if (tb =3D=3D NULL) { return tcg_ctx->code_gen_epilogue;